Пример #1
0
 /**
  * Update ticket.
  *
  * @param integer $id
  */
 public function updateAction($id)
 {
     if (Request::method() != 'post') {
         Request::redirectTo('/');
     }
     // Get the ticket
     $ticket = Ticket::find($id);
     // Ticket changes
     $changes = [];
     foreach (['department', 'status', 'priority'] as $property) {
         if ($ticket->{$property . '_id'} != Request::$post[$property]) {
             $change = ['property' => $property];
             switch ($property) {
                 case 'department':
                 case 'status':
                     $class = "\\Ticketer\\Models\\" . Inflector::classify($property);
                     $change['from'] = $class::find($ticket->{"{$property}_id"})->name;
                     $change['to'] = $class::find(Request::$post[$property])->name;
                     break;
                 case 'priority':
                     $change['from'] = getPriorityName($ticket->priority_id);
                     $change['to'] = getPriorityName(Request::$post['priority']);
                     break;
             }
             $changes[] = $change;
         }
     }
     // Update ticket properties
     $ticket->set(['department_id' => Request::$post['department'], 'status_id' => Request::$post['status'], 'priority_id' => Request::$post['priority']]);
     // Ticket reply
     $reply = new TicketReply(['message' => Request::$post['message'], 'user_id' => $this->currentUser->id, 'ticket_id' => $ticket->id, 'changes' => json_encode($changes)]);
     if (count($changes) or Request::$post['message'] != '') {
         if ($reply->save() and $ticket->save()) {
             Request::redirectTo($ticket->href());
         }
     } else {
         Request::redirectTo($ticket->href());
     }
     $this->set(compact('ticket', 'reply'));
     $this->render['view'] = 'tickets/view';
 }
Пример #2
0
 /**
  * Returns an array of owned objects.
  *
  * @param string $model   Name of the model.
  * @param aray   $options Optional relation options.
  *
  * @return array
  */
 public function hasMany($model, $options = array())
 {
     $options = static::getRelationInfo($model, $options);
     if (!isset($options['localKey'])) {
         $options['localKey'] = static::primaryKey();
     }
     if (!isset($options['foreignKey'])) {
         $options['foreignKey'] = Inflector::foreignKey(static::table());
     }
     return $options['model']::select()->where("{$options['foreignKey']} = ?", $this->{$options['localKey']})->mergeNextWhere();
 }
Пример #3
0
 /**
  * Shortcut for setting up the routes for a resource.
  *
  * @param string $resource   Resource/model name.
  * @param string $controller Controller to use for the resource.
  */
 public static function resources($resource, $controller)
 {
     $uri = strtolower(Inflector::controllerise($resource));
     // Index, show
     static::get("/{$uri}")->to("{$controller}::index");
     static::get("/{$uri}/:id")->to("{$controller}::show");
     // New
     static::get("/{$uri}/new")->to("{$controller}::new");
     static::post("/{$uri}/new")->to("{$controller}::create");
     // Edit
     static::get("/{$uri}/:id/edit")->to("{$controller}::edit");
     static::post("/{$uri}/:id/edit")->to("{$controller}::save");
     // Delete
     static::get("/{$uri}/:id/delete")->to("{$controller}::delete");
     static::post("/{$uri}/:id/delete")->to("{$controller}::destroy");
 }
Пример #4
0
 /**
  * Returns the models table.
  *
  * @return string
  */
 protected static function table()
 {
     $class = new \ReflectionClass(get_called_class());
     return static::$_table !== null ? static::$_table : Inflector::tablise($class->getShortName());
 }