NewsController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. if( isset($_FILES['News']) && is_uploaded_file($_FILES['News']['tmp_name']['photo']) ){
  362. $post['photo_name'] = '';
  363. }else{
  364. $post['photo_name'] = isset($post['photo_name'])?$post['photo_name']:'';
  365. }
  366. $post['flags'] = isset($post['nofirst'])?1:0;
  367. $post['flags'] = $post['flags'] | (isset($post['photoamic'])?2:0);
  368. return $post;
  369. }
  370. public function CheckYN($attr)
  371. {
  372. return (isset($attr) && $attr == 'Y')?'Y':'N';
  373. }
  374. // ** Рубрики **
  375. public function actionTopiclist()
  376. {
  377. return $this->render('/default/topicList', []);
  378. }
  379. public function actionTopicall()
  380. {
  381. return $this->render('/default/topicAll', []);
  382. }
  383. public function actionTopicdel($id)
  384. {
  385. $model = $this->findTopicModel($id);
  386. if($model) $model->del($id);
  387. Yii::$app->cache->delete("archive_rubrics-{$id}");
  388. return $this->render('/default/topicList', []);
  389. }
  390. public function actionTopicshow($id)
  391. {
  392. $model = $this->findTopicModel($id);
  393. if($model) $model->Show($id);
  394. Yii::$app->cache->delete("archive_rubrics-{$id}");
  395. return $this->redirect('topiclist');
  396. }
  397. public function actionTopicactive($id)
  398. {
  399. $model = $this->findTopicModel($id);
  400. if($model) $model->Active($id);
  401. Yii::$app->cache->delete("archive_rubrics-{$id}");
  402. return $this->redirect('topiclist');
  403. }
  404. public function actionTopicsort()
  405. {
  406. if (isset($_POST['item']) && is_array($_POST['item'])) {
  407. $i = 0;
  408. $a = array();
  409. // beginTransaction(); было бы неплохо обернуть в транзакцию но хз как это сделать
  410. foreach ($_POST['item'] as $item) {
  411. $model = $this->findTopicModel($item);
  412. $model->order = $i;
  413. $a[$model->id] = $i;
  414. $model->save(true, ['order']);
  415. // print_a($model->errors);
  416. $i++;
  417. }
  418. Yii::$app->cache->delete("archive_rubrics-");
  419. return json_encode(['status'=>'ok','data'=>$a]);
  420. }
  421. return json_encode(['status'=>'err']);
  422. }
  423. public function actionTopiccreate()
  424. {
  425. $model = new NewsTopic();
  426. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  427. if($model->load($_POST) && $model->save()){
  428. if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) {
  429. // $id = -1; //test
  430. $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']);
  431. Yii::$app->cache->delete("archive_rubrics-{$model->id}");
  432. }
  433. }else{
  434. print_a($model->errors);
  435. }
  436. return $this->redirect('topiclist');
  437. }
  438. return $this->render('/default/topicCreate', ['model'=>$model]);
  439. }
  440. public function actionTopicupdate($id)
  441. {
  442. $model = $this->findTopicModel($id);
  443. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  444. if($model->load($_POST) && $model->save()){
  445. // обновление фото
  446. if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) {
  447. $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']);
  448. Yii::$app->cache->delete("archive_rubrics-{$id}");
  449. }
  450. }else{
  451. print_a($model->errors);
  452. }
  453. return $this->redirect('topiclist');
  454. }
  455. return $this->render('/default/topicUpdate', ['model'=>$model]);
  456. }
  457. // ** Сюжеты **
  458. public function actionStorylist()
  459. {
  460. return $this->render('/default/storyList', []);
  461. }
  462. public function actionStorydel($id)
  463. {
  464. $model = $this->findStoryModel($id);
  465. if($model) $model->del($id);
  466. return $this->render('/default/storyList', []);
  467. }
  468. public function actionStoryshow($id)
  469. {
  470. $model = $this->findStoryModel($id);
  471. if($model) $model->Show($id);
  472. return $this->render('/default/storyList', []);
  473. }
  474. public function actionAjaxstory()
  475. {
  476. if (Yii::$app->request->isGet && $get = Yii::$app->request->get('q')){
  477. $model = new Story();
  478. $items = $model->search($get, 20);
  479. $res = array();
  480. if( $items && is_array( $items ) ){
  481. foreach( $items as $item ){
  482. $res[] = array( 'id'=>$item['id']*1, 'label'=>$item['title'] );
  483. }
  484. return json_encode( ['status'=>'ok', 'item'=>$res] );
  485. }
  486. }
  487. return json_encode( ['status'=>'err'] );
  488. }
  489. public function actionStoryactive($id)
  490. {
  491. $model = $this->findStoryModel($id);
  492. if($model) $model->Active($id);
  493. return $this->render('/default/storyList', []);
  494. }
  495. public function actionStorycreate()
  496. {
  497. $model = new Story();
  498. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  499. if($model->load($_POST) && $model->save()){
  500. if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) {
  501. // $id = -1; //test
  502. $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']);
  503. }
  504. }else{
  505. print_a($model->errors);
  506. }
  507. return $this->redirect('storylist');
  508. }
  509. return $this->render('/default/storyCreate', ['model'=>$model]);
  510. }
  511. public function actionStoryupdate($id)
  512. {
  513. $model = $this->findStoryModel($id);
  514. if (Yii::$app->request->isPost && Yii::$app->request->post()){
  515. if($model->load($_POST) && $model->save()){
  516. // обновление фото
  517. if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) {
  518. $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']);
  519. }
  520. }else{
  521. print_a($model->errors);
  522. }
  523. return $this->redirect('storylist');
  524. }
  525. return $this->render('/default/storyUpdate', ['model'=>$model]);
  526. }
  527. public function actionAddGallery()
  528. {
  529. $gallery = new \manager\models\Gallery();
  530. $gallery->load(Yii::$app->request->get(),'');
  531. $gallery->save();
  532. return $this->renderPartial('@manager/views/news/form/galleryItem',["model"=>$gallery]);
  533. }
  534. public function actionRemoveGallery($id)
  535. {
  536. $gallery = \manager\models\Gallery::find()->andWhere(['id'=>$id])->one();
  537. $gallery->delete();
  538. return true;
  539. }
  540. public function actionAjaxgalleryslide()
  541. {
  542. if (Yii::$app->request->isGet){
  543. $id = Yii::$app->request->get('id');
  544. $gid = Yii::$app->request->get('gid');
  545. $title = Yii::$app->request->get('title');
  546. $description = Yii::$app->request->get('description');
  547. //p = new \manager\models\GalleryImage->getUrl(1,'small');
  548. $db = \Yii::$app->db;
  549. $gallery = \manager\models\Gallery::find()->andWhere(['id'=>$gid])->one();
  550. // print_r( $gallery );
  551. $m = $gallery->getBehavior('galleryBehavior');
  552. // print_r( $db->quoteTableName($m->tableName) );
  553. // $tableName = 'gallery_image'; // хз как получить из компонента
  554. $r = $db->createCommand()
  555. ->insert(
  556. $m->tableName,
  557. [
  558. 'type' => 'html',
  559. 'ownerId' => $gid,
  560. 'name' => $title,
  561. 'description' => $description
  562. ]
  563. )->execute();
  564. // $p = new \manager\models\Gallery();
  565. // echo $p->behaviorName;
  566. /*
  567. \yii\helpers\VarDumper::dump(\Yii::$app->db->createCommand()
  568. ->update(
  569. GalleryImage::tableName(),
  570. ['name' => $title],
  571. ['id' => $id]
  572. )->rawSql); //->execute();
  573. */
  574. if( $r ){
  575. return json_encode( ['status'=>'ok', 'id'=>$id, 'gid'=>$gid, 'title'=>$title, 'description'=>$description] );
  576. }
  577. }
  578. return json_encode( ['status'=>'err'] );
  579. }
  580. // ** отладка **
  581. public function actionTest()
  582. {
  583. return $this->render('/default/test', []);
  584. }
  585. /**
  586. * Найти сюжет.
  587. *
  588. * @param $id
  589. * @return Story|null
  590. * @throws NotFoundHttpException
  591. */
  592. protected function findStoryModel($id)
  593. {
  594. if (($model = Story::findOne($id)) !== null) {
  595. return $model;
  596. }
  597. throw new NotFoundHttpException('Ой! сюжет не найдена.');
  598. return false;
  599. }
  600. /**
  601. * Найти Ркбрику.
  602. *
  603. * @param $id
  604. * @return Story|null
  605. * @throws NotFoundHttpException
  606. */
  607. protected function findTopicModel($id)
  608. {
  609. if (($model = NewsTopic::findOne($id)) !== null) {
  610. return $model;
  611. }
  612. throw new NotFoundHttpException('Ой! рубрика не найдена.');
  613. return false;
  614. }
  615. }