Skip to content

Commit

Permalink
Fixed #192
Browse files Browse the repository at this point in the history
  • Loading branch information
Parziphal committed Aug 14, 2016
1 parent 48b182b commit b009bb7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
32 changes: 22 additions & 10 deletions app/models/TagSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected function associations()
]
];
}

protected function callbacks()
{
return [
Expand All @@ -21,7 +21,7 @@ protected function callbacks()
]
];
}

protected function scopes()
{
return [
Expand All @@ -30,7 +30,7 @@ protected function scopes()
}
];
}

public function normalize_name()
{
/**
Expand All @@ -40,26 +40,26 @@ public function normalize_name()
*/
$this->name = preg_replace(['/\P{L}/', '/_{2,}/'], '_', mb_convert_encoding($this->name, 'ISO-8859-2'));
}

public function initialize_post_ids()
{
if ($this->user->is_privileged_or_higher()) {
$this->cached_post_ids = join(',', array_unique(Post::find_by_tags($this->tag_query, ['limit' => ceil(CONFIG()->tag_subscription_post_limit / 3), 'select' => 'p.id', 'order' => 'p.id desc'])->getAttributes('id')));
}
}

static public function find_post_ids($user_id, $name = null, $limit = null)
{
if (!$limit) {
$limit = CONFIG()->tag_subscription_post_limit;
}

$post_ids = self::select('cached_post_ids')->where(['user_id' => $user_id]);
if ($name) {
$post_ids->where('name LIKE ?', $name . '%');
}
$post_ids = $post_ids->take();

$parsed_ids = [];
foreach ($post_ids as $subs) {
$ids = explode(',', $subs->cached_post_ids);
Expand All @@ -69,15 +69,15 @@ static public function find_post_ids($user_id, $name = null, $limit = null)
$parsed_ids = array_merge($parsed_ids, $ids);
}
sort($parsed_ids);

return array_slice(array_reverse(array_unique($parsed_ids)), 0, $limit);
}

static public function find_posts($user_id, $name = null, $limit = null)
{
return Post::available()->where('id IN (?)', self::find_post_ids($user_id, $name, $limit))->order('id DESC')->take();
}

static public function process_all()
{
foreach (self::all() as $tag_subscription) {
Expand Down Expand Up @@ -110,4 +110,16 @@ static public function process_all()
}
}
}

protected function validations()
{
return [
'name' => [
'length' => ['minimum' => 1]
],
'tag_query' => [
'length' => ['minimum' => 1]
],
];
}
}
4 changes: 2 additions & 2 deletions app/views/tag_subscription/_listing_row.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tr id="tag-subscription-row-<?= $this->tag_subscription->id ?>">
<td><input onclick="new Ajax.Request('<?= $this->urlFor(['tag_subscription#destroy', 'id' => $this->tag_subscription->id, 'format' => 'js']) ?>', {asynchronous:true, evalScripts:true});" type="button" value="<?= '-' ?>"></td>
<td><?= $this->textFieldTag("tag_subscription[".$this->tag_subscription->id."][name]", $this->tag_subscription->name, ['size' => 20]) ?></td>
<td><?= $this->textFieldTag("tag_subscription[".$this->tag_subscription->id."][tag_query]", $this->tag_subscription->tag_query, ['size' => 70]) ?></td>
<td><?= $this->textFieldTag("tag_subscription[".$this->tag_subscription->id."][name]", $this->tag_subscription->name, ['size' => 20, 'required']) ?></td>
<td><?= $this->textFieldTag("tag_subscription[".$this->tag_subscription->id."][tag_query]", $this->tag_subscription->tag_query, ['size' => 70, 'required']) ?></td>
<td>
<?= $this->selectTag("tag_subscription[".$this->tag_subscription->id."][is_visible_on_profile]", $this->optionsForSelect(["Visible" => 1, "Hidden" => 0], $this->tag_subscription->is_visible_on_profile)) ?>
</td>
Expand Down

0 comments on commit b009bb7

Please sign in to comment.