NewsController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?php
  2. namespace manager\controllers;
  3. use manager\models\Gallery;
  4. use manager\models\GalleryImage;
  5. use Yii;
  6. use manager\models\News;
  7. use \app\models\base\Tags;
  8. use \app\models\base\TagsRelation;
  9. use \app\models\base\Story;
  10. use \app\models\base\StoryRelation;
  11. use \app\models\base\NewsTopic;
  12. use \app\models\base\NewsTopicRelation;
  13. use yii\web\UploadedFile;
  14. use \app\helpers\Transliterator;
  15. use zxbodya\yii2\galleryManager\GalleryManagerAction;
  16. use yii\base\ErrorException;
  17. use \app\models\PhotoFilter;
  18. //use zxbodya\yii2\galleryManager\GalleryManager\GalleryImage;
  19. class NewsController extends BaseController
  20. {
  21. // ** Статьи (новости) **
  22. public function actions()
  23. {
  24. return [
  25. 'error' => [
  26. 'class' => 'yii\web\ErrorAction',
  27. ],
  28. 'galleryApi' => [
  29. 'class' => GalleryManagerAction::className(),
  30. // mappings between type names and model classes (should be the same as in behaviour)
  31. 'types' => [
  32. 'product' => News::className(),
  33. 'post_gallery' => Gallery::className()
  34. ]
  35. ],
  36. ];
  37. }
  38. public function actionIndex()
  39. {
  40. return $this->render("/default/news",[]);
  41. }
  42. public function actionList()
  43. {
  44. if (Yii::$app->request->isGet && Yii::$app->request->get('id')){
  45. Yii::$app->session->get('dt-newslistadm');
  46. }else{
  47. Yii::$app->session->remove('dt-newslistadm');
  48. }
  49. return $this->render('/default/newsList', []);
  50. }
  51. public function actionInactive()
  52. {
  53. return $this->render('/default/newsInactive', []);
  54. }
  55. public function actionNewsshow($id)
  56. {
  57. $model = News::findOne($id);
  58. if($model) $model->Active($id);
  59. return $this->redirect(array('list', 'id'=>$id));
  60. }
  61. public function actionDelete($id)
  62. {
  63. if(Yii::$app->user->can('deleteNews')){
  64. $model = News::findOne($id);
  65. if( $model ){
  66. $model->deleteImg($id);
  67. $model->delete();
  68. }
  69. }
  70. return $this->redirect('list');
  71. }
  72. public function actionNewsnh($id)
  73. {
  74. $model = News::findOne($id);
  75. if($model) $model->NH($id);
  76. return $this->redirect(array('list', 'id'=>$id));
  77. }
  78. public function actionNewskd($id)
  79. {
  80. $model = News::findOne($id);
  81. if($model) $model->KD($id);
  82. return $this->redirect(array('list', 'id'=>$id));
  83. }
  84. public function actionNewsping($id)
  85. {
  86. $cache = Yii::$app->cache;
  87. $user = Yii::$app->user->identity->profile->name;
  88. if( $id && $res = $cache->get("editNews_$id") ){
  89. if( unserialize($res)['author'] != $user ){
  90. $cache->set('editNews_'.$id, serialize( array('author'=>$user, 'type' => 'ping' ) ), 90);
  91. return json_encode( ['status'=>'warn', 'author'=>unserialize($res)['author']] );
  92. }
  93. }
  94. $cache->set('editNews_'.$id, serialize( array('author'=>$user, 'type' => 'ping' ) ), 90);
  95. return json_encode( ['status'=>'ok', 'id'=>$id] );
  96. }
  97. public function actionTestping()
  98. {
  99. $authors = array();
  100. $cache = Yii::$app->cache;
  101. $post = Yii::$app->request->get('data');
  102. foreach( unserialize($post) as $id ){
  103. $r = $cache->get("editNews_$id");
  104. if( $r ) $authors[$id] = unserialize($r)['author'];
  105. }
  106. return json_encode( ['status'=>'ok', 'authors'=>$authors] );
  107. }
  108. public function actionCreate()
  109. {
  110. $model = new News();
  111. if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
  112. $pnews = $post['News'];
  113. if( isset($post['cropping']['url']) && $post['cropping']['url'] != '' ){
  114. $pnews['photo_name'] = $post['cropping']['url'];
  115. }
  116. $pnews = $this->formNormalizer($pnews);
  117. $post['News'] = [];
  118. $post['News'] = $pnews;
  119. if($model->load($post, 'News'))
  120. {
  121. if( $model->save($pnews) ){
  122. $id = $model->id;
  123. if( isset($post['Topics']) )
  124. {
  125. $tr = new NewsTopicRelation();
  126. $tr->saveNewsTopics($id, $post['Topics']);
  127. }
  128. if( isset($post['Story']) )
  129. {
  130. $tr = new StoryRelation();
  131. $tr->saveNewsStory($id, $post['Story']);
  132. }
  133. //echo "photo";
  134. //print_r( $_FILES );
  135. if (isset($_FILES['News']) && is_uploaded_file($_FILES['News']['tmp_name']['photo'])) {
  136. // $id = -1; //test
  137. $model->saveImg($id, $_FILES['News']['tmp_name']['photo'], $_FILES['News']['type']['photo']);
  138. }
  139. $tr = new TagsRelation();
  140. if( isset($post['Tags']) )
  141. {
  142. $tr->clearNewsSTG($id);
  143. try {
  144. $tr->saveNewsTags($id, $post['Tags']);
  145. }
  146. catch (\yii\db\Exception $e) {
  147. Yii::warning("Подобный тэг существует");
  148. }
  149. }
  150. if( isset($post['ExtTag']) )
  151. {
  152. $exttag = [];
  153. //удалить повторы
  154. foreach( $post['ExtTag'] as $item )
  155. {
  156. if( isset($post['Tags']) ){
  157. if( !isset( array_flip($post['Tags'])[$item] ) ) $exttag[] = $item;
  158. }else{
  159. $exttag[] = $item;
  160. }
  161. }
  162. try {
  163. $tr->saveNewsTags($id, $exttag);
  164. }
  165. catch (\yii\db\Exception $e) {
  166. Yii::warning("Подобный тэг существует");
  167. }
  168. }
  169. $PFilter = Yii::$app->request->post('PFilter');
  170. if($PFilter){
  171. $pfilter = PhotoFilter::findOne($id);
  172. if( !$pfilter ){
  173. $pfilter = new PhotoFilter();
  174. $pfilter->id = $id;
  175. }
  176. $pfilter->load($_POST, 'PFilter');
  177. $pfilter->save();
  178. }
  179. if( isset( $post['send'] ) ){
  180. Yii::$app->cache->delete("editNews_".$id);
  181. if( isset($post['News']['dt_pub']) ){
  182. $dt = $post['News']['dt_pub'];
  183. return $this->redirect(array('list', 'dt'=>$dt));
  184. }
  185. return $this->redirect('list');
  186. }
  187. //var_dump($model);
  188. ///echo $id; exit;
  189. return $this->redirect(['update', 'id'=>$id]);
  190. }else{
  191. var_dump($model->getErrors());
  192. }
  193. }else{
  194. var_dump($model->getErrors());
  195. }
  196. }
  197. return $this->render('/default/newsCreate', ['model'=>$model]);
  198. }
  199. public function actionUpdate($id)
  200. {
  201. if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
  202. // $model = new \app\models\News();
  203. // $model = $model->find()->andWhere(['id'=>$id])->one();
  204. // Обновить заг галереи
  205. if( isset($post['gallery_name']) && count($post['gallery_name']) > 0 ){
  206. foreach($post['gallery_name'] as $key=>$value){
  207. if( trim($value) == '' ) continue;
  208. \Yii::$app->db->createCommand()
  209. ->update(
  210. \manager\models\Gallery::tableName(),
  211. ['name' => $value],
  212. ['id' => $key]
  213. )->execute(); //->rawSql; //->execute();
  214. }
  215. }
  216. $model = News::findOne($id);
  217. // Удалить фото новости
  218. if( isset($post['News']['del_photo']) && $post['News']['del_photo'] == 'Y'){
  219. $model->deleteImg($id);
  220. }
  221. $pnews = $post['News'];
  222. if( isset($post['cropping']['url']) && $post['cropping']['url'] != '' ){
  223. $pnews['photo_name'] = $post['cropping']['url'];
  224. }
  225. $pnews = $this->formNormalizer($pnews);
  226. $post['News'] = [];
  227. $post['News'] = $pnews;
  228. $model->rev++;
  229. $model->dt_upd = date("Y-m-d H:i:s", time());
  230. if($model->load($post, 'News'))
  231. {
  232. if($model->save($pnews))
  233. {
  234. $tr = new NewsTopicRelation();
  235. if( isset($post['Topics']) )
  236. {
  237. $tr->clearNewsSTG($id);
  238. $tr->saveNewsTopics($id, $post['Topics']);
  239. }else{
  240. $tr->clearNewsSTG($id);
  241. }
  242. $tr = new StoryRelation();
  243. if( isset($post['Story']) )
  244. {
  245. $tr->clearNewsSTG($id);
  246. $tr->saveNewsStory($id, $post['Story']);
  247. }else{
  248. $tr->clearNewsSTG($id);
  249. }
  250. //print_r($_FILES['News']);
  251. //print_r($_REQUEST['cropping']);
  252. if (isset($_FILES['News']) && is_uploaded_file($_FILES['News']['tmp_name']['photo'])) {
  253. // $id = -1; //test
  254. $model->saveImg($id, $_FILES['News']['tmp_name']['photo'], $_FILES['News']['type']['photo']);
  255. }
  256. $tr = new TagsRelation();
  257. if( isset($post['Tags']) )
  258. {
  259. $tr->clearNewsSTG($id);
  260. try {
  261. $tr->saveNewsTags($id, $post['Tags']);
  262. }
  263. catch (\yii\db\Exception $e) {
  264. Yii::warning("Подобный тэг существует");
  265. }
  266. }else{
  267. $tr->clearNewsSTG($id);
  268. }
  269. // добавить тэги для меню фильтров
  270. if( isset($post['ExtTag']) )
  271. {
  272. $exttag = [];
  273. //удалить повторы
  274. foreach( $post['ExtTag'] as $item )
  275. {
  276. if( isset($post['Tags']) ){
  277. if( !isset( array_flip($post['Tags'])[$item] ) ) $exttag[] = $item;
  278. }else{
  279. $exttag[] = $item;
  280. }
  281. }
  282. try {
  283. $tr->saveNewsTags($id, $exttag);
  284. }
  285. catch (\yii\db\Exception $e) {
  286. Yii::warning("Подобный тэг существует");
  287. }
  288. }
  289. $PFilter = Yii::$app->request->post('PFilter');
  290. if($PFilter){
  291. //var_dump($PFilter);exit;
  292. $pfilter = PhotoFilter::findOne($id);
  293. if( !$pfilter ){
  294. $pfilter = new PhotoFilter();
  295. $pfilter->id = $id;
  296. }
  297. $pfilter->load($_POST, 'PFilter');
  298. $pfilter->save();
  299. }
  300. Yii::$app->cache->delete("editNews_".$id);
  301. if( isset( $post['send'] ) ){
  302. if( isset($post['News']['dt_pub']) ){
  303. $dt = $post['News']['dt_pub'];
  304. return $this->redirect(array('list', 'dt'=>$dt));
  305. }
  306. return $this->redirect('list');
  307. }
  308. }else{
  309. echo "no save";
  310. var_dump($model->getErrors());
  311. }
  312. }else{
  313. echo "load";
  314. var_dump($model->getErrors());
  315. }
  316. return $this->render('/default/newsUpdate', ['id'=>$id, 'model'=>$model]);
  317. }
  318. return $this->render('/default/newsUpdate', ['id'=>$id]);
  319. }
  320. public function formNormalizer($post)
  321. {
  322. $profile = Yii::$app->user->identity->profile;
  323. $post['title'] = trim(str_replace( "\xc2\xa0", ' ', $post['title'] ));
  324. $post['title'] = str_replace( ['«','»','&laquo;','&raquo;','&#171;','&laquo;'], '"', $post['title'] );
  325. $post['lid'] = trim(str_replace( "\xc2\xa0", ' ', $post['lid'] ));
  326. $post['lid'] = str_replace( ['«','»','&laquo;','&raquo;','&#171;','&laquo;'], '"', $post['lid'] );
  327. $post['text'] = str_replace( "\xc2\xa0", ' ', $post['text'] );
  328. //удалить 4х-байтные символы UTF
  329. $post['text'] = preg_replace("/[\xf0-\xf7][\x80-\xbf]{3}/", " ", $post['text'] );
  330. $post['active'] = $this->CheckYN(@$post['active']);
  331. $post['show_author'] = $this->CheckYN(@$post['show_author']);
  332. $post['verifed'] = $this->CheckYN(@$post['verifed']);
  333. $post['photo_include'] = $this->CheckYN(@$post['photo_include']);
  334. $post['photo_rcol'] = $this->CheckYN(@$post['photo_rcol']);
  335. $post['top'] = $this->CheckYN(@$post['top']);
  336. if( isset($post['NH']) ){
  337. if( $post['NH'] == 'Y' ){
  338. $post['NH'] = 'Y';
  339. }
  340. if( $post['NH'] == 'F' ){
  341. $post['NH'] = 'F';
  342. }
  343. }else{
  344. $post['NH'] = 'N';
  345. }
  346. $post['photo'] = $this->CheckYN(@$post['photo']);
  347. $post['video'] = $this->CheckYN(@$post['video']);
  348. $post['audio'] = $this->CheckYN(@$post['audio']);
  349. $post['comments'] = ( isset($post['comments']) || ( isset($post['comments']) && $post['comments'] == 'Y') )?'N':'Y';
  350. $post['noindex'] = $this->CheckYN(@$post['noindex']);
  351. $post['export_rss'] = (isset($post['fdzen']) && $post['fdzen'] == 'Y')?1:0;
  352. $post['export_rss'] += (isset($post['fmail']) && $post['fmail'] == 'Y')?2:0;
  353. $post['inscription'] = isset($post['commerc'])?$post['commerc']*1:0;
  354. $post['dt_pub'] = date("Y-m-d H:i:s", strtotime($post['dt_pub']));
  355. $post['alias'] = (isset($post['alias']) && trim( $post['alias'] ) != '' && $post['active'] == 'Y')?$post['alias']:Transliterator::toUrl($post['title']);
  356. $post['editors'] = $post['editors'].(($post['editors'])?',':'').$profile->name;
  357. $post['photo_name'] = isset($post['photo_name'])?$post['photo_name']:'';
  358. $post['flags'] = isset($post['nofirst'])?1:0;
  359. return $post;
  360. }
  361. public function CheckYN($attr)
  362. {
  363. return (isset($attr) && $attr == 'Y')?'Y':'N';
  364. }
  365. // ** Рубрики **
  366. public function actionTopiclist()
  367. {
  368. return $this->render('/default/topicList', []);
  369. }
  370. public function actionTopicall()
  371. {
  372. return $this->render('/default/topicAll', []);
  373. }
  374. public function actionTopicdel($id)
  375. {
  376. $model = $this->findTopicModel($id);
  377. if($model) $model->del($id);
  378. Yii::$app->cache->delete("archive_rubrics-{$id}");
  379. return $this->render('/default/topicList', []);
  380. }
  381. public function actionTopicshow($id)
  382. {
  383. $model = $this->findTopicModel($id);
  384. if($model) $model->Show($id);
  385. Yii::$app->cache->delete("archive_rubrics-{$id}");
  386. return $this->redirect('topiclist');
  387. }
  388. public function actionTopicactive($id)
  389. {
  390. $model = $this->findTopicModel($id);
  391. if($model) $model->Active($id);
  392. Yii::$app->cache->delete("archive_rubrics-{$id}");
  393. return $this->redirect('topiclist');
  394. }
  395. public function actionTopicsort()
  396. {
  397. if (isset($_POST['item']) && is_array($_POST['item'])) {
  398. $i = 0;
  399. $a = array();
  400. // beginTransaction(); было бы неплохо обернуть в транзакцию но хз как это сделать
  401. foreach ($_POST['item'] as $item) {
  402. $model = $this->findTopicModel($item);
  403. $model->order = $i;
  404. $a[$model->id] = $i;
  405. $model->save(true, ['order']);
  406. // print_a($model->errors);
  407. $i++;
  408. }
  409. Yii::$app->cache->delete("archive_rubrics-");
  410. return json_encode(['status'=>'ok','data'=>$a]);
  411. }
  412. return json_encode(['status'=>'err']);
  413. }
  414. public function actionTopiccreate()
  415. {
  416. $model = new NewsTopic();
  417. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  418. if($model->load($_POST) && $model->save()){
  419. if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) {
  420. // $id = -1; //test
  421. $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']);
  422. Yii::$app->cache->delete("archive_rubrics-{$model->id}");
  423. }
  424. }else{
  425. print_a($model->errors);
  426. }
  427. return $this->redirect('topiclist');
  428. }
  429. return $this->render('/default/topicCreate', ['model'=>$model]);
  430. }
  431. public function actionTopicupdate($id)
  432. {
  433. $model = $this->findTopicModel($id);
  434. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  435. if($model->load($_POST) && $model->save()){
  436. // обновление фото
  437. if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) {
  438. $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']);
  439. Yii::$app->cache->delete("archive_rubrics-{$id}");
  440. }
  441. }else{
  442. print_a($model->errors);
  443. }
  444. return $this->redirect('topiclist');
  445. }
  446. return $this->render('/default/topicUpdate', ['model'=>$model]);
  447. }
  448. // ** Сюжеты **
  449. public function actionStorylist()
  450. {
  451. return $this->render('/default/storyList', []);
  452. }
  453. public function actionStorydel($id)
  454. {
  455. $model = $this->findStoryModel($id);
  456. if($model) $model->del($id);
  457. return $this->render('/default/storyList', []);
  458. }
  459. public function actionStoryshow($id)
  460. {
  461. $model = $this->findStoryModel($id);
  462. if($model) $model->Show($id);
  463. return $this->render('/default/storyList', []);
  464. }
  465. public function actionAjaxstory()
  466. {
  467. if (Yii::$app->request->isGet && $get = Yii::$app->request->get('q')){
  468. $model = new Story();
  469. $items = $model->search($get, 20);
  470. $res = array();
  471. if( $items && is_array( $items ) ){
  472. foreach( $items as $item ){
  473. $res[] = array( 'id'=>$item['id']*1, 'label'=>$item['title'] );
  474. }
  475. return json_encode( ['status'=>'ok', 'item'=>$res] );
  476. }
  477. }
  478. return json_encode( ['status'=>'err'] );
  479. }
  480. public function actionStoryactive($id)
  481. {
  482. $model = $this->findStoryModel($id);
  483. if($model) $model->Active($id);
  484. return $this->render('/default/storyList', []);
  485. }
  486. public function actionStorycreate()
  487. {
  488. $model = new Story();
  489. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  490. if($model->load($_POST) && $model->save()){
  491. if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) {
  492. // $id = -1; //test
  493. $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']);
  494. }
  495. }else{
  496. print_a($model->errors);
  497. }
  498. return $this->redirect('storylist');
  499. }
  500. return $this->render('/default/storyCreate', ['model'=>$model]);
  501. }
  502. public function actionStoryupdate($id)
  503. {
  504. $model = $this->findStoryModel($id);
  505. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  506. if($model->load($_POST) && $model->save()){
  507. // обновление фото
  508. if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) {
  509. $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']);
  510. }
  511. }else{
  512. print_a($model->errors);
  513. }
  514. return $this->redirect('storylist');
  515. }
  516. return $this->render('/default/storyUpdate', ['model'=>$model]);
  517. }
  518. public function actionAddGallery()
  519. {
  520. $gallery = new \manager\models\Gallery();
  521. $gallery->load(Yii::$app->request->get(),'');
  522. $gallery->save();
  523. return $this->renderPartial('@manager/views/news/form/galleryItem',["model"=>$gallery]);
  524. }
  525. public function actionRemoveGallery($id)
  526. {
  527. $gallery = \manager\models\Gallery::find()->andWhere(['id'=>$id])->one();
  528. $gallery->delete();
  529. return true;
  530. }
  531. public function actionAjaxgalleryslide()
  532. {
  533. if (Yii::$app->request->isGet){
  534. $id = Yii::$app->request->get('id');
  535. $gid = Yii::$app->request->get('gid');
  536. $title = Yii::$app->request->get('title');
  537. $description = Yii::$app->request->get('description');
  538. //p = new \manager\models\GalleryImage->getUrl(1,'small');
  539. $db = \Yii::$app->db;
  540. $gallery = \manager\models\Gallery::find()->andWhere(['id'=>$gid])->one();
  541. // print_r( $gallery );
  542. $m = $gallery->getBehavior('galleryBehavior');
  543. // print_r( $db->quoteTableName($m->tableName) );
  544. // $tableName = 'gallery_image'; // хз как получить из компонента
  545. $r = $db->createCommand()
  546. ->insert(
  547. $m->tableName,
  548. [
  549. 'type' => 'html',
  550. 'ownerId' => $gid,
  551. 'name' => $title,
  552. 'description' => $description
  553. ]
  554. )->execute();
  555. // $p = new \manager\models\Gallery();
  556. // echo $p->behaviorName;
  557. /*
  558. \yii\helpers\VarDumper::dump(\Yii::$app->db->createCommand()
  559. ->update(
  560. GalleryImage::tableName(),
  561. ['name' => $title],
  562. ['id' => $id]
  563. )->rawSql); //->execute();
  564. */
  565. if( $r ){
  566. return json_encode( ['status'=>'ok', 'id'=>$id, 'gid'=>$gid, 'title'=>$title, 'description'=>$description] );
  567. }
  568. }
  569. return json_encode( ['status'=>'err'] );
  570. }
  571. // ** отладка **
  572. public function actionTest()
  573. {
  574. return $this->render('/default/test', []);
  575. }
  576. /**
  577. * Найти сюжет.
  578. *
  579. * @param $id
  580. * @return Story|null
  581. * @throws NotFoundHttpException
  582. */
  583. protected function findStoryModel($id)
  584. {
  585. if (($model = Story::findOne($id)) !== null) {
  586. return $model;
  587. }
  588. throw new NotFoundHttpException('Ой! сюжет не найдена.');
  589. return false;
  590. }
  591. /**
  592. * Найти Ркбрику.
  593. *
  594. * @param $id
  595. * @return Story|null
  596. * @throws NotFoundHttpException
  597. */
  598. protected function findTopicModel($id)
  599. {
  600. if (($model = NewsTopic::findOne($id)) !== null) {
  601. return $model;
  602. }
  603. throw new NotFoundHttpException('Ой! рубрика не найдена.');
  604. return false;
  605. }
  606. }