diff --git a/app/models/TagSubscription.php b/app/models/TagSubscription.php index fa15fdc..a97fcf8 100755 --- a/app/models/TagSubscription.php +++ b/app/models/TagSubscription.php @@ -9,7 +9,7 @@ class TagSubscription extends Rails\ActiveRecord\Base ] ]; } - + protected function callbacks() { return [ @@ -21,7 +21,7 @@ class TagSubscription extends Rails\ActiveRecord\Base ] ]; } - + protected function scopes() { return [ @@ -30,7 +30,7 @@ class TagSubscription extends Rails\ActiveRecord\Base } ]; } - + public function normalize_name() { /** @@ -40,26 +40,26 @@ class TagSubscription extends Rails\ActiveRecord\Base */ $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); @@ -69,15 +69,15 @@ class TagSubscription extends Rails\ActiveRecord\Base $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) { @@ -110,4 +110,16 @@ class TagSubscription extends Rails\ActiveRecord\Base } } } + + protected function validations() + { + return [ + 'name' => [ + 'length' => ['minimum' => 1] + ], + 'tag_query' => [ + 'length' => ['minimum' => 1] + ], + ]; + } } diff --git a/app/views/tag_subscription/_listing_row.php b/app/views/tag_subscription/_listing_row.php index d424eea..4c61e5c 100755 --- a/app/views/tag_subscription/_listing_row.php +++ b/app/views/tag_subscription/_listing_row.php @@ -1,7 +1,7 @@ - textFieldTag("tag_subscription[".$this->tag_subscription->id."][name]", $this->tag_subscription->name, ['size' => 20]) ?> - textFieldTag("tag_subscription[".$this->tag_subscription->id."][tag_query]", $this->tag_subscription->tag_query, ['size' => 70]) ?> + textFieldTag("tag_subscription[".$this->tag_subscription->id."][name]", $this->tag_subscription->name, ['size' => 20, 'required']) ?> + textFieldTag("tag_subscription[".$this->tag_subscription->id."][tag_query]", $this->tag_subscription->tag_query, ['size' => 70, 'required']) ?> selectTag("tag_subscription[".$this->tag_subscription->id."][is_visible_on_profile]", $this->optionsForSelect(["Visible" => 1, "Hidden" => 0], $this->tag_subscription->is_visible_on_profile)) ?>