Пример #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTaskeds()
 {
     return $this->hasMany(Tasked::className(), ['task_id' => 'id']);
 }
Пример #2
0
 /**
  * Сохранение задачи
  * @return string
  * @throws \Exception
  */
 public function actionTasked()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $user = Yii::$app->getRequest()->getQueryParam('user');
         if (Yii::$app->getRequest()->getQueryParam('task_id') !== null && Yii::$app->getRequest()->getQueryParam('mark') !== null) {
             //return var_dump($user);
             $task = Task::findOne(Yii::$app->getRequest()->getQueryParam('task_id'));
             $task->status = 2;
             $task->update();
             $act = new DiaryActs();
             $act->model_id = 2;
             $act->user_id = (int) $user;
             $act->mark = (int) Yii::$app->getRequest()->getQueryParam('mark');
             $act->mark_status = 0;
             if ($act->save(false)) {
                 $tasked = new Tasked();
                 $tasked->task_id = $task->id;
                 $tasked->user_id = (int) $user;
                 $tasked->act_id = $act->id;
                 $tasked->mark = (int) Yii::$app->getRequest()->getQueryParam('mark');
                 $tasked->mark_status = 0;
                 //return var_dump($tasked);
                 if ($tasked->save()) {
                     return "<span style='color:green'>Задача выполнена!</span>";
                 } else {
                     "<span style='color:red'>Ошибка сохранения tasked</span>";
                 }
             } else {
                 return "<span style='color:red'>Ошибка валидации</span>";
             }
         }
     }
 }
Пример #3
0
 /**
  * Генератор дневника знаний
  */
 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);
 }