Example #1
0
 public function action_index()
 {
     $this->template->page_title = 'Главная страница';
     //$this->template->block_center = array($block_center);
     $category = new Model_Category('tree');
     $categoryName = $this->request->param('category');
     $categoryId = $category->getCategoryIdByUrl('glavnaya');
     //ВИДЖЕТЫ ДЛЯ ГЛАВНОЙ СТРАНИЦЫ
     $widgets = $category->getWidgets($categoryId);
     $this->styles = array();
     $wdgtarr = array();
     //        if($this->template->block_center!=NULL)
     //            {
     //                $oldWidgets = $this->template->block_center;
     //                foreach ($oldWidgets as $oldWidget)
     //                    array_push($wdgtarr['block_center'], $oldWidget);
     //            }
     $widgets = $this->getWidgets($categoryId);
     if (is_array($widgets)) {
         foreach ($widgets as $position => $widget) {
             $this->template->{$position} = $widget;
         }
     }
     $old_styles = $this->template->styles;
     array_unique($this->styles);
     $new_styles = array_merge($this->styles, $old_styles);
     $this->template->styles = $new_styles;
 }
Example #2
0
 public function getWidgets($categoryId, $page = '')
 {
     $category = new Model_Category('tree');
     $widgets = $category->getWidgets($categoryId);
     $wdgtarr = array();
     $positions = $category->getWidgetPositions();
     foreach ($positions as $position) {
         if ($this->template->{$position}['position'] != NULL) {
             $oldWidgets = $this->template->{$position}['position'];
             foreach ($oldWidgets as $oldWidget) {
                 $wdgtarr[$position['position']][] = $oldWidget;
             }
         }
     }
     foreach ($widgets as $widget) {
         //Виджеты
         if ($widget['name'] == 'catalog' || $widget['name'] == 'catalog2') {
             $page1 = $page;
         } else {
             $page1 = '';
         }
         if (is_file('css/' . $widget['name'] . '.less')) {
             array_push($this->styles, 'css/' . $widget['name'] . '.less');
         }
         if (is_file('js/' . $widget['name'] . '.js')) {
             array_push($this->template->scripts, 'js/' . $widget['name'] . '.js');
         }
         $action = Arr::get($widget, 'action', 'index');
         $widget_url = 'widgets/' . $widget['name'] . '/' . $action . '/' . $widget['wid'] . $page1;
         $wdgt = Request::factory($widget_url)->execute();
         if (!isset($wdgtarr[$widget['position']])) {
             $wdgtarr[$widget['position']] = array($wdgt);
         } else {
             array_push($wdgtarr[$widget['position']], $wdgt);
         }
     }
     return $wdgtarr;
     //Вывод в шаблон
 }