public function hasValidTarget()
 {
     if (!$this->_target_value) {
         return true;
     }
     switch ($this->_action_type) {
         case self::ACTION_ASSIGN_ISSUE:
             $target_details = explode('_', $this->_target_value);
             return (bool) ($target_details[0] == 'user') ? \thebuggenie\core\entities\User::doesIDExist($target_details[1]) : Team::doesIDExist($target_details[1]);
             break;
         case self::ACTION_SET_PERCENT:
             return (bool) ($this->_target_value > -1);
             break;
         case self::ACTION_SET_MILESTONE:
             return (bool) Milestone::doesIDExist($this->_target_value);
             break;
         case self::ACTION_SET_PRIORITY:
             return (bool) Priority::has($this->_target_value);
             break;
         case self::ACTION_SET_STATUS:
             return (bool) Status::has($this->_target_value);
             break;
         case self::ACTION_SET_REPRODUCABILITY:
             return (bool) Reproducability::has($this->_target_value);
             break;
         case self::ACTION_SET_RESOLUTION:
             return (bool) Resolution::has($this->_target_value);
             break;
         default:
             return true;
     }
 }
 public function isValid($input)
 {
     switch ($this->_name) {
         case self::RULE_MAX_ASSIGNED_ISSUES:
             $num_issues = (int) $this->getRuleValue();
             return $num_issues ? (bool) (count(framework\Context::getUser()->getUserAssignedIssues()) < $num_issues) : true;
             break;
         case self::RULE_TEAM_MEMBERSHIP_VALID:
             $valid_items = explode(',', $this->getRuleValue());
             $teams = \thebuggenie\core\entities\Team::getAll();
             if ($this->isPost()) {
                 if ($input instanceof \thebuggenie\core\entities\Issue) {
                     $assignee = $input->getAssignee();
                 }
             }
             if (!isset($assignee)) {
                 $assignee = framework\Context::getUser();
             }
             if ($assignee instanceof \thebuggenie\core\entities\User) {
                 if (count($valid_items) == 1 && reset($valid_items) == '') {
                     return true;
                 }
                 foreach ($valid_items as $team_id) {
                     if ($assignee->isMemberOfTeam($teams[$team_id])) {
                         return true;
                     }
                 }
             } elseif ($assignee instanceof \thebuggenie\core\entities\Team) {
                 foreach ($valid_items as $team_id) {
                     if ($assignee->getID() == $team_id) {
                         return true;
                     }
                 }
             }
             return false;
         case self::RULE_ISSUE_IN_MILESTONE_VALID:
             $valid_items = explode(',', $this->getRuleValue());
             if ($input instanceof \thebuggenie\core\entities\Issue) {
                 $issue = $input;
             } else {
                 if ($input->hasParameter('issue_id')) {
                     $issue = \thebuggenie\core\entities\Issue::getB2DBTable()->selectByID((int) $input->getParameter('issue_id'));
                 }
             }
             if (isset($issue) && $issue instanceof \thebuggenie\core\entities\Issue) {
                 if (!$issue->getMilestone() instanceof \thebuggenie\core\entities\Milestone) {
                     return false;
                 }
                 if (count($valid_items) == 1 && reset($valid_items) == '') {
                     return true;
                 }
                 return in_array($issue->getMilestone()->getID(), $valid_items);
             }
             return false;
         case self::RULE_STATUS_VALID:
         case self::RULE_PRIORITY_VALID:
         case self::RULE_RESOLUTION_VALID:
         case self::RULE_REPRODUCABILITY_VALID:
             $valid_items = explode(',', $this->getRuleValue());
             $valid = false;
             if ($this->_name == self::RULE_STATUS_VALID) {
                 $fieldname = 'Status';
                 $fieldname_small = 'status';
             } elseif ($this->_name == self::RULE_RESOLUTION_VALID) {
                 $fieldname = 'Resolution';
                 $fieldname_small = 'resolution';
             } elseif ($this->_name == self::RULE_REPRODUCABILITY_VALID) {
                 $fieldname = 'Reproducability';
                 $fieldname_small = 'reproducability';
             } elseif ($this->_name == self::RULE_PRIORITY_VALID) {
                 $fieldname = 'Priority';
                 $fieldname_small = 'priority';
             } else {
                 throw new framework\exceptions\ConfigurationException(framework\Context::getI18n()->__('Invalid workflow validation rule: %rule_name', array('%rule_name' => $this->_name)));
             }
             if (!$this->getRuleValue()) {
                 if ($input instanceof \thebuggenie\core\entities\Issue) {
                     $getter = "get{$fieldname}";
                     if (is_object($input->{$getter}())) {
                         $valid = true;
                     }
                 } elseif ($input instanceof framework\Request) {
                     if ($input->getParameter("{$fieldname_small}_id") && Status::has($input->getParameter("{$fieldname_small}_id"))) {
                         $valid = true;
                     }
                 }
             } else {
                 foreach ($valid_items as $item) {
                     if ($input instanceof \thebuggenie\core\entities\Issue) {
                         $type = "\\thebuggenie\\core\\entities\\{$fieldname}";
                         $getter = "get{$fieldname}";
                         if (is_object($input->{$getter}()) && $type::getB2DBTable()->selectByID((int) $item)->getID() == $input->{$getter}()->getID()) {
                             $valid = true;
                             break;
                         }
                     } elseif ($input instanceof framework\Request) {
                         if ($input->getParameter("{$fieldname_small}_id") == $item) {
                             $valid = true;
                             break;
                         }
                     }
                 }
             }
             return $valid;
             break;
         default:
             if ($this->isCustom()) {
                 switch ($this->getCustomType()) {
                     case CustomDatatype::RADIO_CHOICE:
                     case CustomDatatype::DROPDOWN_CHOICE_TEXT:
                     case CustomDatatype::TEAM_CHOICE:
                     case CustomDatatype::STATUS_CHOICE:
                     case CustomDatatype::MILESTONE_CHOICE:
                     case CustomDatatype::CLIENT_CHOICE:
                     case CustomDatatype::COMPONENTS_CHOICE:
                     case CustomDatatype::EDITIONS_CHOICE:
                     case CustomDatatype::RELEASES_CHOICE:
                         $valid_items = explode(',', $this->getRuleValue());
                         if ($input instanceof \thebuggenie\core\entities\Issue) {
                             $value = $input->getCustomField($this->getCustomFieldname());
                         } elseif ($input instanceof framework\Request) {
                             $value = $input->getParameter($this->getCustomFieldname() . "_id");
                         }
                         $valid = false;
                         if (!$this->getRuleValue()) {
                             foreach ($this->getCustomField()->getOptions() as $item) {
                                 if ($item->getID() == $value) {
                                     $valid = true;
                                     break;
                                 }
                             }
                         } else {
                             foreach ($valid_items as $item) {
                                 if ($value instanceof Identifiable && $value->getID() == $item) {
                                     $valid = true;
                                     break;
                                 } elseif (is_numeric($value) && $value == $item) {
                                     $valid = true;
                                     break;
                                 }
                             }
                         }
                         return $valid;
                         break;
                 }
             } else {
                 $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionValidationRule::isValid', $this);
                 $event->setReturnValue(false);
                 $event->triggerUntilProcessed(array('input' => $input));
                 return $event->getReturnValue();
             }
     }
 }