PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/seyar/kinda.local
PHP | 256 lines | 183 code | 62 blank | 11 comment | 36 complexity | f12e42da30ac273122c5e1aad03a92af MD5 | raw file
  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. $this->view->assign('publ_type', $publ_type );
  53. $this->template = $publ_type['template'].'_list.tpl';
  54. }
  55. if($this->request->param('value'))
  56. $this->view->assign('filter', $this->request->param('value'));
  57. $page_title = isset($publ_type['pubtype_title']) ? $publ_type['pubtype_title'] : Kohana::config('publications.titles.main');
  58. $this->page_info = array('page_title' => $page_title );
  59. $this->view->assign('rows', $list[0]);
  60. $this->view->assign('page_line', $list[1]);
  61. $this->view->assign('total_pages', $list[2]);
  62. }
  63. public function action_comment()
  64. {
  65. die();
  66. $publ_types = Model_Frontend_Publications::publication_types(CURRENT_LANG_ID);
  67. if (!$this->request->param('type_uri'))
  68. echo Kohana::debug($publ_types);
  69. else
  70. {
  71. foreach ($publ_types as $value)
  72. {
  73. $url = str_replace('//', '/', '/' . $value['parent_url'] . $value['url']);
  74. echo Kohana::debug("$url=/" . $this->request->param('type_uri'));
  75. if ($url == '/' . $this->request->param('type_uri'))
  76. {
  77. echo Kohana::debug($value);
  78. }
  79. }
  80. }
  81. echo Kohana::debug($this->request);
  82. die();
  83. }
  84. public function action_view()
  85. {
  86. $url = '/'.$this->request->param('type_uri').'/'. $this->request->param('id');
  87. $obj = Model_Publications::publ_load_by_url($url, CURRENT_LANG_ID);
  88. /* ratings */
  89. $rating = Model_Frontend_Ratings::getItem($obj['id']);
  90. $obj['rating'] = $rating['rating'];
  91. /* ratings */
  92. $publ_type = Model_Publications::publ_types_load($obj['publicationstypes_id']);
  93. $this->view->assign('publ_type', $publ_type );
  94. $this->template = $publ_type['template'].'.tpl';
  95. if ($obj['id'])
  96. $obj['images'] = Model_Publications::publ_images_show(
  97. Controller_Frontend_Publications::images_folder . "/",
  98. $path = '',
  99. MEDIAWEBPATH . Controller_Frontend_Publications::images_folder . "/{$obj['id']}",
  100. $obj['id']
  101. );
  102. $this->page_info = array('page_title' => $obj['pub_title'], 'page_keywords' => $obj['pub_keywords'],
  103. 'page_keywords' => $obj['pub_description'],);
  104. $obj['user'] = Model_Registration::get_items($obj['add_fields']['user_id']['value_int']);
  105. $this->view->assign('obj', $obj);
  106. $obj_datetime = strtotime($obj['pub_date']);
  107. $lastNews = Model_Frontend_Publications::publication_top( CURRENT_LANG_ID,1,3 );
  108. $this->view->assign('obj_date', $obj_datetime );
  109. $this->view->assign('lastNews', $lastNews );
  110. $this->view->assign('month_names', I18n::get(strtolower(date('M', $obj_datetime))));
  111. $this->view->assign('publ_id', $this->request->param('id'));
  112. }
  113. public function action_widget()
  114. {
  115. $pubtypeId = $this->request->param('type_uri');
  116. if( strstr($pubtypeId, '_') )
  117. {
  118. $pubtypeId = explode('_',$this->request->param('type_uri'));
  119. $this->template = 'publication_'.$this->request->param('type_tpl').'_widget.tpl';
  120. }
  121. else
  122. {
  123. $publ_type = Model_Publications::publ_types_load($pubtypeId);
  124. $this->view->assign('publ_type', $publ_type );
  125. $this->template = $publ_type['template'].'_widget.tpl';
  126. }
  127. $where = array();
  128. if( isset($_GET['filter']) && !empty($_GET['filter']['to_date']) ) $where['pub_date'] = array( 'op'=> '<', 'value'=> $_GET['filter']['to_date'] );
  129. if( isset($_GET['filter']) && !empty($_GET['filter']['from_date']) ) $where['pub_date'] = array( 'op'=> '>', 'value'=> $_GET['filter']['from_date'] );
  130. if( isset($_GET['filter']) && !empty($_GET['filter']['main_new']) ) $where['main_new'] = array( 'op'=> '=', 'value'=> $_GET['filter']['main_new'] );
  131. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID, $pubtypeId, $this->request->param('amount'), $where );
  132. if( $this->request->param('type_uri') == Kohana::config('publications')->anounceID || $this->request->param('type_uri') == Kohana::config('publications')->opinionsID)
  133. {
  134. // for announcements
  135. $cats = self::action_getCats( $this->request->param('type_uri') );
  136. $where_cats = array();
  137. foreach( $cats as $item )
  138. $where_cats[] = $item['id'];
  139. $publ_type = Model_Publications::publ_types_load($this->request->param('type_uri'));
  140. $this->view->assign('publ_type', $publ_type );
  141. $this->template = $publ_type['template'].'_widget.tpl';
  142. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , $this->request->param('amount'), $where );
  143. }
  144. $this->view->assign('rows', $list);
  145. }
  146. public function action_narrowwidget()
  147. {
  148. $pubtypeId = $this->request->param('type_uri');
  149. $publ_type = Model_Publications::publ_types_load($pubtypeId);
  150. $this->view->assign('publ_type', $publ_type );
  151. $this->template = $publ_type['template'].'_narrowwidget.tpl';
  152. $where = array();
  153. if( isset($_GET['notID']) && !empty($_GET['notID']) ) $where['publications.id'] = array('op' => '!=', 'value' => $_GET['notID']);
  154. if( $pubtypeId == Kohana::config('profile')->blog_publicationstypes_id )
  155. {
  156. // for opinioins
  157. $cats = self::action_getCats( Kohana::config('profile')->blog_publicationstypes_id );
  158. $where_cats = array();
  159. foreach( $cats as $item )
  160. $where_cats[] = $item['id'];
  161. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , NULL );
  162. }
  163. elseif( $this->request->param('type_uri') == Kohana::config('publications')->anounceID )
  164. {
  165. // for announcements
  166. $cats = self::action_getCats( Kohana::config('publications')->anounceID );
  167. $where_cats = array();
  168. foreach( $cats as $item )
  169. $where_cats[] = $item['id'];
  170. $publ_type = Model_Publications::publ_types_load(Kohana::config('publications')->anounceID);
  171. $this->view->assign('publ_type', $publ_type );
  172. $this->template = $publ_type['template'].'_narrowwidget.tpl';
  173. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID,$where_cats , $this->request->param('amount'), $where );
  174. }else
  175. $list = Model_Frontend_Publications::publication_index(CURRENT_LANG_ID, $pubtypeId, $this->request->param('amount'), $where );
  176. $this->view->assign('rows', $list);
  177. }
  178. static public function action_getDayNew( $thisObj )
  179. {
  180. $pub = Model_Frontend_Publications::getDayNew();
  181. $type = Model_Publications::publ_types_load($pub['publicationstypes_id']);
  182. $thisObj->assign('pub_type', $type);
  183. $thisObj->assign('obj', $pub);
  184. return $thisObj->fetch('pub_day_new.tpl');
  185. }
  186. static public function action_getCats( $pubtype_id = NULL )
  187. {
  188. return Model_Publications::getCats( $pubtype_id );
  189. }
  190. static public function action_getAutors( $pubtype_id = NULL )
  191. {
  192. return Model_Publications::getAutors( $pubtype_id );
  193. }
  194. }