Skip to content

Commit

Permalink
Closed #46
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kurczewski committed Oct 21, 2013
1 parent ff3e4bc commit 6b55706
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ private function decorateSearchQuery($dbQuery, $tokens)
->innerJoin('tag')
->on('post_tag.tag_id = tag.id')
->where('post_id = post.id')
->and('tag.name = ?')->put($val)
->and('LOWER(tag.name) = LOWER(?)')->put($val)
->close();
continue;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Models/Model_Comment.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
class Model_Comment extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$comment = R::findOne('comment', 'id = ?', [$key]);
if (!$comment)
throw new SimpleException('Invalid comment ID "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid comment ID "' . $key . '"');
return null;
}
return $comment;
}

Expand Down
14 changes: 11 additions & 3 deletions src/Models/Model_Post.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?php
class Model_Post extends RedBean_SimpleModel
{
public static function locate($key, $disallowNumeric = false)
public static function locate($key, $disallowNumeric = false, $throw = true)
{
if (is_numeric($key) and !$disallowNumeric)
{
$post = R::findOne('post', 'id = ?', [$key]);
if (!$post)
throw new SimpleException('Invalid post ID "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid post ID "' . $key . '"');
return null;
}
}
else
{
$post = R::findOne('post', 'name = ?', [$key]);
if (!$post)
throw new SimpleException('Invalid post name "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid post name "' . $key . '"');
return null;
}
}
return $post;
}
Expand Down
16 changes: 10 additions & 6 deletions src/Models/Model_Tag.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php
class Model_Tag extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$user = R::findOne('tag', 'name = ?', [$key]);
if (!$user)
throw new SimpleException('Invalid tag name "' . $key . '"');
return $user;
$tag = R::findOne('tag', 'LOWER(name) = LOWER(?)', [$key]);
if (!$tag)
{
if ($throw)
throw new SimpleException('Invalid tag name "' . $key . '"');
return null;
}
return $tag;
}

public static function insertOrUpdate($tags)
{
$dbTags = [];
foreach ($tags as $tag)
{
$dbTag = R::findOne('tag', 'name = ?', [$tag]);
$dbTag = self::locate($tag, false);
if (!$dbTag)
{
$dbTag = R::dispense('tag');
Expand Down
8 changes: 6 additions & 2 deletions src/Models/Model_User.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
class Model_User extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$user = R::findOne('user', 'name = ?', [$key]);
if (!$user)
throw new SimpleException('Invalid user name "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid user name "' . $key . '"');
return null;
}
return $user;
}

Expand Down

0 comments on commit 6b55706

Please sign in to comment.