Example #1
0
 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');
 }
Example #2
0
 protected static function actionDefault()
 {
     $products = new Collection('Product', App::currentLang()->getId());
     $products->link('cover');
     $products->where("`id` IN (" . implode(',', array_keys($_SESSION['cart'])) . ")");
     $products = $products->items();
     foreach ($products as $product) {
         $product->quantity = $_SESSION['cart'][$product->getId()];
     }
     self::templateVar('cart_items', $products);
     return self::displayPage('cart');
 }
Example #3
0
 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');
 }
Example #4
0
 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');
 }
Example #5
0
foreach ($books as $book) {
    $info = $book->attribs();
    dbm_debug('info', "written about {$info['title']} by {$info['author']}.");
}
dbm_debug('heading', 'Beginning testing for relational linking.');
$collection = new Collection(1);
$mhi = new Book(1);
$aotr = new Book(2);
$tram = new Book(3);
dbm_debug('info', 'Loaded a collection and three books:');
$collection->dumpview(true);
$mhi->dumpview(true);
$aotr->dumpview(true);
$tram->dumpview(true);
dbm_debug('info', 'Creating a relational link "Sci-Fi" from collection 1 to book 1');
$collection->link($mhi, "Sci-Fi");
dbm_debug('info', 'Creating a relational link "guns" from collection 1 to book 1');
$collection->link($mhi, "guns");
dbm_debug('info', 'Creating a relational link "guns" from collection 1 to book 2');
$collection->link($aotr, "guns");
dbm_debug('info', 'Creating a blank link from collection 1 to book 3');
$collection->link($tram);
dbm_debug('info', 'Attempting to find all books labeled "Sci-Fi" (should just be Monster Hunter International)');
$books = $collection->getLinks('Book', 'Sci-Fi');
foreach ($books as $book) {
    $book->dumpview(true);
}
dbm_debug('info', 'Attempting to find all books labeled "guns" (should just be Monster Hunter International and Art of the Rifle)');
$books = $collection->getLinks('Book', 'guns');
foreach ($books as $book) {
    $book->dumpview(true);