예제 #1
0
 public function removeFlag($object, $flag, UserInterface $user = null)
 {
     parent::removeFlag($object, $flag, $user);
     /** remove recusivly to the childs */
     foreach ($object->getTopics() as $topic) {
         parent::removeFlag($topic, $flag, $user);
         foreach ($topic->getPosts() as $post) {
             parent::removeFlag($post, $flag, $user);
         }
     }
     // remove flag also from parent
     // but only if the parent has not the same flag for a other child
     $parent = $object->getParent();
     if (is_object($parent)) {
         $subforums = $parent->getChildren();
         $otherFlag = false;
         foreach ($subforums as $subforum) {
             $otherFlag = $this->findOne($flag, $subforum, $user);
             if ($otherFlag) {
                 break;
             }
         }
         if (!$otherFlag) {
             $this->removeFlag($parent, $flag, $user);
         }
     }
 }
예제 #2
0
 /**
  * @param $object
  * @param $flag
  * @param UserInterface $user
  * @param bool $flushEm
  */
 public function insertFlag($object, $flag, UserInterface $user = null, $flushEm = true)
 {
     $ignore = false;
     // if we add a topic "new" flag, we need to check if the user has read access to the forum
     // an we must check if the user has ignore the forum
     if ($flag === AbstractFlagHandler::FLAG_NEW) {
         $access = $this->securityContext->isGranted(ForumVoter::VIEW, $object->getForum(), $user);
         if ($access) {
             $ignore = $this->forumFlagHandler->checkFlag($object->getForum(), 'ignore', $user);
         } else {
             $ignore = true;
         }
     }
     if (!$ignore) {
         parent::insertFlag($object, $flag, $user, $flushEm);
         if ($flag === AbstractFlagHandler::FLAG_NEW) {
             // insert to all parents ( recrusivly )
             $parent = $object->getForum();
             do {
                 if (is_object($parent)) {
                     parent::insertFlag($parent, $flag, $user, $flushEm);
                 } else {
                     break;
                 }
             } while ($parent = $parent->getParent());
             // insert to all posts (childs)
             foreach ($object->getPosts() as $post) {
                 parent::insertFlag($post, $flag, $user, $flushEm);
             }
         }
     }
 }
예제 #3
0
 /**
  * remove the flag an look recrusivily up if the parent has only this child with this flag
  * @param $object
  * @param $flag
  * @param UserInterface $user
  */
 public function removeFlag($object, $flag, UserInterface $user = null)
 {
     parent::removeFlag($object, $flag, $user);
     $otherPostsHasThisFlag = false;
     foreach ($object->getTopic()->getPosts() as $post) {
         if ($this->checkFlag($post, $flag, $user)) {
             $otherPostsHasThisFlag = true;
             break;
         }
     }
     if (!$otherPostsHasThisFlag) {
         parent::removeFlag($object->getTopic(), $flag, $user);
         $otherTopicsHasThisFlag = false;
         // remove from parents if the child is the only one with that flag
         $parent = $object->getTopic()->getForum();
         do {
             if (is_object($parent)) {
                 $topics = $parent->getTopics();
                 $otherFlagFound = false;
                 foreach ($topics as $topic) {
                     $otherFlagFound = $this->checkFlag($topic, $flag, $user);
                     if ($otherFlagFound) {
                         break;
                     }
                 }
                 if (!$otherFlagFound) {
                     parent::removeFlag($parent, $flag, $user);
                 }
             } else {
                 break;
             }
         } while ($parent = $parent->getParent());
     }
 }