コード例 #1
0
ファイル: AdminCategories.php プロジェクト: swash13/shop
 protected static function actionDefault()
 {
     $categories = new Collection('Category', App::currentLang()->getId());
     $list = new TemplateList();
     $list->fields = array('id' => array('type' => 'id', 'title' => 'Номер'), 'name' => array('type' => 'text', 'title' => 'Название'), 'active' => array('type' => 'active', 'title' => 'Вкл/Выкл', 'action' => 'active', 'controller' => 'admin-categories'));
     $list->itemActions = array('edit' => array('hint' => 'Изменить', 'icon' => 'edit', 'controller' => 'admin-categories'), 'delete' => array('hint' => 'Удалить', 'icon' => 'delete', 'controller' => 'admin-categories'));
     $list->actions = array('new' => array('hint' => 'Добавить', 'icon' => 'add', 'controller' => 'admin-categories'));
     $list->items = $categories->items();
     $list->classes = 'center-list';
     self::templateVar('title', App::t('Категории'));
     self::templateVar('content', $list);
     return self::displayPage('admin');
 }
コード例 #2
0
ファイル: Index.php プロジェクト: swash13/shop
 protected static function actionDefault()
 {
     /*
      * Если выводиться вся страница то списко товаров передается шаблону products-list таким образом
      * Controller -> index -> products-list
      * Если запрос аяксовый то переменные передаются напрямую шаблону products-list
      * Controller -> products-list
      * Но при создании этих переменных мы не думаем о том какой шаблон будет выводиться.
      */
     // Заголовок списка товаров
     self::templateVar('product_list_title', 'Последние товары');
     // товары в списке (6 последних добавленных в соотвествии с фильтром цен)
     $collection = new Collection('Product', App::currentLang()->getId());
     $collection->link('cover');
     $collection->order("`add` DESC");
     $where = "`active` = 1";
     if (isset($_POST['submitPriceRange'])) {
         $where .= " AND `price` >= {$_POST['min']} AND `price` <= {$_POST['max']}";
     }
     $collection->where($where);
     $collection->limit(6);
     self::templateVar('product_list_items', $collection->items());
     if (App::isAjax()) {
         // Если это ajax выводим чанк списка товаров
         return self::displayPage('chunks/product-list');
     }
     // Привязка категорий для табов под списком товаров
     // Получаем две категории из базы
     $collection = new Collection('Category', App::currentLang()->getId());
     $collection->where("`active` = 1");
     $collection->limit(2);
     $categories = $collection->items();
     foreach ($categories as $category) {
         $collection = new Collection('Product', App::currentLang()->getId());
         $collection->where("`id_category` = " . $category->getId() . " AND `active` = 1");
         $collection->limit(4);
         $category->setLink('products', $collection->items());
     }
     foreach ($categories as $index => $category) {
         if (empty($category->products)) {
             unset($categories[$index]);
         }
     }
     // Привязываем к шаблону
     static::templateVar('tab_categories', $categories);
     return self::displayPage('index');
 }
コード例 #3
0
ファイル: Catalog.php プロジェクト: swash13/shop
 protected static function actionSearch()
 {
     // Заголовок над списком твоаров
     self::templateVar('product_list_title', 'Результаты поиска');
     // Товары
     $products = new Collection('Product', App::currentLang()->getId());
     $products->link('cover');
     $products->where("`active` = 1 AND `name` LIKE '%{$_GET['q']}%'" . (isset($_POST['submitPriceRange']) ? " AND `price` >= {$_POST['min']} AND `price` <= {$_POST['max']}" : ''));
     $products->order("`add` DESC");
     $products->limit(12);
     self::templateVar('product_list_items', $products->items());
     // Если это ajax выводим только чанк product-list
     if (App::isAjax()) {
         return self::displayPage('chunks/product-list');
     }
     return self::displayPage('catalog');
 }
コード例 #4
0
ファイル: AdminProducts.php プロジェクト: swash13/shop
 protected static function actionDefault()
 {
     // Получение списка товаров
     $products = new Collection('Product', 1);
     $products->link('category');
     $products->link('brand');
     $products->link('cover');
     $products->order('`add` DESC');
     $list = new TemplateList();
     $list->fields = array('id' => array('type' => 'id', 'title' => 'Номер'), 'cover->file' => array('type' => 'image', 'title' => 'Изображение', 'directory' => 'products', 'size' => '85x84'), 'name' => array('type' => 'text', 'title' => 'Название'), 'category->name' => array('type' => 'text', 'title' => 'Категория'), 'brand->name' => array('type' => 'text', 'title' => 'Производитель'), 'price' => array('type' => 'text', 'title' => 'Цена'), 'active' => array('type' => 'active', 'title' => 'Вкл/Выкл', 'action' => 'active', 'controller' => 'admin-products'));
     $list->itemActions = array('edit' => array('hint' => 'Изменить', 'icon' => 'edit', 'controller' => 'admin-products'), 'delete' => array('hint' => 'Удалить', 'icon' => 'delete', 'controller' => 'admin-products'));
     $list->actions = array('new' => array('hint' => 'Добавить', 'icon' => 'add', 'controller' => 'AdminProducts'));
     $list->items = Model::setModelsAutoload($products->items(), false, true);
     $list->classes = 'center-list';
     self::templateVar('title', App::t('Товары'));
     self::templateVar('content', $list);
     return self::displayPage('admin');
 }
コード例 #5
0
ファイル: ControllerAside.php プロジェクト: swash13/shop
 protected static function init()
 {
     parent::init();
     /*
      * Если текущий запрос не ajax
      * Происходит привязка глобальных данных для левого меню
      */
     if (!App::isAjax()) {
         // Привязка списка категорий
         $collection = new Collection('Category', App::currentLang()->getId());
         $collection->where("`active` = 1");
         static::templateGlobal('aside_categories', $collection->items());
         // Привязка списка производителей
         $collection = new Collection('Brand', App::currentLang()->getId());
         $collection->where("`active` = 1");
         static::templateGlobal('aside_brands', $collection->items());
         // Привязка данных для фильтра цен
         static::templateGlobal('filter_price', Database::getRow("\n                SELECT\n                    MIN(`price`) AS `min`,\n                    MAX(`price`) AS `max`\n                FROM `product`\n                WHERE `active` = 1\n            "));
     }
 }
コード例 #6
0
ファイル: document.php プロジェクト: Digt/trusted-php
 /**
  * Возвращает элемент коллекции по индексу
  * @param number $i Число [0..n]
  * @return DocumentItem Документ
  */
 function items($i)
 {
     return parent::items($i);
 }
コード例 #7
0
ファイル: Model.php プロジェクト: alexelev/bmf
 private function loadLink($link_name)
 {
     if (isset(static::$links[$link_name]) && $this->id) {
         $link = static::$links[$link_name];
         switch ($link['type']) {
             // Когда модель связана со списком объектов другой модели
             case LinkType::PRIMARY_KEY:
                 $collection = new Collection($link['model']);
                 if (isset($link['order'])) {
                     $collection->order($link['order']);
                 }
                 $where = "`{$link['field']}` = {$this->id}";
                 if (isset($link['where'])) {
                     $where .= " AND {$link['where']}";
                 }
                 $collection->where($where);
                 if (isset($link['limit'])) {
                     $collection->limit($link['limit']);
                 }
                 $models = $collection->items();
                 if (isset($link['limit']) && $link['limit'] == 1) {
                     if (!empty($models)) {
                         $this->models[$link_name] = $models[0];
                     } else {
                         $this->models[$link_name] = null;
                     }
                 } else {
                     $this->models[$link_name] = $models;
                 }
                 break;
                 // Когда модель связана с одним объектом другой модели
             // Когда модель связана с одним объектом другой модели
             case LinkType::FOREIGN_KEY:
                 $collection = new Collection($link['model']);
                 $where = "`id` = {$this->{$link['field']}}";
                 if (!empty($link['where'])) {
                     $where .= " AND {$link['where']}";
                 }
                 $collection->where($where);
                 $models = $collection->items();
                 if (!empty($models)) {
                     $this->models[$link_name] = $models[0];
                 } else {
                     $this->models[$link_name] = null;
                 }
                 break;
                 // Связь многие ко многим через промежуточную таблицу
             // Связь многие ко многим через промежуточную таблицу
             case LinkType::TABLE:
                 $ids = DB::getTable("SELECT `{$link['field2']}`\n                        FROM `{$link['table']}`\n                        WHERE `{$link['field1']}` = {$this->id}\n                    ");
                 foreach ($ids as $index => $row) {
                     $ids[$index] = $row[$link['field2']];
                 }
                 $collection = new Collection($link['model']);
                 if ($link['order']) {
                     $collection->order($link['order']);
                 }
                 $where = "`id` IN (" . implode(', ', $ids) . ")";
                 if ($link['where']) {
                     $where .= " AND {$link['where']}";
                 }
                 $collection->where($where);
                 if ($link['limit']) {
                     $collection->limit($link['limit']);
                 }
                 $models = $collection->items();
                 if ($link['limit'] == 1) {
                     if (!empty($models)) {
                         $this->models[$link_name] = $models[0];
                     } else {
                         $this->models[$link_name] = null;
                     }
                 } else {
                     $this->models[$link_name] = $models;
                 }
                 break;
         }
     }
 }