PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/starter/htdocs/core/modules/apps/components/NewsFeed.class.php

http://energine.googlecode.com/
PHP | 285 lines | 189 code | 26 blank | 70 comment | 28 complexity | e6f284842189d30894b86c4e1cbf1a39 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-3.0
  1. <?php
  2. /**
  3. * ???????? ????? NewsFeed
  4. *
  5. * @package energine
  6. * @subpackage share
  7. * @author dr.Pavka
  8. * @copyright Energine 2007
  9. * @version $Id$
  10. */
  11. /**
  12. * ????? ????????
  13. *
  14. * @package energine
  15. * @subpackage share
  16. * @author dr.Pavka
  17. */
  18. class NewsFeed extends ExtendedFeed {
  19. /**
  20. * ?????????
  21. *
  22. * @access private
  23. * @var Calendar
  24. */
  25. private $calendar;
  26. /**
  27. * ??????????? ??????
  28. * ?????? ???????????? ? ??????? ????????
  29. *
  30. * @param string $name
  31. * @param string $module
  32. * @param array $params
  33. * @access public
  34. */
  35. public function __construct($name, $module, array $params = null) {
  36. parent::__construct($name, $module, $params);
  37. $this->setTableName('apps_news');
  38. $this->setOrder(array('news_date' => QAL::DESC));
  39. if($this->document->getRights()<ACCESS_EDIT){
  40. $this->addFilterCondition(array('news_is_active' => true));
  41. }
  42. if (!$this->document->getProperty('single') && $this->getParam('hasCalendar'))
  43. $this->createCalendar();
  44. }
  45. /**
  46. * ?????????? ?????????? ????????? ?????????? ? ?? ???????? ??-?????????
  47. * ? ???? ??????? array(paramName => defaultValue).
  48. *
  49. * @access protected
  50. * @return array
  51. */
  52. protected function defineParams() {
  53. $result = array_merge(parent::defineParams(),
  54. array(
  55. 'hasCalendar' => false
  56. ));
  57. return $result;
  58. }
  59. protected function createBuilder() {
  60. return new SimpleBuilder();
  61. }
  62. /**
  63. * ??? ??????? ??????? ????? ??????? ???? ????????? ?????? ???????
  64. *
  65. * @return Data
  66. */
  67. protected function createData() {
  68. if ($this->document->getRights() < ACCESS_EDIT) {
  69. $this->addFilterCondition(
  70. 'news_date <= NOW()'
  71. );
  72. }
  73. $res = parent::createData();
  74. return $res;
  75. }
  76. /**
  77. * ????? ??????? ????????
  78. * ????????? ???????????
  79. * ????? ?????? - ????????? ? ???????
  80. */
  81. protected function main() {
  82. $ap = $this->getStateParams(true);
  83. foreach ($dateArr = array(
  84. 'year' => 'YEAR(%s)',
  85. 'month' => 'MONTH(%s)',
  86. 'day' => 'DAY(%s)'
  87. ) as $parameterName => $SQLFuncName) {
  88. if (isset($ap[$parameterName])) {
  89. $this->addFilterCondition(
  90. array(
  91. sprintf($SQLFuncName, 'news_date') => $ap[$parameterName]
  92. )
  93. );
  94. }
  95. }
  96. parent::main();
  97. if ($this->pager) {
  98. $additionalURL = array();
  99. foreach (array_keys($dateArr) as $parameterName) {
  100. if (isset($ap[$parameterName])) {
  101. array_push($additionalURL, $ap[$parameterName]);
  102. }
  103. else {
  104. break;
  105. }
  106. }
  107. if ($additionalURL) {
  108. unset($ap['pageNumber']);
  109. $pageTitle = $this->translate('TXT_NEWS_BY_DATE') . ': ' . implode('/', array_reverse($ap));
  110. E()->getDocument()->componentManager->getBlockByName('breadCrumbs')->addCrumb(null, $pageTitle);
  111. E()->getDocument()->setProperty('title', $pageTitle);
  112. $additionalURL = implode('/', $additionalURL) . '/';
  113. $this->pager->setProperty('additional_url', $additionalURL);
  114. }
  115. }
  116. }
  117. /**
  118. * ????????? ??? ????????????? ??????? ???
  119. *
  120. * @return void
  121. * @access protected
  122. */
  123. protected function view() {
  124. $ap = $this->getStateParams(true);
  125. $this->addFilterCondition(
  126. array(
  127. $this->getTableName() . '.' . $this->getPK() => $ap['id'],
  128. 'news_segment' => $ap['segment'],
  129. )
  130. );
  131. $this->setType(self::COMPONENT_TYPE_FORM);
  132. $this->setDataDescription($this->createDataDescription());
  133. $this->setBuilder($this->createBuilder());
  134. $this->createPager();
  135. $this->setData($this->createData());
  136. if (!$this->getData()->isEmpty()) {
  137. list($newsTitle) = $this->getData()->getFieldByName('news_title')->getData();
  138. $this->document->componentManager->getBlockByName('breadCrumbs')->addCrumb('', $newsTitle);
  139. }
  140. else {
  141. throw new SystemException('ERR_404', SystemException::ERR_404);
  142. }
  143. $this->addToolbar($this->createToolbar());
  144. foreach ($this->getDataDescription() as $fieldDescription) {
  145. $fieldDescription->setMode(FieldDescription::FIELD_MODE_READ);
  146. }
  147. $am = new AttachmentManager($this->getDataDescription(), $this->getData(), $this->getTableName());
  148. $am->createFieldDescription();
  149. $am->createField();
  150. }
  151. /**
  152. * ??????? ???????, ???????????????
  153. * ????????????? ????. ???? ????? ?????????????? ???,
  154. * ?? ??????? ??? ????? ?????????? ??????.
  155. *
  156. * @return void
  157. * @access protected
  158. */
  159. protected function tag() {
  160. $tagID = $this->getStateParams(true);
  161. $tagID = (int)$tagID['tagID'];
  162. $newsIDs = $this->dbh->select($this->getTableName() . '_tags', 'news_id', array('tag_id' => $tagID));
  163. if (is_array($newsIDs)) {
  164. $newsIDs = array_keys(convertDBResult($newsIDs, 'news_id', true));
  165. $this->addFilterCondition(array($this->getTableName() . '.news_id' => $newsIDs));
  166. $tagName = simplifyDBResult(
  167. $this->dbh->select('share_tags', 'tag_name', array('tag_id' => $tagID)),
  168. 'tag_name',
  169. true);
  170. $pageTitle = $this->translate('TXT_NEWS_BY_TAG') . ': ' . $tagName;
  171. E()->getDocument()->componentManager->getBlockByName('breadCrumbs')->addCrumb(null, $pageTitle);
  172. E()->getDocument()->setProperty('title', $pageTitle);
  173. }
  174. $this->main();
  175. if ($newsIDs === true) {
  176. $this->setData(new Data());
  177. }
  178. if($this->pager) {
  179. $this->pager->setProperty('additional_url', 'tag/' . $tagID . '/');
  180. }
  181. }
  182. /**
  183. * ??????? ??? ????????? ?????????? ?????????,
  184. * ??????? ???????? ???????????? ????????? ?? ????????.
  185. *
  186. * @access private
  187. * @var Calendar
  188. */
  189. protected function createCalendar() {
  190. $calendarParams = array();
  191. $ap = $this->getStateParams(true);
  192. if ($this->getState() == 'main') {
  193. if (isset($ap['year']) && isset($ap['month']) &&
  194. isset($ap['day'])
  195. ) {
  196. if ($this->getParam('hasCalendar')) {
  197. $calendarParams['month'] = $ap['month'];
  198. $calendarParams['year'] = $ap['year'];
  199. $calendarParams['date'] =
  200. DateTime::createFromFormat('Y-m-d',
  201. $ap['year'] . '-' . $ap['month'] . '-' .
  202. $ap['day']);
  203. }
  204. $additionalFilter =
  205. 'DAY(news_date) = "' . $ap['day'] .
  206. '" AND MONTH(news_date) = "' .
  207. $ap['month'] .
  208. '" AND YEAR(news_date) = "' .
  209. $ap['year'] . '"';
  210. }
  211. elseif (isset($ap['year']) && isset($ap['month'])) {
  212. if ($this->getParam('hasCalendar')) {
  213. $calendarParams['month'] = $ap['month'];
  214. $calendarParams['year'] = $ap['year'];
  215. }
  216. $additionalFilter =
  217. 'MONTH(news_date) = "' . $ap['month'] .
  218. '" AND YEAR(news_date) = "' .
  219. $ap['year'] . '"';
  220. }
  221. elseif (isset($ap['year'])) {
  222. if ($this->getParam('hasCalendar')) {
  223. $calendarParams['year'] = $ap['year'];
  224. }
  225. $additionalFilter =
  226. 'YEAR(news_date) = "' . $ap['year'] . '"';
  227. }
  228. if ($this->getParam('tags')) {
  229. $filteredIDs = TagManager::getFilter($this->getParam('tags'), $this->tagsTableName);
  230. if (!empty($filteredIDs)) {
  231. $this->addFilterCondition(array('trku_news.news_id' => $filteredIDs));
  232. }
  233. else {
  234. $this->addFilterCondition(array('trku_news.news_id' => 0));
  235. }
  236. }
  237. }
  238. elseif (($this->getState() == 'view') &&
  239. ($this->getParam('hasCalendar'))
  240. ) {
  241. $calendarParams['month'] = $ap['month'];
  242. $calendarParams['year'] = $ap['year'];
  243. $calendarParams['date'] = DateTime::createFromFormat('Y-m-d',
  244. $ap['year'] . '-' . $ap['month'] . '-' . $ap['day']);
  245. }
  246. if ($this->getParam('hasCalendar')) {
  247. $calendarParams['filter'] = $this->getFilter();
  248. $calendarParams['tableName'] = $this->getTableName();
  249. //??????? ????????? ????????? ????????
  250. $this->document->componentManager->addComponent(
  251. $this->calendar =
  252. $this->document->componentManager->createComponent('calendar', 'apps', 'NewsCalendar', $calendarParams)
  253. );
  254. }
  255. if (isset($additionalFilter)) {
  256. $this->addFilterCondition($additionalFilter);
  257. }
  258. }
  259. }