private function getUserValue(Tracker_FormElement_Field $field, $value)
 {
     if (isset($value['format']) && (string) $value['format'] === self::FORMAT_ID) {
         return (string) $value;
     }
     if ($this->doesValueConcernUser($value)) {
         $user = $this->xml_import_helper->getUser($value);
         if ($user->isAnonymous()) {
             return '';
         }
         return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $user->getId();
     }
     return $field->getFieldData((string) $value);
 }
 /**
  * Extract Field data from XML input
  *
  * @param Tracker_FormElement_Field $field
  * @param SimpleXMLElement $field_change
  *
  * @return array
  */
 public function getFieldData(Tracker_FormElement_Field $field, SimpleXMLElement $field_change)
 {
     $bind = (string) $field_change['bind'];
     $data = array();
     if ($bind === self::BIND_STATIC) {
         foreach ($field_change as $value) {
             $data[] = $this->getStaticListDataValue($field, $value);
         }
     } elseif ($bind === self::BIND_UGROUPS) {
         foreach ($field_change as $value) {
             $data[] = $this->getUgroupListDataValue($value);
         }
     } else {
         foreach ($field_change as $value) {
             $user = $this->xml_import_helper->getUser($value);
             $data[] = $user->getId();
         }
     }
     return $data;
 }
Example #3
0
    public function testItImportsAnonymousUser()
    {
        $user_manager = mock('UserManager');
        $import_helper = new Tracker_XMLImport_XMLImportHelper($user_manager);
        stub($user_manager)->getUserByIdentifier()->returns(null);
        stub($user_manager)->getUserAnonymous()->returns(new PFUser());
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
<user>veloc@dino.com</user>');
        $user = $import_helper->getUser($xml);
        $this->assertEqual($user->getEmail(), '*****@*****.**');
    }
 /**
  * Creates a Field_List_Bind Object
  *
  * @param SimpleXMLElement          $xml         containing the structure of the imported bind
  * @param Tracker_FormElement_Field $field       to which the bind is attached
  * @param array                     &$xmlMapping where the newly created formElements indexed by their XML IDs are stored
  *
  * @return Tooltip Object
  */
 public function getInstanceFromXML($xml, $field, &$xmlMapping)
 {
     $row = array('type' => (string) $xml['type'], 'field' => $field, 'default_values' => null, 'decorators' => null);
     if (isset($xml->decorators)) {
         $row['decorators'] = array();
         foreach ($xml->decorators->decorator as $deco) {
             $ID = (string) $deco['REF'];
             $row['decorators'][$ID] = $this->getDecoratorInstance($field, $ID, (int) $deco['r'], (int) $deco['g'], (int) $deco['b']);
         }
     }
     $type = (string) $xml['type'];
     switch ($type) {
         case self::STATIK:
             $row['is_rank_alpha'] = (int) $xml['is_rank_alpha'];
             $values = array();
             if ($xml->items->item) {
                 $i = 0;
                 foreach ($xml->items->item as $item) {
                     $ID = (string) $item['ID'];
                     $description = '';
                     if (isset($item->description)) {
                         $description = (string) $item->description;
                     }
                     $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0;
                     $values[$ID] = $this->getStaticValueInstance($ID, (string) $item['label'], $description, $i++, $is_hidden);
                     $xmlMapping[$ID] = $values[$ID];
                 }
             }
             $row['values'] = $values;
             break;
         case self::USERS:
             $values = array();
             if ($xml->items->item) {
                 foreach ($xml->items->item as $item) {
                     $values[] = (string) $item['label'];
                 }
             }
             $row['value_function'] = implode(',', $values);
             break;
         case self::UGROUPS:
             $values = array();
             if ($xml->items->item) {
                 foreach ($xml->items->item as $item) {
                     $ugroup = $this->ugroup_manager->getUGroupByName($field->getTracker()->getProject(), (string) $item['label']);
                     if ($ugroup) {
                         $ID = (string) $item['ID'];
                         $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0;
                         $values[$ID] = new Tracker_FormElement_Field_List_Bind_UgroupsValue($ID, $ugroup, $is_hidden);
                         $xmlMapping[$ID] = $values[$ID];
                     }
                 }
             }
             $row['values'] = array_filter($values);
             break;
         default:
             break;
     }
     if (isset($xml->default_values)) {
         $row['default_values'] = array();
         foreach ($xml->default_values->value as $default_value) {
             if (isset($default_value['REF'])) {
                 $ID = (string) $default_value['REF'];
                 if (isset($xmlMapping[$ID])) {
                     $row['default_values'][$ID] = $xmlMapping[$ID];
                 }
             } else {
                 $xml_helper = new Tracker_XMLImport_XMLImportHelper(UserManager::instance());
                 $user = $xml_helper->getUser($default_value);
                 $row['default_values'][$user->getId()] = new Tracker_FormElement_Field_List_Bind_UsersValue($user->getId());
             }
         }
     }
     return $this->getInstanceFromRow($row);
 }
Example #5
0
 private function getSubmittedBy(SimpleXMLElement $xml_changeset)
 {
     return $this->xml_import_helper->getUser($xml_changeset->submitted_by);
 }