PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/publications/classes/controller/frontend/publications.php

https://bitbucket.org/seyar/ari100krat.local
PHP | 259 lines | 188 code | 60 blank | 11 comment | 40 complexity | 0fa30a11325aaa6cf1a0d4f876a83e95 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2. class Controller_Frontend_Publications extends Controller_Content
  3. {
  4. public $template = 'publication_list.tpl';
  5. static public $newIDs = array();
  6. const images_folder = 'publications';
  7. const root_url = 'publications';
  8. public $top_count = 5;
  9. public function before()
  10. {
  11. parent::before();
  12. $this->model->images_folder = MEDIAPATH . $this->images_folder . '/';
  13. // Kohana_I18n::lang(LANGUAGE_ROUTE_DEFAULT);
  14. self::$newIDs = Kohana::config('publications')->newIDs;
  15. $this->view->assign('newIDs', self::$newIDs);
  16. $this->view->assign('root_folder', Controller_Frontend_Publications::root_url);
  17. $this->view->assign('images_folder', MEDIAWEBPATH . Controller_Frontend_Publications::images_folder . "/");
  18. $this->view->assign('module_id', Model_AdminModulesControl::find('publications'));
  19. $this->view->assign('publRootUrl', Kohana::config('publications')->pubRootUrl );
  20. $this->view->assign('rating_values', Kohana::config('publications')->rating_values );
  21. }
  22. public function action_index()
  23. {
  24. $publ_types = Model_Frontend_Publications::publication_types(CURRENT_LANG_ID);
  25. $where = array('publications.status' => array( 'op'=> '=', 'value'=> 1 ) );
  26. if (!$this->request->param('type_uri'))
  27. {
  28. // show all types top messages
  29. $list = Model_Frontend_Publications::publication_top(CURRENT_LANG_ID);
  30. }
  31. else
  32. {
  33. /* filters */
  34. if( $this->request->param('filter') && $this->request->param('filter') == 'to_date' ) $where['pub_date'] = array( 'op'=> '<', 'value'=> $this->request->param('value') );
  35. if( $this->request->param('filter') && $this->request->param('filter') == 'from_date' ) $where['pub_date'] = array( 'op'=> '>', 'value'=> $this->request->param('value') );
  36. if( $this->request->param('filter') && $this->request->param('filter') == 'exact_date' ) $where['pub_date'] = array( 'op'=> '=', 'value'=> DB::expr( 'TO_DAYS(\''. $this->request->param('value') .'\')') );
  37. if( $this->request->param('filter') && $this->request->param('filter') == 'main_new' ) $where['main_new'] = array( 'op'=> '=', 'value'=> 1 );
  38. /* end filters */
  39. foreach ($publ_types as $value)
  40. {
  41. $url = str_replace('//', '/', '/' . $value['parent_url'] . $value['url']);
  42. if ($url == '/' . $this->request->param('type_uri'))
  43. {
  44. // show current publ_type list
  45. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID, $value['id'], NULL, $where);
  46. $publ_typeId = $value['id'];
  47. $this->view->assign('publ_id', $publ_typeId);
  48. }
  49. }
  50. $publ_type = Model_Publications::publ_types_load($publ_typeId);
  51. // TODO need delete
  52. if( $publ_type['id'] = Kohana::config('publications.webconfID') )
  53. {
  54. if($where['pub_date']['op'] == '>')
  55. $publ_type['pubtype_title'] = Kohana::config('publications.titles.pred').' '.$publ_type['name'];
  56. elseif($where['pub_date']['op'] == '<')
  57. $publ_type['pubtype_title'] = Kohana::config('publications.titles.sost').' '.$publ_type['name'];
  58. }
  59. $this->view->assign('publ_type', $publ_type );
  60. $this->template = $publ_type['template'].'_list.tpl';
  61. }
  62. if($this->request->param('value'))
  63. $this->view->assign('filter', $this->request->param('value'));
  64. $page_title = isset($publ_type['pubtype_title']) ? $publ_type['pubtype_title'] : Kohana::config('publications.titles.main');
  65. $this->page_info = array('page_title' => $page_title );
  66. $this->view->assign('rows', $list[0]);
  67. $this->view->assign('page_line', $list[1]);
  68. $this->view->assign('total_pages', $list[2]);
  69. }
  70. public function action_comment()
  71. {
  72. die();
  73. $publ_types = Model_Frontend_Publications::publication_types(CURRENT_LANG_ID);
  74. if (!$this->request->param('type_uri'))
  75. echo Kohana::debug($publ_types);
  76. else
  77. {
  78. foreach ($publ_types as $value)
  79. {
  80. $url = str_replace('//', '/', '/' . $value['parent_url'] . $value['url']);
  81. echo Kohana::debug("$url=/" . $this->request->param('type_uri'));
  82. if ($url == '/' . $this->request->param('type_uri'))
  83. {
  84. echo Kohana::debug($value);
  85. }
  86. }
  87. }
  88. echo Kohana::debug($this->request);
  89. die();
  90. }
  91. public function action_view()
  92. {
  93. $url = '/'.$this->request->param('type_uri').'/'. $this->request->param('id');
  94. $obj = Model_Publications::publ_load_by_url($url, CURRENT_LANG_ID);
  95. /* ratings */
  96. $rating = Model_Frontend_Ratings::getItem($obj['id']);
  97. $obj['rating'] = $rating['rating'];
  98. /* ratings */
  99. $publ_type = Model_Publications::publ_types_load($obj['publicationstypes_id']);
  100. $this->view->assign('publ_type', $publ_type );
  101. $this->template = $publ_type['template'].'.tpl';
  102. if ($obj['id'])
  103. $obj['images'] = Model_Publications::publ_images_show(
  104. Controller_Frontend_Publications::images_folder . "/",
  105. $path = '',
  106. MEDIAWEBPATH . Controller_Frontend_Publications::images_folder . "/{$obj['id']}",
  107. $obj['id']
  108. );
  109. $this->page_info = array('page_title' => $obj['pub_title'], 'page_keywords' => $obj['pub_keywords'],
  110. 'page_keywords' => $obj['pub_description'],);
  111. $obj['user'] = Model_Registration::get_items($obj['add_fields']['user_id']['value_int']);
  112. $this->view->assign('obj', $obj);
  113. $obj_datetime = strtotime($obj['pub_date']);
  114. $this->view->assign('obj_date', $obj_datetime);
  115. $this->view->assign('month_names', I18n::get(strtolower(date('M', $obj_datetime))));
  116. $this->view->assign('publ_id', $this->request->param('id'));
  117. }
  118. public function action_widget()
  119. {
  120. $pubtypeId = $this->request->param('type_uri');
  121. if( strstr($pubtypeId, '_') )
  122. {
  123. $pubtypeId = explode('_',$this->request->param('type_uri'));
  124. $this->template = 'publication_'.$this->request->param('type_tpl').'_widget.tpl';
  125. }
  126. else
  127. {
  128. $publ_type = Model_Publications::publ_types_load($pubtypeId);
  129. $this->view->assign('publ_type', $publ_type );
  130. $this->template = $publ_type['template'].'_widget.tpl';
  131. }
  132. $where = array();
  133. if( isset($_GET['filter']) && !empty($_GET['filter']['to_date']) ) $where['pub_date'] = array( 'op'=> '<', 'value'=> $_GET['filter']['to_date'] );
  134. if( isset($_GET['filter']) && !empty($_GET['filter']['from_date']) ) $where['pub_date'] = array( 'op'=> '>', 'value'=> $_GET['filter']['from_date'] );
  135. if( isset($_GET['filter']) && !empty($_GET['filter']['main_new']) ) $where['main_new'] = array( 'op'=> '=', 'value'=> $_GET['filter']['main_new'] );
  136. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID, $pubtypeId, $this->request->param('amount'), $where );
  137. if( $this->request->param('type_uri') == Kohana::config('publications')->anounceID || $this->request->param('type_uri') == Kohana::config('publications')->opinionsID)
  138. {
  139. // for announcements
  140. $cats = self::action_getCats( $this->request->param('type_uri') );
  141. $where_cats = array();
  142. foreach( $cats as $item )
  143. $where_cats[] = $item['id'];
  144. $publ_type = Model_Publications::publ_types_load($this->request->param('type_uri'));
  145. $this->view->assign('publ_type', $publ_type );
  146. $this->template = $publ_type['template'].'_widget.tpl';
  147. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , $this->request->param('amount'), $where );
  148. }
  149. $this->view->assign('rows', $list);
  150. }
  151. public function action_narrowwidget()
  152. {
  153. $pubtypeId = $this->request->param('type_uri');
  154. $publ_type = Model_Publications::publ_types_load($pubtypeId);
  155. $this->view->assign('publ_type', $publ_type );
  156. $this->template = $publ_type['template'].'_narrowwidget.tpl';
  157. $where = array();
  158. if( isset($_GET['notID']) && !empty($_GET['notID']) ) $where['publications.id'] = array('op' => '!=', 'value' => $_GET['notID']);
  159. if( $pubtypeId == Kohana::config('profile')->blog_publicationstypes_id )
  160. {
  161. // for opinioins
  162. $cats = self::action_getCats( Kohana::config('profile')->blog_publicationstypes_id );
  163. $where_cats = array();
  164. foreach( $cats as $item )
  165. $where_cats[] = $item['id'];
  166. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , NULL );
  167. }
  168. elseif( $this->request->param('type_uri') == Kohana::config('publications')->anounceID )
  169. {
  170. // for announcements
  171. $cats = self::action_getCats( Kohana::config('publications')->anounceID );
  172. $where_cats = array();
  173. foreach( $cats as $item )
  174. $where_cats[] = $item['id'];
  175. $publ_type = Model_Publications::publ_types_load(Kohana::config('publications')->anounceID);
  176. $this->view->assign('publ_type', $publ_type );
  177. $this->template = $publ_type['template'].'_narrowwidget.tpl';
  178. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , $this->request->param('amount'), $where );
  179. }else
  180. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID, $pubtypeId, $this->request->param('amount'), $where );
  181. $this->view->assign('rows', $list);
  182. }
  183. static public function action_getDayNew( $thisObj )
  184. {
  185. $pub = Model_Frontend_Publications::getDayNew();
  186. $type = Model_Publications::publ_types_load($pub['publicationstypes_id']);
  187. $thisObj->assign('pub_type', $type);
  188. $thisObj->assign('obj', $pub);
  189. return $thisObj->fetch('pub_day_new.tpl');
  190. }
  191. static public function action_getCats( $pubtype_id = NULL )
  192. {
  193. return Model_Publications::getCats( $pubtype_id );
  194. }
  195. static public function action_getAutors( $pubtype_id = NULL )
  196. {
  197. return Model_Publications::getAutors( $pubtype_id );
  198. }
  199. }