/**
  * Returns all custom types available
  *
  * @return array
  */
 public static function getAll()
 {
     if (self::$_types === null) {
         self::$_types = tables\CustomFields::getTable()->getAll();
     }
     return self::$_types;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, Issues::getTable(), Issues::ID);
     parent::_addForeignKeyColumn(self::CUSTOMFIELDS_ID, CustomFields::getTable(), CustomFields::ID);
     parent::_addForeignKeyColumn(self::CUSTOMFIELDOPTION_ID, CustomFieldOptions::getTable(), CustomFieldOptions::ID);
     parent::_addText(self::OPTION_VALUE, false);
 }
 public function getRuleValueAsJoinedString()
 {
     $is_core = in_array($this->_name, array(self::RULE_STATUS_VALID, self::RULE_RESOLUTION_VALID, self::RULE_REPRODUCABILITY_VALID, self::RULE_PRIORITY_VALID, self::RULE_TEAM_MEMBERSHIP_VALID, self::RULE_ISSUE_IN_MILESTONE_VALID));
     $is_custom = $this->isCustom();
     $customtype = $this->getCustomType();
     if ($this->_name == self::RULE_STATUS_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Status';
     } elseif ($this->_name == self::RULE_RESOLUTION_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Resolution';
     } elseif ($this->_name == self::RULE_REPRODUCABILITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Reproducability';
     } elseif ($this->_name == self::RULE_PRIORITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Priority';
     } elseif ($this->_name == self::RULE_TEAM_MEMBERSHIP_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Team';
     } elseif ($this->_name == self::RULE_ISSUE_IN_MILESTONE_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Milestone';
     }
     if ($is_core || $is_custom) {
         $values = explode(',', $this->getRuleValue());
         if ($is_custom) {
             $custom_field_key = substr($this->_name, strlen(self::CUSTOMFIELD_VALIDATE_PREFIX) - 1);
             $custom_field = tables\CustomFields::getTable()->getByKey($custom_field_key);
         }
         $return_values = array();
         foreach ($values as $value) {
             try {
                 if ($is_core) {
                     $field = $fieldname::getB2DBTable()->selectByID((int) $value);
                 } elseif ($is_custom) {
                     switch ($customtype) {
                         case CustomDatatype::RADIO_CHOICE:
                         case CustomDatatype::DROPDOWN_CHOICE_TEXT:
                             $field = tables\CustomFieldOptions::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::TEAM_CHOICE:
                             $field = Teams::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::STATUS_CHOICE:
                             $field = ListTypes::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::MILESTONE_CHOICE:
                             $field = Milestones::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::CLIENT_CHOICE:
                             $field = Clients::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::COMPONENTS_CHOICE:
                             $field = Components::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::EDITIONS_CHOICE:
                             $field = Editions::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::RELEASES_CHOICE:
                             $field = Builds::getTable()->selectById((int) $value);
                             break;
                     }
                 }
                 if ($field instanceof \thebuggenie\core\entities\common\Identifiable) {
                     if ($field instanceof Milestone || $field instanceof Component || $field instanceof Edition || $field instanceof Build) {
                         $return_values[] = $field->getProject()->getName() . ' - ' . $field->getName();
                     } elseif ($field instanceof Status) {
                         $return_values[] = '<span class="status_badge" style="background-color: ' . $field->getColor() . '; color: ' . $field->getTextColor() . ';">' . $field->getName() . '</span>';
                     } else {
                         $return_values[] = $field->getName();
                     }
                 }
             } catch (\Exception $e) {
             }
         }
         return join(' / ', $return_values);
     } else {
         $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionValidationRule::getRuleValueAsJoinedString', $this);
         $event->triggerUntilProcessed();
         return $event->getReturnValue();
     }
 }
Beispiel #4
0
 public function getBySchemeIDandIssuetypeID($scheme_id, $issuetype_id)
 {
     $crit = $this->getCriteria();
     $crit->addJoin(CustomFields::getTable(), CustomFields::FIELD_KEY, self::FIELD_KEY);
     $crit->addWhere(self::ISSUETYPE_SCHEME_ID, $scheme_id);
     $crit->addWhere(self::ISSUETYPE_ID, $issuetype_id);
     $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
     $res = $this->doSelect($crit, false);
     return $res;
 }
Beispiel #5
0
 protected function updateCustomFields($issue_ids, $to_scope_id)
 {
     $this->cliEcho("Moving custom fields... ");
     $crit = IssueCustomFields::getTable()->getCriteria();
     $crit->addWhere('issuecustomfields.issue_id', $issue_ids, Criteria::DB_IN);
     $crit->addSelectionColumn('issuecustomfields.customfieldoption_id', 'option_id');
     $crit->addSelectionColumn('issuecustomfields.customfields_id', 'customfield_id');
     $customfields = [];
     $customfieldoptions = [];
     if ($res = IssueCustomFields::getTable()->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $customfields[] = $row['customfield_id'];
         }
     }
     $customfields_criteria = CustomFields::getTable()->getCriteria();
     $customfields_criteria->addWhere('customfields.scope', $to_scope_id);
     $customfields_criteria->indexBy('customfields.key');
     $to_scope_customfields = CustomFields::getTable()->select($customfields_criteria);
     $customfields_criteria = CustomFields::getTable()->getCriteria();
     $customfields_criteria->addWhere('customfields.scope', $this->from_scope);
     $customfields_criteria->indexBy('customfields.key');
     $from_scope_customfields = CustomFields::getTable()->select($customfields_criteria);
     foreach ($from_scope_customfields as $key => $customfield) {
         if (!array_key_exists($key, $to_scope_customfields)) {
             $new_customfield = clone $customfield;
             $new_customfield->setScope($to_scope_id);
             $new_customfield->save();
         } else {
             $new_customfield = $customfield;
         }
         $customfields[$customfield->getID()] = $new_customfield->getID();
         if ($customfield->hasCustomOptions()) {
             $custom_options = $new_customfield->getOptions();
             foreach ($customfield->getOptions() as $option) {
                 $found = false;
                 foreach ($custom_options as $custom_option) {
                     if ($custom_option->getValue() == $option->getValue()) {
                         $new_custom_option = $custom_option;
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $new_custom_option = clone $option;
                     $new_custom_option->setCustomdatatype($new_customfield);
                     $new_custom_option->setScope($to_scope_id);
                     $new_custom_option->save();
                 }
                 $customfieldoptions[$option->getID()] = $new_custom_option->getID();
             }
         }
     }
     if (count($customfields)) {
         foreach ($customfields as $old_id => $new_id) {
             $crit = IssueCustomFields::getTable()->getCriteria();
             $crit->addWhere('issuecustomfields.customfields_id', $old_id);
             $crit->addUpdate('issuecustomfields.customfields_id', $new_id);
             $crit->addUpdate('issuecustomfields.scope', $to_scope_id);
             IssueCustomFields::getTable()->doUpdate($crit);
         }
     }
     if (count($customfieldoptions)) {
         foreach ($customfieldoptions as $old_id => $new_id) {
             $crit = IssueCustomFields::getTable()->getCriteria();
             $crit->addWhere('issuecustomfields.customfieldoption_id', $old_id);
             $crit->addUpdate('issuecustomfields.customfieldoption_id', $new_id);
             $crit->addUpdate('issuecustomfields.scope', $to_scope_id);
             IssueCustomFields::getTable()->doUpdate($crit);
         }
     }
     $this->cliEcho(" done\n");
 }
 public function getRuleValueAsJoinedString()
 {
     $is_core = true;
     $is_custom = false;
     if ($this->_name == self::RULE_STATUS_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Status';
     } elseif ($this->_name == self::RULE_RESOLUTION_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Resolution';
     } elseif ($this->_name == self::RULE_REPRODUCABILITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Reproducability';
     } elseif ($this->_name == self::RULE_PRIORITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Priority';
     } elseif ($this->_name == self::RULE_TEAM_MEMBERSHIP_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Team';
     } else {
         $is_core = false;
         $is_custom = (bool) (strpos($this->_name, self::CUSTOMFIELD_VALIDATE_PREFIX) !== false);
     }
     if ($is_core || $is_custom) {
         $values = explode(',', $this->getRuleValue());
         if ($is_custom) {
             $custom_field_key = substr($this->_name, strlen(self::CUSTOMFIELD_VALIDATE_PREFIX) - 1);
             $custom_field = tables\CustomFields::getTable()->getByKey($custom_field_key);
         }
         $return_values = array();
         foreach ($values as $value) {
             try {
                 if ($is_core) {
                     $field = $fieldname::getB2DBTable()->selectByID((int) $value);
                 } elseif ($is_custom) {
                     $field = tables\CustomFieldOptions::getTable()->selectById((int) $value);
                 }
                 if ($field instanceof \thebuggenie\core\entities\common\Identifiable) {
                     $return_values[] = $field->getName();
                 }
             } catch (\Exception $e) {
             }
         }
         return join(' / ', $return_values);
     } else {
         $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionValidationRule::getRuleValueAsJoinedString', $this);
         $event->triggerUntilProcessed();
         return $event->getReturnValue();
     }
 }