Since: 3.0.0
Author: Jack P.
Inheritance: extends Traq\Models\Model
Example #1
0
 /**
  * Returns an array of custom field ticket filters for the specified project.
  *
  * @param Project $project
  *
  * @return array
  */
 public static function customFieldFiltersFor(Project $project)
 {
     static $filters = [];
     if (count($filters)) {
         return $filters;
     }
     foreach (CustomField::forProject($project->id) as $field) {
         $filters[$field->slug] = $field->name;
     }
     return $filters;
 }
Example #2
0
 /**
  * Set ticket filters.
  */
 public function setFiltersAction()
 {
     $queryString = [];
     $filters = Request::$post->get('filters', [], false);
     // Add filter
     if ($newFilter = Request::$post->get('new_filter') and $newFilter !== '') {
         if (!isset($filters[$newFilter])) {
             $filters[$newFilter] = ['prefix' => '', 'values' => []];
         } else {
             $filters[$newFilter]['values'][] = '';
         }
     }
     foreach ($filters as $name => $filter) {
         $filter['prefix'] = $filter['prefix'] == '-' ? '!' : '';
         // Is this a filter?
         if (!in_array($name, array_keys(TicketFilters::filtersFor($this->currentProject)))) {
             continue;
         }
         if (!isset($filter['values'])) {
             $filter['values'] = [];
         }
         if ($field = CustomField::find('slug', $name)) {
             $queryString[$name] = $filter['prefix'] . implode(',', $filter['values']);
         } else {
             $queryString[$name] = $filter['prefix'] . implode(',', $filter['values']);
         }
     }
     return $this->redirect($this->generateUrl('tickets', ['pslug' => $this->currentProject['slug']]) . '?' . Request::buildQueryString($queryString, false));
 }
Example #3
0
 /**
  * Delete field.
  */
 public function action_delete($id)
 {
     // Find field
     $field = CustomField::find($id);
     // Verify project
     if ($field->project_id != $this->project->id) {
         return $this->show_no_permission();
     }
     // Delete and redirect
     $field->delete();
     if ($this->is_api) {
         return \API::response(1);
     } else {
         Request::redirectTo($this->project->href('settings/custom_fields'));
     }
 }
Example #4
0
 /**
  * Delete field.
  */
 public function destroyAction($id)
 {
     $field = CustomField::select()->where('id = ?')->andWhere('project_id = ?')->setParameter(0, $id)->setParameter(1, $this->currentProject['id'])->fetch();
     $field->delete();
     return $this->respondTo(function ($format) use($field) {
         if ($format == "html") {
             return $this->redirectTo('project_settings_custom_fields');
         } elseif ($format == "json") {
             return $this->jsonResponse(['deleted' => true, 'field' => $field->toArray()]);
         }
     });
 }
Example #5
0
 /**
  * Returns the content for the ticket listing headers.
  *
  * @param string $column The column to get the content for.
  *
  * @return mixed
  */
 public static function headerFor($column)
 {
     switch ($column) {
         case 'ticket_id':
             return Language::translate('id');
             break;
         case 'summary':
         case 'status':
         case 'owner':
         case 'type':
         case 'component':
         case 'milestone':
         case 'version':
         case 'assigned_to':
         case 'updates':
         case 'votes':
         case 'priority':
         case 'severity':
             return Language::translate($column);
         case 'created_at':
             return Language::translate('created');
             break;
         case 'updated_at':
             return Language::translate('updated');
             break;
     }
     // If we're still here, it may be a custom field
     if ($column = CustomField::find($column)) {
         return $column->name;
     }
     // Nothing!
     return '';
 }
Example #6
0
function createCustomField($project = null)
{
    if (!$project) {
        $project = createProject();
    }
    $hash = mkRandomHash(5);
    $customField = new CustomField(['name' => $hash . '-name', 'slug' => $hash . '-slug', 'type' => 1, 'ticket_type_ids' => 0, 'project_id' => $project['id']]);
    $customField->save();
    return $customField;
}