public function setStartDate($date) { if ($this->startDate) { // todo: can be better $posts = Posts::find()->where(['PostType' => 2])->orderBy('PostID')->all(); foreach ($posts as $post) { $postIds[] = $post->PostID; } $startDatePost = PostDates::find()->where(['PostID' => $postIds, 'PostDateType' => 1])->one(); $startDatePost->PostDate = $date; $startDatePost->save(); $this->startDate = $date; } else { $post = new Posts(); $post->UserID = Yii::$app->user->getId(); $post->PostType = 2; $post->save(); $postDate = new PostDates(); $postDate->PostDateType = 1; $postDate->PostID = $post->PostID; $postDate->PostDate = $date; $postDate->save(); $this->startDate = $date; } }
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]); } } }