Example #1
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($tag = Doctrine_Core::getTable('Tag')->find(array($request->getParameter('id'))), sprintf('Object tag does not exist (%s).', $request->getParameter('id')));
     $team_members = sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getUser()->getGuardUser())->execute();
     $team_members_id = array();
     foreach ($team_members as $team_member) {
         $team_members_id[] = $team_member->id;
     }
     if (in_array($tag->user_id, $team_members_id)) {
         $tagAlternatives = TagAlternativeTable::getInstance()->findByTagId($tag->id);
         foreach ($tagAlternatives as $tagAlternative) {
             Doctrine_Query::create()->delete('Graph')->where('decision_id = ?', $tagAlternative->Alternative->decision_id)->execute();
         }
         Doctrine_Query::create()->delete('TagAlternative')->where('tag_id = ?', $tag->id)->execute();
         Doctrine_Query::create()->delete('TagDecision')->where('tag_id = ?', $tag->id)->execute();
         $tag->delete();
     }
     $this->redirect('tag/index');
 }
Example #2
0
 public function load()
 {
     /** @var RoleFilter[] $roleFilters  */
     $alternatives = AlternativeTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($alternatives as $alternative) {
         $tagAlternatives = TagAlternativeTable::getInstance()->findBy('alternative_id', $alternative->id);
         foreach ($tagAlternatives as $tagAlternative) {
             $this->tags[$tagAlternative->Tag->id] = $tagAlternative->Tag->name;
         }
     }
     /** @var RoleFilter[] $roleFilters  */
     $tagFilters = TagFilterTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($tagFilters as $tagFilter) {
         $this->data[] = $tagFilter->Tag->name;
         $ta_by_name = Doctrine_Query::create()->from('TagAlternative ta')->select('ta.id as id, a.id as a_id')->leftJoin('ta.Tag t')->leftJoin('ta.Alternative a')->where("t.name = ?", $tagFilter->Tag->name)->andWhere('a.decision_id = ?', $this->decision_id)->execute();
         foreach ($ta_by_name as $v) {
             $this->data_for_sql[] = $v->a_id;
         }
     }
     $this->tags = array_unique($this->tags);
 }
Example #3
0
 /**
  * @param sfGuardUser $user
  * @param integer $element_id
  * @param string $name
  * @param string $type
  */
 public static function removeTag($user, $element_id, $name, $type)
 {
     if ($type == 'decision') {
         $tagBridge = Doctrine_Core::getTable('TagDecision')->createQuery('td')->leftJoin('td.Tag t')->where('td.decision_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne();
     } else {
         if ($type == 'release') {
             $tagBridge = Doctrine_Core::getTable('TagRelease')->createQuery('td')->leftJoin('td.Tag t')->where('td.release_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne();
         } else {
             $tagBridge = Doctrine_Core::getTable('TagAlternative')->createQuery('ta')->leftJoin('ta.Tag t')->where('ta.alternative_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne();
         }
     }
     if ($tagBridge) {
         $tagBridge->delete();
         $tagDecision = TagDecisionTable::getInstance()->findOneByTagId($tagBridge->tag_id);
         if (!$tagDecision) {
             $tagAlternative = TagAlternativeTable::getInstance()->findOneByTagId($tagBridge->tag_id);
             if (!$tagAlternative) {
                 TagTable::getInstance()->find($tagBridge->tag_id)->delete();
             }
         }
     }
     return;
 }