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); }
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; }