function createComponent($project = null) { if (!$project) { $project = createProject(); } $component = new Component(['name' => 'component-' . mkRandomHash(5) . '-name', 'project_id' => $project['id']]); $component->save(); return $component; }
/** * Returns options for the specific ticket filter. * * @param string $filter * * @return array */ public static function selectOptionsFor($filter, Project $project) { switch ($filter) { // Milestone options case 'milestone': $options = $project->milestoneSelectOptions('slug'); break; // Version options // Version options case 'version': $options = $project->milestoneSelectOptions('slug'); break; // Type options // Type options case 'type': $options = Type::selectOptions('name'); break; // Status options // Status options case 'status': $options = Status::selectOptions('name'); break; // Component options // Component options case 'component': $options = Component::selectOptions($project->id, 'name'); break; // Priority options // Priority options case 'priority': $options = Priority::selectOptions('name'); break; // Severity options // Severity options case 'severity': $options = Severity::selectOptions('name'); break; } return $options; }
/** * Override to only get the relevant projects milestones. * * @return array */ protected function getAllRows() { return Component::select('id', 'name')->where('project_id = ?')->orderBy('name', 'ASC')->setParameter(0, $this->currentProject['id'])->execute()->fetchAll(); }
<?php /*! * Traq Lite * Copyright (c) 2009-2016 Jack P. * https://github.com/nirix/traq-lite * * Licensed under the BSD 3-Clause license. */ use Traq\Models\Component; $component = new Component(); if (Request::$method == 'POST') { $component->set(['name' => Request::$post['name'], 'project_id' => Request::$post['project_id']]); if ($component->validate()) { db()->beginTransaction(); $query = db()->prepare('INSERT INTO ' . PREFIX . 'components (name, project_id) VALUES(:name, :project_id)'); $query->bindValue(':name', $component['name']); $query->bindValue(':project_id', $component['project_id'], PDO::PARAM_INT); $query->execute(); db()->commit(); return redirect('/admin/components'); } } return view('admin/components/new.phtml', ['component' => $component]);
/** * @return array[] */ public function componentSelectOptions() { $options = []; $components = Component::where('project_id = ?')->setParameter(0, $this->id)->orderBy('name', 'ASC'); foreach ($components->execute()->fetchAll() as $component) { $options[] = ['label' => $component['name'], 'value' => $component['id']]; } return $options; }
<?php /*! * Traq Lite * Copyright (c) 2009-2016 Jack P. * https://github.com/nirix/traq-lite * * Licensed under the BSD 3-Clause license. */ use Traq\Models\Component; $query = db()->prepare('SELECT * FROM ' . PREFIX . 'components WHERE id = ? LIMIT 1'); $query->bindValue(1, Request::$properties['id']); $query->execute(); $component = $query->fetch(); if (!$component) { return show404(); } $component = new Component($component); if (Request::$method == 'POST') { $component->set(['name' => Request::$post['name'], 'slug' => Request::$post['slug'], 'description' => Request::$post['description'], 'display_order' => Request::$post['display_order']]); if ($component->validate()) { db()->beginTransaction(); $query = db()->prepare('UPDATE ' . PREFIX . 'components SET name = :name WHERE id = :id LIMIT 1'); $query->bindValue(':id', $component['id'], PDO::PARAM_INT); $query->bindValue(':name', $component['name']); $query->execute(); db()->commit(); return redirect('/admin/components'); } } return view('admin/components/edit.phtml', ['component' => $component]);