function action_add($input) { $trackerId = $input->trackerId->int(); $definition = Tracker_Definition::get($trackerId); if (!$definition) { throw new Services_Exception_NotFound(); } $delayAfter = abs($input->after->int() * $input->after_unit->int()); $delayNotif = abs($input->notif->int() * $input->notif_unit->int()); $from = $input->from->word(); $to = $input->to->word(); $event = $input->event->word(); $subject = $input->subject->text(); $body = $input->body->text(); $todolib = TikiLib::lib('todo'); if (!$delayAfter) { throw new Services_Exception_MissingValue('after'); } $todoId = $todolib->addTodo($delayAfter, $event, 'tracker', $trackerId, array('status' => $from), array('status' => $to)); if ($delayNotif) { $detail = array('mail' => 'creator', 'before' => $delayNotif); if ($subject) { $detail['subject'] = $subject; } if ($body) { $detail['body'] = $body; } $todolib->addTodo($delayAfter - $delayNotif, $event, 'todo', $todoId, "", $detail); } return array('trackerId' => $trackerId, 'todoId' => $todoId); }
function smarty_function_trackerfields($params, $smarty) { if (!isset($params['fields']) || !is_array($params['fields'])) { return tr('Invalid fields provided.'); } if (!isset($params['trackerId']) || !($definition = Tracker_Definition::get($params['trackerId']))) { return tr('Missing or invalid tracker reference.'); } $sectionFormat = $definition->getConfiguration('sectionFormat', 'flat'); switch ($sectionFormat) { case 'tab': $title = tr('General'); $sections = array(); foreach ($params['fields'] as $field) { if ($field['type'] == 'h') { $title = tr($field['name']); } else { $sections[$title][] = $field; } } $out = array(); foreach ($sections as $title => $fields) { $out[md5($title)] = array('heading' => $title, 'fields' => $fields); } $smarty->assign('sections', $out); return $smarty->fetch('trackerinput/layout_tab.tpl'); case 'flat': default: $smarty->assign('fields', $params['fields']); return $smarty->fetch('trackerinput/layout_flat.tpl'); } }
function wp_fixture_tracker_data($data, $params, $mock) { $table = new FixtureTable($data); $headings = $table->getHeadings(); $trackerId = $params->trackerId->int(); $tracker = Tracker_Definition::get($trackerId); if (!$tracker) { return '__' . tr('Tracker not found.') . '__'; } $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_sefurl'); $url = smarty_modifier_sefurl($trackerId, 'tracker'); $table->setTitle(tr('Tracker Data for [%0|%1]', $url, $tracker->getConfiguration('name'))); if (!in_array('itemId', $headings)) { return '__' . tr('Table must contain at least one field named itemId') . '__'; } foreach ($headings as $permName) { if ($permName != 'itemId' && !($field = $tracker->getFieldFromPermName($permName))) { return '__' . tr('Tracker Field not found: %0', $permName) . '__'; } } foreach ($table as $row) { $fields = array_combine($headings, $row); $itemId = $fields['itemId']; unset($fields['itemId']); $mock->addValues($itemId, $fields); } return $table; }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Importing tracker...'); $lib = \TikiLib::lib('tabular'); $info = $lib->getInfo($input->getArgument('tabularId')); $perms = \Perms::get('tabular', $info['tabularId']); if (!$info || !$perms->tabular_import) { throw new \Exception('Tracker Import: Tabular Format not found'); } $fileName = $input->getArgument('filename'); if (!file_exists($fileName)) { throw new \Exception('Tracker Import: File not found'); } // from \Services_Tracker_TabularController::getSchema TODO refactor? $tracker = \Tracker_Definition::get($info['trackerId']); if (!$tracker) { throw new \Exception('Tracker Import: Tracker not found'); } $schema = new \Tracker\Tabular\Schema($tracker); $schema->loadFormatDescriptor($info['format_descriptor']); $schema->loadFilterDescriptor($info['filter_descriptor']); $schema->validate(); if (!$schema->getPrimaryKey()) { throw new \Exception(tr('Primary Key required')); } // this will throw exceptions and not return if there's a problem $source = new \Tracker\Tabular\Source\CsvSource($schema, $fileName); $writer = new \Tracker\Tabular\Writer\TrackerWriter(); $writer->write($source); $output->writeln('Import done'); return 0; }
private function infobox_trackeritem($input) { $itemId = $input->object->int(); $trklib = TikiLib::lib('trk'); if (!($item = $trklib->get_tracker_item($itemId))) { throw new Services_Exception_NotFound(); } if (!($definition = Tracker_Definition::get($item['trackerId']))) { throw new Services_Exception_NotFound(); } $itemObject = Tracker_Item::fromInfo($item); if (!$itemObject->canView()) { throw new Services_Exception('Permission denied', 403); } $fields = array(); foreach ($definition->getPopupFields() as $fieldId) { if ($itemObject->canViewField($fieldId) && ($field = $definition->getField($fieldId))) { $fields[] = $field; } } $smarty = TikiLib::lib('smarty'); $smarty->assign('fields', $fields); $smarty->assign('item', $item); $smarty->assign('can_modify', $itemObject->canModify()); $smarty->assign('can_remove', $itemObject->canRemove()); $smarty->assign('mode', $input->mode->text() ? $input->mode->text() : ''); // default divs mode return $smarty->fetch('object/infobox/trackeritem.tpl'); }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('<info>Clearing tracker...</info>'); $trackerId = $input->getArgument('trackerId'); $tracker = \Tracker_Definition::get($trackerId); if (!$tracker) { throw new \Exception('Tracker Clear: Tracker not found'); } $perms = \Perms::get('tracker', $trackerId); if (!$perms->admin_trackers) { throw new \Exception('Tracker Clear: Admin permission required'); } $confirm = $input->getOption('confirm'); $utilities = new \Services_Tracker_Utilities(); if ($confirm) { $utilities->clearTracker($trackerId); $output->writeln('<info>Tracker clear done</info>'); } else { $name = $tracker->getConfiguration('name'); $output->writeln("<info>Use the --confirm option to proceed with the clear operation.</info>"); $output->writeln("<info> There is NO undo and no notifications will be sent.</info>"); $output->writeln("<info> All items in tracker #{$trackerId} \"{$name}\" will be deleted.</info>"); } return 0; }
function wikiplugin_trackercalendar($data, $params) { static $id = 0; $headerlib = TikiLib::lib('header'); $headerlib->add_cssfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.css'); $headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js'); $jit = new JitFilter($params); $definition = Tracker_Definition::get($jit->trackerId->int()); $itemObject = Tracker_Item::newItem($jit->trackerId->int()); if (!$definition) { return WikiParser_PluginOutput::userError(tr('Tracker not found.')); } $beginField = $definition->getFieldFromPermName($jit->begin->word()); $endField = $definition->getFieldFromPermName($jit->end->word()); if (!$beginField || !$endField) { return WikiParser_PluginOutput::userError(tr('Fields not found.')); } $views = array('month', 'agendaWeek', 'agendaDay'); $resources = array(); if ($resourceField = $jit->resource->word()) { $field = $definition->getFieldFromPermName($resourceField); $resources = wikiplugin_trackercalendar_get_resources($field); $views[] = 'resourceMonth'; $views[] = 'resourceWeek'; $views[] = 'resourceDay'; } $smarty = TikiLib::lib('smarty'); $smarty->assign('trackercalendar', array('id' => 'trackercalendar' . ++$id, 'trackerId' => $jit->trackerId->int(), 'begin' => $jit->begin->word(), 'end' => $jit->end->word(), 'resource' => $resourceField, 'resourceList' => $resources, 'coloring' => $jit->coloring->word(), 'beginFieldName' => 'ins_' . $beginField['fieldId'], 'endFieldName' => 'ins_' . $endField['fieldId'], 'firstDayofWeek' => 0, 'views' => implode(',', $views), 'viewyear' => (int) date('Y'), 'viewmonth' => (int) date('n'), 'viewday' => (int) date('j'), 'minHourOfDay' => 7, 'maxHourOfDay' => 20, 'addTitle' => tr('Insert'), 'canInsert' => $itemObject->canModify(), 'body' => $data)); return $smarty->fetch('wiki-plugins/trackercalendar.tpl'); }
function module_map_edit_features($mod_reference, $module_params) { $targetField = null; $smarty = TikiLib::lib('smarty'); $definition = Tracker_Definition::get($module_params['trackerId']); if ($definition) { foreach ($definition->getFields() as $field) { if ($field['type'] == 'GF') { $targetField = $field; break; } } } $hiddeninput = isset($module_params['hiddeninput']) ? $module_params['hiddeninput'] : ''; preg_match_all('/(\w+)\(([^\)]*)\)/', $hiddeninput, $parts, PREG_SET_ORDER); $hidden = array(); foreach ($parts as $p) { $hidden[$p[1]] = $p[2]; } $smarty->assign( 'edit_features', array( 'trackerId' => $module_params['trackerId'], 'definition' => $definition, 'field' => $targetField, 'hiddenInput' => $hidden, 'standardControls' => isset($module_params['standard']) ? intval($module_params['standard']) : 1, ) ); }
function getLanguage($type, $object) { $lang = null; switch ($type) { case 'wiki page': $info = TikiLib::lib('tiki')->get_page_info($object); $lang = $info['lang']; break; case 'article': $info = TikiLib::lib('art')->get_article($object); $lang = $info['lang']; break; case 'trackeritem': $info = TikiLib::lib('trk')->get_tracker_item($object); $definition = Tracker_Definition::get($info['trackerId']); if ($field = $definition->getLanguageField()) { $lang = $info[$field]; } break; case 'forum post': $object = TikiLib::lib('comments')->get_comment_forum_id($object); // no break: drop through to forum // no break: drop through to forum case 'forum': $info = TikiLib::lib('comments')->get_forum($object); $lang = $info['forumLanguage']; break; } if (!$lang) { throw new Services_Exception(tr('Object has no language and cannot be translated'), 400); } return $lang; }
public static function newItem($trackerId) { $obj = new self(); $obj->info = array(); $obj->definition = Tracker_Definition::get($trackerId); $obj->initialize(); return $obj; }
private function getAllIndexableHandlers() { $trackers = $this->db->table('tiki_trackers')->fetchColumn('trackerId', array()); $handlers = array(); foreach ($trackers as $trackerId) { $definition = Tracker_Definition::get($trackerId); $handlers = array_merge($handlers, $this->getIndexableHandlers($definition)); } return $handlers; }
function wikiplugin_addfreetag($data, $params) { global $user; $object = current_object(); if (isset($params['object']) && false !== strpos($params['object'], ':')) { list($object['type'], $object['object']) = explode(':', $params['object'], 2); } if ($object['type'] == 'wiki page' && !ctype_digit($object['object'])) { $identifier = 'wp_addfreetag_' . str_replace(array(':',' '), array('_',''), TikiLib::lib('tiki')->get_page_id_from_name($params['object'])); } else { $identifier = 'wp_addfreetag_' . str_replace(array(':',' '), array('_',''), $params['object']); } if ($object['type'] == 'trackeritem') { $permobject = TikiLib::lib('trk')->get_tracker_for_item($object['object']); $permobjecttype = 'tracker'; } else { $permobject = $object['object']; $permobjecttype = $object['type']; } if (! TikiLib::lib('tiki')->user_has_perm_on_object($user, $permobject, $permobjecttype, 'tiki_p_freetags_tag')) { return ''; } if (!empty($_POST[$identifier])) { $_POST[$identifier] = '"' . str_replace('"', '', $_POST[$identifier]) . '"'; TikiLib::lib('freetag')->tag_object($user, $object['object'], $object['type'], $_POST[$identifier]); if ($object['type'] == 'trackeritem') { // need to update tracker field as well $definition = Tracker_Definition::get($permobject); if ($field = $definition->getFreetagField()) { $currenttags = TikiLib::lib('freetag')->get_tags_on_object($object['object'], 'trackeritem'); $taglist = ''; foreach ($currenttags['data'] as $tag) { if (strstr($tag['tag'], ' ')) { $taglist .= '"'.$tag['tag'] . '" '; } else { $taglist .= $tag['tag'] . ' '; } } // taglist will have slashes TikiLib::lib('trk')->modify_field($object['object'], $field, stripslashes($taglist)); } } require_once 'lib/search/refresh-functions.php'; refresh_index($object['type'], $object['object']); $url = $_SERVER['REQUEST_URI']; header("Location: $url"); die; } $smarty = TikiLib::lib('smarty'); $smarty->assign('wp_addfreetag', $identifier); return $smarty->fetch('wiki-plugins/wikiplugin_addfreetag.tpl'); }
/** * @param $mod_reference * @param $module_params */ function module_tracker_input($mod_reference, $module_params) { global $prefs; $smarty = TikiLib::lib('smarty'); $trackerId = $module_params['trackerId']; $itemObject = Tracker_Item::newItem($trackerId); $definition = Tracker_Definition::get($trackerId); if (!$itemObject->canModify()) { $smarty->assign('tracker_input', array('trackerId' => 0, 'textInput' => array(), 'hiddenInput' => array(), 'location' => null)); return; } $textinput = isset($module_params['textinput']) ? $module_params['textinput'] : ''; $hiddeninput = isset($module_params['hiddeninput']) ? $module_params['hiddeninput'] : ''; $streetview = isset($module_params['streetview']) ? $module_params['streetview'] : ''; $streetViewField = $definition->getFieldFromPermName($streetview); $success = isset($module_params['success']) ? $module_params['success'] : ''; $insertmode = isset($module_params['insertmode']) ? $module_params['insertmode'] : ''; if (!$streetview || $prefs['fgal_upload_from_source'] != 'y' || !$streetViewField) { $streetview = ''; } $location = null; $locationMode = null; if (isset($module_params['location'])) { $parts = explode(':', $module_params['location'], 2); $location = array_shift($parts); $locationMode = array_shift($parts); if (!$locationMode) { $locationMode = 'marker'; } $hiddeninput .= " {$location}()"; } preg_match_all('/(\\w+)\\(([^\\)]+)\\)/', $textinput, $parts, PREG_SET_ORDER); $text = array(); foreach ($parts as $p) { $text[$p[1]] = tra($p[2]); } preg_match_all('/(\\w+)\\(([^\\)]*)\\)/', $hiddeninput, $parts, PREG_SET_ORDER); $hidden = array(); foreach ($parts as $p) { $hidden[$p[1]] = $p[2]; } $galleryId = null; if ($streetview) { $galleryId = TikiLib::lib('filegal')->check_user_file_gallery($streetViewField['options_array'][0]); } $operation = null; $operationArgument = null; if (preg_match("/(\\w+)\\(([^\\)]*)\\)/", $success, $parts)) { $operation = $parts[1]; $operationArgument = $parts[2]; } $smarty->assign('tracker_input', array('trackerId' => $trackerId, 'textInput' => $text, 'hiddenInput' => $hidden, 'location' => $location, 'locationMode' => $locationMode, 'streetview' => $streetview, 'galleryId' => $galleryId, 'submit' => isset($module_params['submit']) ? $module_params['submit'] : tr('Create'), 'success' => array('operation' => $operation, 'argument' => $operationArgument), 'insertMode' => $insertmode)); }
function execute(JitFilter $data) { $object_id = $data->object_id->int(); $field = $data->field->word(); $value = $data->value->text(); $trklib = TikiLib::lib('trk'); $info = $trklib->get_item_info($object_id); $definition = Tracker_Definition::get($info['trackerId']); $utilities = new Services_Tracker_Utilities(); $utilities->updateItem($definition, array('itemId' => $object_id, 'status' => $info['status'], 'fields' => array($field => $value))); return true; }
function action_list($input) { global $prefs; $unifiedsearchlib = TikiLib::lib('unifiedsearch'); $index = $unifiedsearchlib->getIndex(); $dataSource = $unifiedsearchlib->getDataSource(); $start = 'tracker_field_' . $input->beginField->word(); $end = 'tracker_field_' . $input->endField->word(); if ($resource = $input->resourceField->word()) { $resource = 'tracker_field_' . $resource; } if ($coloring = $input->coloringField->word()) { $coloring = 'tracker_field_' . $coloring; } $query = $unifiedsearchlib->buildQuery(array()); $query->filterRange($input->start->int(), $input->end->int(), array($start, $end)); $query->setRange(0, $prefs['unified_lucene_max_result']); if ($body = $input->filters->none()) { $builder = new Search_Query_WikiBuilder($query); $builder->apply(WikiParser_PluginMatcher::match($body)); } $result = $query->search($index); $result = $dataSource->getInformation($result, array('title', $start, $end)); $response = array(); $fields = array(); if ($definition = Tracker_Definition::get($input->trackerId->int())) { foreach ($definition->getPopupFields() as $fieldId) { if ($field = $definition->getField($fieldId)) { $fields[] = $field; } } } $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_sefurl'); $trklib = TikiLib::lib('trk'); foreach ($result as $row) { $item = Tracker_Item::fromId($row['object_id']); $description = ''; foreach ($fields as $field) { if ($item->canViewField($field['fieldId'])) { $val = trim($trklib->field_render_value(array('field' => $field, 'item' => $item->getData(), 'process' => 'y'))); if ($val) { if (count($fields) > 1) { $description .= "<h5>{$field['name']}</h5>"; } $description .= $val; } } } $response[] = array('id' => $row['object_id'], 'trackerId' => isset($row['tracker_id']) ? $row['tracker_id'] : null, 'title' => $row['title'], 'description' => $description, 'url' => smarty_modifier_sefurl($row['object_id'], $row['object_type']), 'allDay' => false, 'start' => $this->getTimestamp($row[$start]), 'end' => $this->getTimestamp($row[$end]), 'editable' => $item->canModify(), 'color' => $this->getColor(isset($row[$coloring]) ? $row[$coloring] : ''), 'textColor' => '#000', 'resource' => $resource && isset($row[$resource]) ? strtolower($row[$resource]) : ''); } return $response; }
public static function updateIcon($args) { $definition = Tracker_Definition::get($args['trackerId']); if ($fieldId = $definition->getIconField()) { $value = isset($args['values'][$fieldId]) ? $args['values'][$fieldId] : null; if (!empty($value)) { $tikilib = TikiLib::lib('tiki'); $value = $tikilib->tikiUrl($value); } $attributelib = TikiLib::lib('attribute'); $attributelib->set_attribute($args['type'], $args['object'], 'tiki.icon.src', $value); } }
public static function computeFields($args) { $trklib = TikiLib::lib('trk'); $definition = Tracker_Definition::get($args['trackerId']); foreach ($definition->getFields() as $field) { $fieldId = $field['fieldId']; if ($field['type'] == 'C') { $calc = preg_replace('/#([0-9]+)/', '$args[\'values\'][\\1]', $field['options_array'][0]); eval('$value = ' . $calc . ';'); $args['values'][$fieldId] = $value; $trklib->modify_field($args['itemId'], $fieldId, $value); } } }
public static function update_language($args) { $definition = Tracker_Definition::get($args['trackerId']); $fieldId = $definition->getLanguageField(); if ($fieldId) { $old = isset($args['old_values'][$fieldId]) ? $args['old_values'][$fieldId] : null; $new = isset($args['values'][$fieldId]) ? $args['values'][$fieldId] : null; if ($old != $new) { $multilinguallib = TikiLib::lib('multilingual'); $multilinguallib->updateObjectLang('trackeritem', $args['object'], $new); TikiLib::lib('trk')->sync_user_lang($args); } } }
public static function updateIcon($args) { $definition = Tracker_Definition::get($args['trackerId']); if ($fieldId = $definition->getIconField()) { $value = isset($args['values'][$fieldId]) ? $args['values'][$fieldId] : null; if (!empty($value) && isset($_SERVER['REQUEST_METHOD'])) { // leave URLs alone when run from a shell command $tikilib = TikiLib::lib('tiki'); $value = $tikilib->tikiUrl($value); } $attributelib = TikiLib::lib('attribute'); $attributelib->set_attribute($args['type'], $args['object'], 'tiki.icon.src', $value); } }
function getDocument($objectId, Search_Type_Factory_Interface $typeFactory) { $lib = TikiLib::lib('trk'); $field = $lib->get_tracker_field($objectId); if (!$field) { return false; } $trackername = tr('unknown'); if ($definition = Tracker_Definition::get($field['trackerId'])) { $trackername = $definition->getConfiguration('name'); } $data = array('title' => $typeFactory->sortable($field['name']), 'description' => $typeFactory->plaintext($field['description']), 'tracker_id' => $typeFactory->identifier($field['trackerId']), 'tracker_name' => $typeFactory->sortable($trackername), 'searchable' => $typeFactory->identifier('n'), 'view_permission' => $typeFactory->identifier('tiki_p_view_trackers')); return $data; }
public function renderInnerOutput($context = array()) { $definition = Tracker_Definition::get($this->getOption('trackerId')); $field = $definition->getField($this->getOption('listFieldIdThere')); if ($field['type'] == 'e' || $field['type'] == 'r') { $item = $this->getItemData(); $item['ins_' . $this->getOption('listFieldIdThere')] = array($this->getValue()); $field['value'] = $this->getValue(); $handler = TikiLib::lib('trk')->get_field_handler($field, $item); $field = array_merge($field, $handler->getFieldData($item)); // get category field to build it's data arrays $handler = TikiLib::lib('trk')->get_field_handler($field, $item); return $handler->renderOutput($context); } else { return parent::renderInnerOutput($context); } }
function render($name, $value, array $entry) { if ($name === 'tracker_status') { switch ($value) { case 'o': $status = 'open'; break; case 'p': $status = 'pending'; break; default: case 'c': $status = 'closed'; break; } $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_function_icon'); return smarty_function_icon(['name' => 'status-' . $status, 'iclass' => 'tips', 'ititle' => ':' . ucfirst($status)], $smarty); } elseif (substr($name, 0, 14) !== 'tracker_field_') { return $value; } $tracker = Tracker_Definition::get($entry['tracker_id']); if (!is_object($tracker)) { return $value; } $field = $tracker->getField(substr($name, 14)); // TextArea fields need the raw wiki syntax here for it to get wiki parsed if necessary if ($field['type'] === 'a' && isset($entry[$name . '_raw'])) { $value = $entry[$name . '_raw']; } $field['value'] = $value; $this->cancache = !in_array($field['type'], array('STARS', 's')); // don't cache ratings fields if ($this->editable) { // Caching breaks inline editing $this->cancache = false; } $item = array(); if ($entry['object_type'] == 'trackeritem') { $item['itemId'] = $entry['object_id']; } $trklib = TikiLib::lib('trk'); $rendered = $trklib->field_render_value(array('item' => $item, 'field' => $field, 'process' => 'y', 'search_render' => 'y', 'list_mode' => $this->list_mode, 'editable' => $this->editable, 'editgroup' => $this->group)); return '~np~' . $rendered . '~/np~'; }
protected function fetchValue($object, $field, $default) { $trklib = TikiLib::lib('trk'); $item = $trklib->get_tracker_item($object); if (!$item) { return $default; } if (!($definition = Tracker_Definition::get($item['trackerId']))) { return $default; } if (!($field = $definition->getFieldFromPermName($field))) { return $default; } $fieldId = $field['fieldId']; if (!isset($item[$fieldId])) { return $default; } return $item[$fieldId]; }
function render($name, $value, array $entry) { if (substr($name, 0, 14) !== 'tracker_field_') { return ""; } $tracker = Tracker_Definition::get($entry['tracker_id']); if (!is_object($tracker)) { return $value; } $field = $tracker->getField(substr($name, 14)); $field['value'] = $value; $item = array(); if ($entry['object_type'] == 'trackeritem') { $item['itemId'] = $entry['object_id']; } $trklib = TikiLib::lib('trk'); $rendered = $trklib->field_render_value(array('item' => $item, 'field' => $field, 'process' => 'y', 'search_render' => 'y', 'list_mode' => 'n', 'editable' => 'direct')); return '~np~<span class="fa fa-sort inline-sort-handle" data-current-value="' . smarty_modifier_escape($value) . '"></span><span class="hidden">' . $rendered . '</span>~/np~'; }
function render($name, $value, array $entry) { if (substr($name, 0, 14) !== 'tracker_field_') { return $value; } $tracker = Tracker_Definition::get($entry['tracker_id']); if (!is_object($tracker)) { return $value; } $field = $tracker->getField(substr($name, 14)); $field['value'] = $value; $this->cancache = !in_array($field['type'], array('STARS', 's')); // don't cache ratings fields $item = array(); if ($entry['object_type'] == 'trackeritem') { $item['itemId'] = $entry['object_id']; } $trklib = TikiLib::lib('trk'); return '~np~' . $trklib->field_render_value(array('item' => $item, 'field' => $field, 'process' => 'y', 'search_render' => 'y', 'list_mode' => $this->list_mode)) . '~/np~'; }
function evaluate($element) { $default = 0; $allowed = array('object', 'field'); if ($extra = $element->getExtraValues($allowed)) { $this->error(tr('Unexpected values: %0', implode(', ', $extra))); } $object = $element->object; if (!$object || count($object) != 2) { $this->error(tra('Item must be provided and contain one argument: type, object-id')); } $type = $this->evaluateChild($object[0]); $object = $this->evaluateChild($object[1]); $field = $element->field; if (!$field || count($field) != 1) { $this->error(tra('Field must be provided and contain one argument: field permanent name')); } $field = $field[0]; if ($type != 'trackeritem') { return $default; } $trklib = TikiLib::lib('trk'); $item = $trklib->get_tracker_item($object); if (!$item) { return $default; } if (!($definition = Tracker_Definition::get($item['trackerId']))) { return $default; } if (!($field = $definition->getFieldFromPermName($field))) { return $default; } $fieldId = $field['fieldId']; if (!isset($item[$fieldId])) { return $default; } return (double) $item[$fieldId]; }
function render($name, $value, array $entry) { if ($name === 'tracker_status') { switch ($value) { case 'o': $status = 'open'; break; case 'p': $status = 'pending'; break; default: case 'c': $status = 'closed'; break; } $alt = tr($status); return "<img src=\"img/icons/status_{$status}.gif\" alt=\"{$status}\"/>"; } elseif (substr($name, 0, 14) !== 'tracker_field_') { return $value; } $tracker = Tracker_Definition::get($entry['tracker_id']); if (!is_object($tracker)) { return $value; } $field = $tracker->getField(substr($name, 14)); $field['value'] = $value; $this->cancache = !in_array($field['type'], array('STARS', 's')); // don't cache ratings fields $item = array(); if ($entry['object_type'] == 'trackeritem') { $item['itemId'] = $entry['object_id']; } $trklib = TikiLib::lib('trk'); $rendered = $trklib->field_render_value(array('item' => $item, 'field' => $field, 'process' => 'y', 'search_render' => 'y', 'list_mode' => $this->list_mode, 'editable' => $this->editable)); return '~np~' . $rendered . '~/np~'; }
function wikiplugin_trackerfilter_build_trackerlist_filter($input, $formats, &$ffs, &$values, &$exactValues, Tracker_Definition $tracker_definition) { global $trklib; foreach ($input as $key =>$val) { if (substr($key, 0, 2) == 'f_' && !empty($val) && (!is_array($val) || !empty($val[0]))) { if (!is_array($val)) { $val = urldecode($val); } $fieldId = substr($key, 2); $field = $tracker_definition->getField($fieldId); if ($fieldId == 'status') continue; if (preg_match('/([0-9]+)(Month|Day|Year|Hour|Minute|Second)/', $fieldId, $matches)) { // a date if (!in_array($matches[1], $ffs)) { $fieldId = $matches[1]; $ffs[] = $matches[1]; // TO do optimize get options of the field $date = $trklib->build_date($_REQUEST, $trklib->get_tracker_field($fieldId), 'f_'.$fieldId); if (empty($formats[$fieldId])) { // = date $exactValues[] = $date; } else { // > or < data $exactValues[] = array($formats[$fieldId]=>$date); } } } else if ($field['type'] == 'F') { // if field type is freetag force the use of $values instead of $exactValues $ffs[] = $fieldId; if (is_array($val)) { $val = implode('%', $val); } $values[] = "%$val%"; } else { if (!is_numeric($fieldId)) { // composite filter $ffs[] = array('sqlsearch'=>explode(':', str_replace(array('(', ')'), '', $fieldId))); } else { $ffs[] = $fieldId; } if (isset($formats[$fieldId]) && ($formats[$fieldId] == 't' || $formats[$fieldId] == 'i')) { $exactValues[] = ''; $values[] = ($formats[$fieldId] == 'i')? "$val%": $val; } else { if (!empty($formats[$fieldId]) && preg_match('/[\>\<]+/', $formats[$fieldId]) ) { $exactValues[] = array($formats[$fieldId]=>$val); } else { $exactValues[] = $val; } $values[] = ''; } } } } }
public static function syncCategoryFields($args) { if ($args['type'] == 'trackeritem') { $itemId = $args['object']; $trackerId = TikiLib::lib('trk')->get_tracker_for_item($itemId); $definition = Tracker_Definition::get($trackerId); if ($fieldIds = $definition->getCategorizedFields()) { foreach ($fieldIds as $fieldId) { $field = $definition->getField($fieldId); $handler = TikiLib::lib('trk')->get_field_handler($field); $data = $handler->getFieldData(); $applicable = array_keys($data['list']); $value = $old_value = explode(",", TikiLib::lib('trk')->get_item_value($trackerId, $itemId, $fieldId)); foreach ($args['added'] as $added) { if (!in_array($added, $applicable)) { continue; } if (!in_array($added, $value)) { $value[] = $added; } } foreach ($args['removed'] as $removed) { if (!in_array($removed, $applicable)) { continue; } if (in_array($removed, $value)) { $value = array_diff($value, [$removed]); } } if ($value != $old_value) { $value = implode(",", $value); TikiLib::lib('trk')->modify_field($itemId, $fieldId, $value); } } } } }
/** * @param array $conditions e.g. array('trackerId' => 42) * @param int $maxRecords default -1 (all) * @param int $offset default -1 * @param array $fields array of fields to fetch (by permNames) * * @return mixed */ function getItems(array $conditions, $maxRecords = -1, $offset = -1, $fields = array()) { $keyMap = array(); $definition = Tracker_Definition::get($conditions['trackerId']); foreach ($definition->getFields() as $field) { if (!empty($field['permName']) && (empty($fields) || in_array($field['permName'], $fields))) { $keyMap[$field['fieldId']] = $field['permName']; } } $table = TikiDb::get()->table('tiki_tracker_items'); if (!empty($conditions['status'])) { $conditions['status'] = $table->in(str_split($conditions['status'], 1)); } else { unset($conditions['status']); } if (!empty($conditions['modifiedSince'])) { $conditions['lastModif'] = $table->greaterThan($conditions['modifiedSince']); } if (!empty($conditions['itemId'])) { $conditions['itemId'] = $table->in((array) $conditions['itemId']); } unset($conditions['modifiedSince']); $items = $table->fetchAll(array('itemId', 'status'), $conditions, $maxRecords, $offset); foreach ($items as &$item) { $item['fields'] = $this->getItemFields($item['itemId'], $keyMap); } return $items; }