Esempio n. 1
0
 /**
  * @todo Update the total of posts related to a tags
  *
  * @return bool
  */
 public function saveTagsInPosts($_tag, $object)
 {
     $tags = $this->isTags($_tag);
     if (is_array($tags)) {
         //
         $postsTags = PostsTags::find(['postsId = ?0', 'bind' => [$object->getId()]]);
         if (isset($postsTags)) {
             $postsTags->delete();
         }
         foreach ($tags as $tagsId) {
             $postsTags = new PostsTags();
             $postsTags->setTagsId($tagsId);
             $postsTags->setPostsId($object->getId());
             if (!$postsTags->save()) {
                 return false;
             }
             //Update the total of posts related to a tags
             if ($object->getOperationMade() == \Phalcon\Mvc\Model::OP_CREATE) {
                 $tag = Tags::findFirstById($tagsId);
                 $number = $tag->getNumberposts();
                 $tag->setNumberPosts($number + 1);
                 if (!$tag->save()) {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @param $postId
  * @param $tagIds
  */
 public function deletedTag($postId, $tagIds)
 {
     foreach ($tagIds as $id) {
         $object = PostsTags::find(['postsId = ?0 AND tagsId =?1', 'bind' => [$postId, $id]]);
         if ($object) {
             $object->delete();
         }
     }
 }