Example #1
0
 protected function moduleList3($data)
 {
     $pages = $data['pages'];
     $mpage_id = ModulesInPages::model()->getLink($data['doc_id_last'], 'list3');
     $records_on_page = 0;
     // количество публикаций на странице
     $type = explode($pages->make_url($data['doc_id_last']), '/' . Yii::app()->request->pathInfo);
     $type = explode('/', $type[1]);
     $type = $type[0];
     if (substr($type, 0, 5) == 'show_') {
         // конкретная публикация
         $lenta = new ModuleList3();
         $item_id = floor(substr($type, 5));
         if ($lenta->existsItem($mpage_id, $item_id, 1)) {
             $data['item_id'] = $item_id;
             $data['item'] = $lenta->getItem($item_id, $mpage_id);
             $data['longtitle'] = $data['item']['title'];
             switch ($data['doc_id_last']) {
                 case 37:
                     $data['longtitle'] = 'Вклад ' . $data['item']['title'];
                     break;
                     /*case :
                       $data['longtitle'] = ''.$data['item']['title'];
                       break;*/
             }
             //$data['other_lenta'] = $lenta->getOtherList($mpage_id, $item_id,4,1);
             if (count($data['item']) == 0) {
                 $this->redirect($pages->make_url($data['doc_id_last']));
             } else {
                 $data['title'] = $data['item']['title'] . ' — ' . $data['title'];
                 if ($data['doc_id_last'] == 37) {
                     $data['list3'] = ModuleList3::model()->getList($mpage_id);
                     $ids = [];
                     foreach ($data['list3'] as $value) {
                         $ids[] = $value->id;
                     }
                     $count = count($ids);
                     $i = 0;
                     while ($ids[$i] != $item_id) {
                         $i++;
                     }
                     if ($i == 0) {
                         $data['prev'] = false;
                         $data['next'] = $count > 1 ? $lenta->getItem($ids[1], $mpage_id) : false;
                     } else {
                         if ($i == $count - 1) {
                             $data['prev'] = $count > 1 ? $lenta->getItem($ids[$i - 1], $mpage_id) : false;
                             $data['next'] = false;
                         } else {
                             $data['prev'] = $lenta->getItem($ids[$i - 1], $mpage_id);
                             $data['next'] = $lenta->getItem($ids[$i + 1], $mpage_id);
                         }
                     }
                     $list3files = ModuleList3Files::model()->findAllByAttributes(['item_id' => $item_id]);
                     if (count($list3files) > 0) {
                         foreach ($list3files as $file) {
                             $data['files'][$file->id]['short'] = $file->short;
                             $data['files'][$file->id]['ref'] = Files::model()->getVirtualPath('list3', $file->file_id);
                         }
                     }
                     $this->render('deposit_show', $data);
                 } else {
                     $this->render('list3_show', $data);
                 }
             }
         } else {
             // публикация не найдена
             $this->redirect($pages->make_url($data['doc_id_last']));
         }
     } elseif (substr($type, 0, 5) == 'page_' || empty($type)) {
         // выбор страницы
         $page = 1;
         $lenta = new ModuleList3();
         if (!empty($type)) {
             $page = floor(substr($type, 5));
         }
         if ($page < 1) {
             $page = 1;
         }
         if ($records_on_page > 0) {
             $data['pagination'] = $this->pagination($pages->make_url($data['doc_id_last']) . 'page_', $lenta->getCount($mpage_id, 1), $page, $records_on_page);
         }
         $offset = ($page - 1) * $records_on_page;
         $limit = $records_on_page;
         $data['list3'] = ModuleList3::model()->getList($mpage_id, $offset, $limit, 1);
         $data['url_for_menu'] = substr(substr($data['pages']->make_url($data['doc_id_last']), 0, -1), 1);
         if ($data['doc_id_last'] == 37) {
             $this->render('deposit', $data);
         } else {
             $this->render('list3', $data);
         }
     } else {
         // неизвестный тип отображения ПУБЛИКАЦИЙ
         $this->redirect($pages->make_url($data['doc_id_last']));
     }
 }