Esempio n. 1
0
 public function response()
 {
     $user_order = @$_GET['order'];
     $user_direction = @$_GET['direction'];
     $user_limit = @$_GET['limit'];
     $user_start = @$_GET['start'];
     $direction = $user_direction == 'desc' ? 'desc' : 'asc';
     $order = reset($this->table->columns)->name;
     foreach ($this->table->columns as $column) {
         if ($column->name == $user_order) {
             $order = $column->name;
         }
     }
     $limit = min(max(intval($user_limit), 20), 500);
     $start = max(intval($user_start), 0);
     return parent::response(['rows' => $this->da->select($this->table, "1 ORDER BY {$order} {$direction} LIMIT {$start}, {$limit}"), 'order' => $order, 'direction' => $direction, 'limit' => $limit, 'start' => $start]);
 }
Esempio n. 2
0
 public function response()
 {
     $template_params['links'] = [];
     foreach ($this->table->links as $link) {
         if ($link instanceof \Carbo\Extensions\Admin\LinkInformation) {
             $template_params['links'][] = ['all' => $this->da->select($link->remoteTable), 'info' => $link];
         } elseif ($link instanceof \Carbo\Extensions\Admin\OneToManyLinkInformation) {
             $template_params['links'][] = ['all' => $this->da->select($link->remoteTable), 'info' => $link];
         }
     }
     foreach ($this->table->columns as $column) {
         if ($column->isForeign) {
             $foreign_table = $this->da->schema->tables[$column->foreignTable];
             $template_params['row'][$column->name] = ['all' => $this->da->select($foreign_table), 'info' => new \Carbo\Extensions\Admin\OneToManyLinkInformation($foreign_table, $this->table, $column)];
         }
     }
     return parent::response($template_params);
 }
Esempio n. 3
0
 public function response($template_params = [])
 {
     $template_params['row'] = $this->da->selectOne($this->table, "{$this->key} = ?", [$this->value]);
     if (!$template_params['row']) {
         throw new \Carbo\Http\CodeException(\Carbo\Http\Code::NotFound);
     }
     $template_params['links'] = [];
     foreach ($this->table->links as $link) {
         if ($link instanceof \Carbo\Extensions\Admin\LinkInformation) {
             $template_params['links'][] = ['all' => $this->da->select($link->remoteTable), 'selected' => $this->da->getLinks($link, $this->value), 'info' => $link];
         } elseif ($link instanceof \Carbo\Extensions\Admin\OneToManyLinkInformation) {
             $template_params['links'][] = ['all' => $this->da->select($link->remoteTable), 'selected' => $this->da->select($link->remoteTable, "{$link->remoteColumn->name} = ?", [$this->value], true), 'info' => $link];
         }
     }
     foreach ($this->table->columns as $column) {
         if ($column->isForeign) {
             $foreign_table = $this->da->schema->tables[$column->foreignTable];
             $template_params['row'][$column->name] = ['all' => $this->da->select($foreign_table), 'selected' => [$template_params['row'][$column->name]], 'info' => new \Carbo\Extensions\Admin\OneToManyLinkInformation($foreign_table, $this->table, $column)];
         }
     }
     return parent::response($template_params);
 }