public function updateContent(Request $request, $id, $aid) { $article = Article::find($id); $content = ArticlesContent::find($aid); $content->content = $request->input('content'); $content->save(); return response()->json($content); }
/** * Показываем контент * @param $id * @return string */ public function actionShow($id) { $article = Articles::findOne($id); $comment = new Comments(); $this->title = $article->title; $allArticles = ArticlesContent::find()->where(['articles_id' => $id]); //var_dump($allArticles); exit; $countQuery = clone $allArticles; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]); $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all(); $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title; $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name; return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]); }
/** * Получает массив умных фраз * * @return array */ public function actionGetphrases() { $arr = []; if (__DIR__ == '/home/romanych/public_html/plis/basic/modules/bardzilla/controllers') { $allPhrases = ArticlesContent::find()->joinWith(['articles' => function ($query) { $query->andWhere('cat_id = 35'); }])->all(); // var_dump($allPhrases); exit; } else { $allPhrases = ArticlesContent::find()->joinWith(['articles' => function ($query) { $query->andWhere('cat_id = 5'); }])->all(); // var_dump($allPhrases); exit; } foreach ($allPhrases as $phrase) { $arr[] = $phrase->body; } return json_encode($arr); }
public function actionKlavir() { /* $query = new Query(); // $search_result = $query_search->from('siteSearch')->match($q)->all(); // поиск осуществляется по средством метода match с переданной поисковой фразой. $r = $query->from('items') ->match('шкалика') ->all(); var_dump(Items::findOne($r)); exit; */ $article_id = Articles::find()->select('MAX(id)')->scalar(); if ($article_id) { $article = Articles::findOne($article_id); } else { return $this->redirect(Url::toRoute('articles/index')); } $artContent = new ArticlesContent(); if ($artContent->load(Yii::$app->request->post())) { $artContent->body = Yii::$app->request->post('ArticlesContent')['body']; $artContent->minititle = Yii::$app->request->post('ArticlesContent')['minititle']; $artContent->source_id = 434; $artContent->articles_id = $article_id; if ($this->loadModel($article_id)->site_id == 13) { $act = new DiaryActs(); $act->model_id = 6; $act->mark = 1; $act->user_id = 8; $act->save(false); } $artContent->save(); $content = ArticlesContent::find()->where(['articles_id' => $article_id]); $dataCont = new ActiveDataProvider(['query' => $content]); return $this->render('pages', ['content' => $dataCont, 'model' => $artContent]); } else { return $this->render('klavir', ['model' => $artContent]); } }
/** * Генератор дневника знаний */ public function actionDiaryGenerator() { $arr = []; $arr['ate_sum_kkal'] = 0; $article_time = '00:00'; $start_day = strtotime('now 00:00:00'); $today = date('Ymd', $start_day); //$today = '20161011_01'; //echo $today.PHP_EOL; exit; $today_acts = DiaryActs::find()->where("time > {$start_day} and user_id = 8")->all(); //var_dump($today_acts); exit; $f = 0; foreach ($today_acts as $act) { switch ($act->model_id) { case 1: if (DiaryAte::find()->where(['act_id' => $act->id])->one()) { $arr['ate'][$act->time] = DiaryAte::find()->where(['act_id' => $act->id])->one(); } $arr['ate_sum_kkal'] += DiaryAte::find()->where(['act_id' => $act->id])->one()->kkal; break; case 2: $arr['tasked'][$act->time] = Tasked::find()->where(['act_id' => $act->id])->one(); break; case 3: $arr['bought'][$act->time] = Bought::find()->where(['act_id' => $act->id])->one(); break; case 4: $arr['day_params'][$act->time] = DiaryRecDayParams::find()->where(['act_id' => $act->id])->one(); break; case 5: $arr['deals'][$act->time] = DiaryDoneDeal::find()->where(['act_id' => $act->id])->one(); break; case 6: if (Articles::find()->where(['act_id' => $act->id])->one()) { if ($f == 0) { echo $f . " " . $today . PHP_EOL; $articles = ArticlesContent::find()->where(['articles_id' => Articles::find()->where(['act_id' => $act->id])->one()->id])->all(); //var_dump($articles); exit; //$article_time = $act->time; $arr['article_title'] = Articles::find()->where(['act_id' => $act->id])->one()->title; $f = 1; } } break; case 7: if (Items::find()->where(['act_id' => $act->id])->one()) { $arr['items'][$act->time] = Items::find()->where(['act_id' => $act->id])->one(); } break; case 9: if (Incomes::find()->where(['act_id' => $act->id])->one()) { $arr['incomes'][$act->time] = Incomes::find()->where(['act_id' => $act->id])->one(); } break; case 10: if (Event::find()->where(['act_id' => $act->id])->one()) { $arr['events'][$act->time] = Event::find()->where(['act_id' => $act->id])->one(); } break; } } $ate_sum_kkal = $arr['ate_sum_kkal']; //print_r($arr['articles']); var_dump($articles); exit; $file = fopen("/home/romanych/www/vrs/diary/2016/{$today}.html", "w"); //хэдер fwrite($file, '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style>.item_head{font-weight: bold;} body{padding-left: 20px; padding-top: 20px; background-color: rgba(78, 82, 65, 0.11);} img {width: 100%;min-height: 100px;} h3,h4,h5 {color: #994b43; text-align: left; margin-top: 1px; margin-bottom: 5px;} .mini{font-size: 10px; margin: 0; } .image img{width: auto;} </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> '); if (isset($arr['article_title'])) { fwrite($file, "<hr><h3>" . date('d-m-Y', $start_day) . " " . $arr['article_title'] . "</h3><div class=\"btn-group\">\n <button type=\"button\" class=\"btn btn-default\"><span class=\"glyphicon glyphicon-star\"></button>\n \n </div> <script>\n \$('.mw-editsection-visualeditor').hide();\n </script>"); } /*блок еды if(isset($arr['ate'])){ fwrite($file, "<p>Съел $ate_sum_kkal kkal</p> <table class='table'> <tbody> <tr > <td>м</td> <td>блюдо</td> <td>кол-во</td> <td>ккал</td> </tr>"); foreach ($arr['ate'] as $key => $ate){ $dish = $ate->dish->name; $time = date('H:i',$key+7*3600); fwrite($file, " <tr > <td> $time </td> <td> $dish </td> <td> $ate->measure </td> <td> $ate->kkal </td> </tr> "); } fwrite($file, "</tbody></table>"); } */ // блок статей $i = 0; if (isset($articles) && $arr['article_title']) { fwrite($file, "<hr><h4>**Статьи**</h4>"); foreach ($articles as $article) { $i++; fwrite($file, "<hr><h4>*" . $i . " " . $article->source->author->name . " - - " . $article->source->title . "</h4>"); fwrite($file, "<h4>" . $article->minititle . "</h4>"); fwrite($file, $article->body); } } //блок айтемов if (isset($arr['items'])) { fwrite($file, "<hr><h4>**Краткости талантов**</h4>"); foreach ($arr['items'] as $time => $item) { $i++; fwrite($file, "<p class='mini'>*" . $i . " " . date('H:i', $time) . " "); fwrite($file, $item->title . "<br>"); fwrite($file, " " . $item->source->title . " - " . $item->source->author->name . " - " . $item->cat->name . "</p>"); if ($item->old_data) { fwrite($file, "<p class='mini'>" . $item->old_data . "</p>"); } if ($item->img) { fwrite($file, "<img src=/" . $item->img . ">"); } fwrite($file, "<p>" . nl2br($item->text) . "</p>"); } } //блок событий //var_dump($arr['events']); if (isset($arr['events'])) { fwrite($file, "<hr><h4>**События**</h4>"); foreach ($arr['events'] as $time => $event) { $i++; fwrite($file, "<p class='mini'>*" . $i . " " . date('H:i', $time) . " -"); fwrite($file, $event->cat->name . " - "); if ($event->old_data) { fwrite($file, " " . $event->old_data . "</p>"); } else { fwrite($file, "</p>"); } if ($event->img) { fwrite($file, "<img src=/" . $event->img . ">"); } fwrite($file, "<p>" . nl2br($event->text) . "</p>"); } } fwrite($file, self::$footer); fclose($file); }