コード例 #1
0
ファイル: Controller.php プロジェクト: rjsmelo/tiki
 function action_edit_field($input)
 {
     $trackerId = $input->trackerId->int();
     $perms = Perms::get('tracker', $trackerId);
     if (!$perms->admin_trackers) {
         throw new Services_Exception_Denied(tr('Reserved for tracker administrators'));
     }
     $fieldId = $input->fieldId->int();
     $definition = Tracker_Definition::get($trackerId);
     if (!$definition) {
         throw new Services_Exception_NotFound();
     }
     $field = $definition->getField($fieldId);
     if (!$field) {
         throw new Services_Exception_NotFound();
     }
     $types = $this->utilities->getFieldTypes();
     $typeInfo = $types[$field['type']];
     $permName = $input->permName->word();
     if ($field['permName'] != $permName) {
         if ($definition->getFieldFromPermName($permName)) {
             throw new Services_Exception_DuplicateValue('permName', $permName);
         }
     }
     if ($input->name->text()) {
         $input->replaceFilters(array('visible_by' => 'groupname', 'editable_by' => 'groupname'));
         $visibleBy = $input->asArray('visible_by', ',');
         $editableBy = $input->asArray('editable_by', ',');
         global $prefs;
         if ($prefs['tracker_change_field_type'] === 'y') {
             $type = $input->type->text();
             if ($field['type'] !== $type) {
                 if (!isset($types[$type])) {
                     throw new Services_Exception(tr('Type does not exist'), 400);
                 }
                 $typeInfo = $types[$type];
                 // update typeInfo and clear out old options if changed type
                 $input->offsetSet('option', new JitFilter(array()));
             }
         } else {
             $type = $field['type'];
         }
         $this->utilities->updateField($trackerId, $fieldId, array('name' => $input->name->text(), 'description' => $input->description->text(), 'descriptionIsParsed' => $input->description_parse->int() ? 'y' : 'n', 'options' => $this->utilities->buildOptions($input->option, $typeInfo), 'validation' => $input->validation_type->word(), 'validationParam' => $input->validation_parameter->none(), 'validationMessage' => $input->validation_message->text(), 'isMultilingual' => $input->multilingual->int() ? 'y' : 'n', 'visibleBy' => array_filter(array_map('trim', $visibleBy)), 'editableBy' => array_filter(array_map('trim', $editableBy)), 'isHidden' => $input->visibility->alpha(), 'errorMsg' => $input->error_message->text(), 'permName' => $permName, 'type' => $type));
     }
     array_walk($typeInfo['params'], function (&$param) {
         if (isset($param['profile_reference'])) {
             $lib = TikiLib::lib('object');
             $param['selector_type'] = $lib->getSelectorType($param['profile_reference']);
             $param['parent'] = isset($param['parent']) ? "#option-{$param['parent']}" : null;
             $param['parentkey'] = isset($param['parentkey']) ? $param['parentkey'] : null;
         } else {
             $param['selector_type'] = null;
         }
     });
     return array('title' => tr('Edit %0', $field['name']), 'field' => $field, 'info' => $typeInfo, 'options' => $this->utilities->parseOptions($field['options'], $typeInfo), 'validation_types' => array('' => tr('None'), 'captcha' => tr('CAPTCHA'), 'distinct' => tr('Distinct'), 'pagename' => tr('Page Name'), 'password' => tr('Password'), 'regex' => tr('Regular Expression (Pattern)'), 'username' => tr('Username')), 'types' => $types);
 }