Exemplo n.º 1
0
 public static function fromInput(JitFilter $input, array $typeInfo)
 {
     $options = new Tracker_Options();
     $options->info = $typeInfo;
     foreach ($typeInfo['params'] as $key => $info) {
         $filter = $info['filter'];
         if (isset($info['count']) && $info['count'] === '*') {
             $rawValue = $input->{$key}->none();
             if ($rawValue !== '') {
                 $values = explode(',', $rawValue);
                 $filter = TikiFilter::get($filter);
                 $values = array_map(array($filter, 'filter'), $values);
             } else {
                 $values = '';
             }
             $options->setParam($key, $values);
         } elseif (isset($info['separator'])) {
             $input->replaceFilter($key, $filter);
             $values = $input->asArray($key, $info['separator']);
             $options->setParam($key, $values);
         } else {
             $options->setParam($key, $input->{$key}->{$filter}());
         }
     }
     return $options;
 }
Exemplo n.º 2
0
 function __construct($fieldInfo, $itemData, $trackerDefinition)
 {
     $this->options = Tracker_Options::fromSerialized($fieldInfo['options'], $fieldInfo);
     if (!isset($fieldInfo['options_array'])) {
         $fieldInfo['options_array'] = $this->options->buildOptionsArray();
     }
     $this->definition = $fieldInfo;
     $this->itemData = $itemData;
     $this->trackerDefinition = $trackerDefinition;
 }
Exemplo n.º 3
0
 static function export(Tiki_Profile_Writer $writer, $field)
 {
     if (!is_array($field)) {
         $trklib = TikiLib::lib('trk');
         $field = $trklib->get_tracker_field($field);
         if (!$field) {
             return false;
         }
     }
     $factory = new Tracker_Field_Factory();
     $fieldInfo = $factory->getFieldInfo($field['type']);
     $options = Tracker_Options::fromSerialized($field['options'], $fieldInfo);
     $optionsData = array_filter($options->getAllParameters());
     foreach ($optionsData as $key => $value) {
         $paramInfo = $options->getParamDefinition($key);
         if (isset($paramInfo['profile_reference'])) {
             $optionsData[$key] = $writer->getReference($paramInfo['profile_reference'], $value);
         }
     }
     $data = array('name' => $field['name'], 'permname' => $field['permName'], 'tracker' => $writer->getReference('tracker', $field['trackerId']), 'options' => $optionsData);
     $optionMap = array_flip(self::getOptionMap());
     $defaults = self::getDefaultValues();
     $conversions = self::getConverters();
     $flag = array();
     foreach ($field as $key => $value) {
         if (empty($optionMap[$key])) {
             continue;
         }
         $optionKey = $optionMap[$key];
         $default = '';
         if (isset($defaults[$optionKey])) {
             $default = $defaults[$optionKey];
         }
         if ($value != $default) {
             if (in_array($optionKey, array('list', 'link', 'searchable', 'public', 'mandatory', 'multilingual'))) {
                 if (!empty($value)) {
                     $flag[] = $optionKey;
                 }
             } elseif (!empty($conversions[$optionKey])) {
                 $reverseVal = $conversions[$optionKey]->reverse($value);
                 $data[$optionKey] = $reverseVal;
             } else {
                 $data[$optionKey] = $value;
             }
         }
     }
     if (!empty($flag)) {
         $data['flags'] = $flag;
     }
     $writer->addObject('tracker_field', $field['fieldId'], $data);
     return true;
 }
function upgrade_20130513_convert_tracker_field_parameters_tiki($installer)
{
    // Using an old version of the definition could be critical here, so making sure
    // a fresh one is used
    $cachelib = TikiLib::lib('cache');
    $oldCache = $cachelib->replaceImplementation(new CacheLibNoCache());
    $fields = $installer->fetchAll('SELECT fieldId, type, options FROM tiki_tracker_fields');
    $factory = new Tracker_Field_Factory();
    $table = $installer->table('tiki_tracker_fields');
    foreach ($fields as $field) {
        $info = $factory->getFieldInfo($field['type']);
        $options = Tracker_Options::fromString($field['options'], $info);
        $table->update(array('options' => $options->serialize()), array('fieldId' => $field['fieldId']));
    }
    $cachelib->replaceImplementation($oldCache);
}
Exemplo n.º 5
0
 function parseOptions($raw, $typeInfo)
 {
     $options = Tracker_Options::fromSerialized($raw, $typeInfo);
     return $options->getAllParameters();
 }
Exemplo n.º 6
0
 function testBuildLegacyStringBuilder()
 {
     $options = Tracker_Options::fromSerialized(json_encode(array('a' => 3, 'b' => 2, 'c' => 1)), array('params' => array('a' => array('legacy_index' => 2), 'b' => array('legacy_index' => 1), 'c' => array('legacy_index' => 0), 'd' => array())));
     $this->assertEquals(array('1', '2', '3'), $options->buildOptionsArray());
 }
Exemplo n.º 7
0
 public function copy_item($from, $to, $except = null, $only = null, $status = null)
 {
     global $user, $prefs;
     if ($prefs['feature_categories'] == 'y') {
         $categlib = TikiLib::lib('categ');
         $cats = $categlib->get_object_categories('trackeritem', $from);
     }
     if (empty($to)) {
         $is_new = 'y';
         $info_to['trackerId'] = $this->items()->fetchOne('trackerId', array('itemId' => $from));
         $info_to['status'] = empty($status) ? $this->items()->fetchOne('status', array('itemId' => $from)) : $status;
         $info_to['created'] = $info_to['lastModif'] = $this->now;
         $info_to['createdBy'] = $info_to['lastModifBy'] = $user;
         $to = $this->items()->insert($info_to);
     }
     $query = 'select ttif.*, ttf.`type`, ttf.`options` from `tiki_tracker_item_fields` ttif left join `tiki_tracker_fields` ttf on (ttif.`fieldId` = ttf.`fieldId`) where `itemId`=?';
     $result = $this->fetchAll($query, array($from));
     $clean = array();
     $factory = new Tracker_Field_Factory();
     foreach ($result as $res) {
         $typeInfo = $factory->getFieldInfo($res['type']);
         $options = Tracker_Options::fromSerialized($res['options'], $typeInfo);
         $res['options_array'] = $options->buildOptionsArray();
         if ($prefs['feature_categories'] == 'y' && $res['type'] == 'e') {
             //category
             if (!empty($except) && in_array($res['fieldId'], $except) || !empty($only) && !in_array($res['fieldId'], $only)) {
                 // take away the categories from $cats
                 if (ctype_digit($res['options_array'][0]) && $res['options_array'][0] > 0) {
                     $filter = array('identifier' => $res['options_array'][0], 'type' => 'children');
                 } else {
                     $filter = null;
                 }
                 $children = $categlib->getCategories($filter, true, false);
                 $local = array();
                 foreach ($children as $child) {
                     $local[] = $child['categId'];
                 }
                 $cats = array_diff($cats, $local);
             }
         }
         if (!empty($except) && in_array($res['fieldId'], $except) || !empty($only) && !in_array($res['fieldId'], $only) || $res['type'] == 'q') {
             continue;
         }
         if (!empty($is_new) && in_array($res['type'], array('u', 'g', 'I')) && ($res['options_array'][0] == 1 || $res['options_array'][0] == 2)) {
             $res['value'] = $res['type'] == 'u' ? $user : ($res['type'] == 'g' ? $_SESSION['u_info']['group'] : TikiLib::get_ip_address());
         }
         if (in_array($res['type'], array('A', 'N'))) {
             // attachment - image
             continue;
             //not done yet
         }
         //echo "duplic".$res['fieldId'].' '. $res['value'].'<br>';
         if (!in_array($res['fieldId'], $clean)) {
             $this->itemFields()->delete(array('itemId' => $to, 'fieldId' => $res['fieldId']));
             $clean[] = $res['fieldId'];
         }
         $data = array('itemId' => $to, 'fieldId' => $res['fieldId'], 'value' => $res['value']);
         $this->itemFields()->insert($data);
     }
     if (!empty($cats)) {
         $trackerId = $this->items()->fetchOne('trackerId', array('itemId' => $from));
         $this->categorized_item($trackerId, $to, "item {$to}", $cats);
     }
     return $to;
 }
Exemplo n.º 8
0
 function testSeparatorOnEmptyData()
 {
     $options = Tracker_Options::fromString('a,,b', array('params' => array('a' => array('legacy_index' => 0), 'b' => array('legacy_index' => 1, 'separator' => '|'), 'c' => array('legacy_index' => 2))));
     $this->assertEquals(array(), $options->getParam('b'));
 }