public function actionAdd($ingredientId)
 {
     // less queries here
     $postType = Posts::TYPE_USER_INGREDIENTS;
     $post = Posts::find()->where(['and', ['PostType' => $postType], ['UserID' => Yii::$app->user->getId()]])->one();
     if (!$post) {
         $post = new Posts();
         $post->PostType = $postType;
         $post->UserID = Yii::$app->user->getId();
         $post->save();
     }
     $ingredient = Tags::findOne($ingredientId);
     $post->link('tags', $ingredient);
 }
 public function getUserIngredients()
 {
     $post = Posts::find()->where(['and', ['PostType' => Posts::TYPE_USER_INGREDIENTS], ['UserID' => Yii::$app->user->getId()]])->one();
     if ($post) {
         $tags = $post->tags;
     } else {
         $tags = [];
     }
     $userTags = [];
     foreach ($tags as $tag) {
         $userTags[$tag->TagID] = $tag->Name;
     }
     return $userTags;
 }
 public function actionIndex($username)
 {
     //phrasedisp
     //phrase
     //mondaysdisp
     //
     // @todo: sort post dates
     // @todo: draw 2 weeks, week, 2 days and so on for past post dates
     $userid = User::findByUsername($username)->id;
     if ($userid) {
         $vacationDates = new PastDates(Yii::$app->user->getId());
         $startDate = $vacationDates->getStartDate();
         $datePosts = $vacationDates->getDatePosts();
         if ($startDate) {
             // dont show data
             $posts = Posts::find()->where(['and', ['UserID' => $userid], ['PostType' => 2]])->all();
             $postids = [];
             foreach ($posts as $p) {
                 $postids[] = $p['PostID'];
             }
             $postdates = PostDates::find()->where(['PostID' => $postids])->all();
             $ps = [];
             foreach ($postdates as $postdate) {
                 $ps[] = $postdate['PostDate'];
             }
             $vacations = new Determinate($startDate, null, $ps);
             $allHolidays = $vacations->getAllHolidays();
             $weekendHolidays = $vacations->getWeekendHolidays();
             $workDayHolidays = $vacations->getWorkDayHolidays();
             $daysForTwoWeeks = $vacations->getDaysForVacations(14);
             $furureMondaysForTwoWeeks = $vacations->getFurureMondays(14);
             $furureWorkingHoursForTwoWeeks = $vacations->getFurureWorkingHours(14);
             $daysForWeek = $vacations->getDaysForVacations(7);
             $furureMondaysForWeek = $vacations->getFurureMondays(7);
             $furureWorkingHoursForWeek = $vacations->getFurureWorkingHours(7);
             $daysForDay = $vacations->getDaysForVacations(1);
             $furureMondaysForDay = $vacations->getFurureMondays(1);
             $furureWorkingHoursForDay = $vacations->getFurureWorkingHours(1);
             return $this->render('index', ['username' => $username, 'posts' => $postdates, 'postids' => $postids, 'allHolidays' => $allHolidays, 'weekendHolidays' => $weekendHolidays, 'workDayHolidays' => $workDayHolidays, 'daysForTwoWeeks' => $daysForTwoWeeks, 'furureMondaysForTwoWeeks' => $furureMondaysForTwoWeeks, 'furureWorkingHoursForTwoWeeks' => $furureWorkingHoursForTwoWeeks, 'daysForWeek' => $daysForWeek, 'furureMondaysForWeek' => $furureMondaysForWeek, 'furureWorkingHoursForWeek' => $furureWorkingHoursForWeek, 'daysForDay' => $daysForDay, 'furureMondaysForDay' => $furureMondaysForDay, 'furureWorkingHoursForDay' => $furureWorkingHoursForDay, 'startDate' => $startDate, 'datePosts' => $datePosts]);
         } else {
             $model = new Posts();
             return $this->render('set_start_date', ['username' => $username]);
         }
     }
 }
 public function getDatePosts()
 {
     $dataProvider = new ActiveDataProvider(['query' => Posts::find()->joinWith('postDates')->where(['PostType' => 2, 'UserID' => \Yii::$app->user->getId(), 'PostDates.PostDateType' => 0])]);
     return $dataProvider;
 }
 public static function deleteWish($postid)
 {
     $data = Posts::find()->where(['and', 'UserID' => \Yii::$app->user->getId(), 'PostID' => $postid])->one();
     if (isset($data->PostID)) {
         Posts::deleteAll(['PostID' => $postid]);
         PostURL::deleteAll(['PostID' => $postid]);
         // След строчки уже были в коде, можно вынести их
         $imgstodelete = PostImgs::find()->select(['PostImgID', 'PostImg'])->where(['PostID' => $postid])->all();
         if (count($imgstodelete)) {
             foreach ($imgstodelete as $img) {
                 if (isset($img->PostImgID)) {
                     unlink(Yii::getAlias('@webroot/photos/wishlist/' . \Yii::$app->user->getId() . '/' . $img->PostImgID . '-xn.jpg'));
                     unlink(Yii::getAlias('@webroot/photos/wishlist/' . \Yii::$app->user->getId() . '/' . $img->PostImgID . '-n.jpg'));
                     unlink(Yii::getAlias('@webroot/photos/wishlist/' . \Yii::$app->user->getId() . '/' . $img->PostImgID . '-s.jpg'));
                 }
             }
         }
         PostImgs::deleteAll(['PostID' => $postid]);
     }
 }
Пример #6
0
 public function actionRead()
 {
     $read = Posts::find()->where(['id' => 1])->one();
     return $this->render('read', ['read' => $read]);
 }