NewsController.php 20 KB

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