예제 #1
0
 public function __construct($itemCount, $page = 1)
 {
     $itemsPerPage = Scaffold::Config('items_per_page');
     $this->itemsPerPage = $itemsPerPage !== null ? (int) max(1, $itemsPerPage) : 20;
     $this->itemCount = (int) max(0, $itemCount);
     $this->pageCount = ceil($this->itemCount / $this->itemsPerPage);
     $this->page = (int) min(max(1, $page), $this->pageCount);
     $this->previous = $this->page > 1 ? $this->page - 1 : false;
     $this->next = $this->page < $this->pageCount ? $this->page + 1 : false;
     $this->offset = ($this->page - 1) * $this->itemsPerPage;
 }
예제 #2
0
파일: db.php 프로젝트: eugeniy/scaffold
 public function Fields()
 {
     if ((empty($this->fields) or !$this->useCache) and self::$db !== null and $this->Table() !== null) {
         $table = $this->Escape($this->table);
         $output = array();
         $result = self::$db->query("SHOW COLUMNS FROM {$table}");
         if (!empty($result)) {
             foreach ($result as $col) {
                 $sortable = Scaffold::Config('tables', $this->table, 'fields', $col['Field'], 'sortable');
                 $label = Scaffold::Config('tables', $this->table, 'fields', $col['Field'], 'label');
                 $default = Scaffold::Config('tables', $this->table, 'fields', $col['Field'], 'default');
                 // Load the parent table
                 $parentTable = Scaffold::Config('tables', $this->table, 'fields', $col['Field'], 'parent');
                 if ($parentTable !== null and self::$depth > 0) {
                     self::$depth--;
                     $this->parents[$col['Field']] = new Scaffold_Db($parentTable);
                 }
                 $output[$col['Field']] = array('label' => $label === null ? $this->FormatLabel($col['Field']) : $label, 'type' => Scaffold::Config('tables', $this->table, 'fields', $col['Field'], 'type'), 'sortable' => $sortable === false ? false : true, 'sort' => "{$col['Field']} asc", 'default' => $default === null ? '' : $default, 'primary' => ($col['Key'] == 'PRI' and empty($this->primary) or $col['Field'] == $this->primary) ? true : false, 'parent' => $parentTable === null ? '' : $parentTable);
             }
             $this->fields = $output;
         }
     }
     return $this->fields;
 }