コード例 #1
0
 /**
  * The Id of the (list) field used for contributor semantic
  * 
  * @return int The Id of the (list) field used for contributor semantic, or 0 if no field
  */
 public function getFieldId()
 {
     if ($this->list_field) {
         return $this->list_field->getId();
     } else {
         return 0;
     }
 }
コード例 #2
0
 /**
  * Display the basic info about this semantic
  *
  * @return string html
  */
 public function display()
 {
     if ($this->list_field) {
         echo $GLOBALS['Language']->getText('plugin_tracker_admin_semantic', 'status_long_desc', array($this->list_field->getLabel()));
         if ($this->open_values) {
             echo '<ul>';
             $field_values = $this->list_field->getAllValues();
             foreach ($this->open_values as $v) {
                 if (isset($field_values[$v])) {
                     echo '<li><strong>' . $field_values[$v]->getLabel() . '</strong></li>';
                 }
             }
             echo '</ul>';
         } else {
             echo '<blockquote><em>' . $GLOBALS['Language']->getText('plugin_tracker_admin_semantic', 'status_no_value') . '</em></blockquote>';
         }
     } else {
         echo $GLOBALS['Language']->getText('plugin_tracker_admin_semantic', 'status_no_field');
     }
 }
コード例 #3
0
 public function getDefaultValue()
 {
     $default_values = parent::getDefaultValue();
     if (!$default_values) {
         return '';
     }
     //all default values must be binded
     return self::BIND_PREFIX . implode(',' . self::BIND_PREFIX, $default_values);
 }
 public function getFieldDataFromRESTObject(array $rest_data, Tracker_FormElement_Field_List $field)
 {
     $project = $field->getTracker()->getProject();
     if (isset($rest_data['id'])) {
         $representation_class = '\\Tuleap\\Project\\REST\\UserGroupRepresentation';
         $value = call_user_func_array($representation_class . '::getProjectAndUserGroupFromRESTId', array($rest_data['id']));
         $id = $value['user_group_id'];
         $bind_value = $this->getValueByUGroupId($id);
         if ($bind_value) {
             return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $bind_value->getId();
         }
         $user_group = $this->ugroup_manager->getUGroup($project, $id);
         if (!$user_group) {
             throw new Tracker_FormElement_InvalidFieldValueException('User Group with ID ' . $id . ' does not exist for field ID ' . $field->getId());
         }
         if (!$bind_value) {
             $identifier = $user_group->getName();
         }
     } else {
         if (isset($rest_data['short_name'])) {
             $name = (string) $rest_data['short_name'];
             $user_group = $this->ugroup_manager->getUGroupByName($project, $name);
             if (!$user_group) {
                 throw new Tracker_FormElement_InvalidFieldValueException('User Group with short_name ' . $name . ' does not exist for field ID ' . $field->getId());
             }
             $identifier = $name;
         } else {
             throw new Tracker_FormElement_InvalidFieldValueException('OpenList static fields values should be passed as an object with at least one of the properties "id" or "short_name"');
         }
     }
     $row = $this->getOpenValueDao()->searchByExactLabel($field->getId(), $identifier)->getRow();
     if ($row) {
         return Tracker_FormElement_Field_OpenList::OPEN_PREFIX . $row['id'];
     }
     return Tracker_FormElement_Field_OpenList::NEW_VALUE_PREFIX . $identifier;
 }
 public function getFieldDataFromRESTObject(array $rest_data, Tracker_FormElement_Field_List $field)
 {
     if (isset($rest_data['id']) && is_numeric($rest_data['id'])) {
         $id = (int) $rest_data['id'];
         try {
             $this->getValue($id);
         } catch (Tracker_FormElement_InvalidFieldValueException $e) {
             if (!$this->getOpenValueDao()->searchById($field->getId(), $id)->getRow()) {
                 throw new Tracker_FormElement_InvalidFieldValueException('Bind Value with ID ' . $id . ' does not exist for field ID ' . $field->getId());
             }
             return Tracker_FormElement_Field_OpenList::OPEN_PREFIX . $id;
         }
         return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $id;
     }
     if (isset($rest_data['label'])) {
         $identifier = (string) $rest_data['label'];
     } else {
         throw new Tracker_FormElement_InvalidFieldValueException('OpenList static fields values should be passed as an object with at least one of the properties "id" or "label"');
     }
     $row = $this->getOpenValueDao()->searchByExactLabel($field->getId(), $identifier)->getRow();
     if ($row) {
         return Tracker_FormElement_Field_OpenList::OPEN_PREFIX . $row['id'];
     }
     return Tracker_FormElement_Field_OpenList::NEW_VALUE_PREFIX . $identifier;
 }
コード例 #6
0
 /**
  * Hook called after a creation of a field
  *
  * @param array $data The data used to create the field
  *
  * @return void
  */
 public function afterCreate($formElement_data)
 {
     //force the bind
     $formElement_data['bind-type'] = 'users';
     $formElement_data['bind'] = array('value_function' => array('artifact_submitters'));
     parent::afterCreate($formElement_data);
 }
コード例 #7
0
 /**
  * Add some additionnal information beside the field in the submit new artifact form.
  * This is up to the field. It can be html or inline javascript
  * to enhance the user experience
  * @return string
  */
 public function fetchSubmitAdditionnalInfo($submitted_values)
 {
     $html = parent::fetchSubmitAdditionnalInfo($submitted_values);
     if ($this->isJavascriptIncludedInValue($submitted_values)) {
         $html .= $this->displaySubmitJavascript();
     }
     return $html;
 }
コード例 #8
0
 private function getMatchingValueById(Tracker_FormElement_Field_List $field, $value_id)
 {
     foreach ($field->getAllValues() as $value) {
         if ($value->getId() == $value_id) {
             return $value;
         }
     }
     throw new Tracker_FormElement_InvalidFieldValueException("Value doesn't belong to field");
 }
 public function getFieldDataFromRESTObject(array $rest_data, Tracker_FormElement_Field_List $field)
 {
     if (isset($rest_data['id']) && is_numeric($rest_data['id'])) {
         $id = (int) $rest_data['id'];
         $user = $this->getValue($id);
         if (!$user) {
             throw new Tracker_FormElement_InvalidFieldValueException('Cannot Bind to user with ID ' . $id . ' for field ID ' . $field->getId());
         }
         return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $id;
     }
     if (isset($rest_data['username'])) {
         $identifier = (string) $rest_data['username'];
         $user = $this->userManager->getUserByIdentifier($identifier);
         if (!$user) {
             throw new Tracker_FormElement_InvalidFieldValueException('Cannot Bind to user "' . $identifier . '" for field ID ' . $field->getId());
         }
         return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $user->getId();
     }
     if (!isset($rest_data['email'])) {
         throw new Tracker_FormElement_InvalidFieldValueException('OpenList user fields values should be passed as an object with at least one of the properties "id", "username" or "email"');
     }
     $identifier = (string) $rest_data['email'];
     $user = $this->userManager->getUserByIdentifier("email:{$identifier}");
     if (!$user) {
         return Tracker_FormElement_Field_OpenList::NEW_VALUE_PREFIX . $identifier;
     }
     return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $user->getId();
 }
コード例 #10
0
 public function isBasedOnASharedField()
 {
     return $this->list_field->isTargetSharedField();
 }
コード例 #11
0
 public function getRESTAvailableValues()
 {
     $type = $this->getBind()->getType();
     if ($type === Tracker_FormElement_Field_List_Bind_Users::TYPE) {
         return array('resource' => array('type' => 'users', 'uri' => 'users/?query='));
     }
     if ($type === Tracker_FormElement_Field_List_Bind_Ugroups::TYPE) {
         $class_user_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation';
         $ugroup_manager = new UGroupManager();
         $project = $this->getTracker()->getProject();
         $user_groups = $ugroup_manager->getUGroups($project);
         $values = array();
         foreach ($user_groups as $ugroup) {
             $ugroup_representation = new $class_user_representation();
             $ugroup_representation->build($project->getID(), $ugroup);
             $values[] = $ugroup_representation;
         }
         return $values;
     }
     return parent::getRESTAvailableValues();
 }
コード例 #12
0
 /**
  * Add some additionnal information beside the field in the submit new artifact form.
  * This is up to the field. It can be html or inline javascript
  * to enhance the user experience
  * @return string
  */
 public function fetchSubmitAdditionnalInfo()
 {
     $html = parent::fetchSubmitAdditionnalInfo();
     $html .= $this->displaySubmitJavascript();
     return $html;
 }
 public function afterCreate($formElement_data)
 {
     $formElement_data['bind-type'] = 'users';
     $formElement_data['bind'] = array('value_function' => array('artifact_modifiers'));
     parent::afterCreate($formElement_data);
 }
コード例 #14
0
 public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user)
 {
     parent::process($layout, $request, $current_user);
     switch ($request->get('func')) {
         case 'textboxlist':
             if ($request->get('keyword')) {
                 echo $this->textboxlist($request->get('keyword'));
             } else {
                 echo '[]';
             }
             exit;
             break;
     }
 }
コード例 #15
0
 public function isFieldBoundToStaticValues()
 {
     $bindType = $this->list_field->getBind()->getType();
     return $bindType == Tracker_FormElement_Field_List_Bind_Static::TYPE;
 }