/** * * Sets the fields for a cc_show_days table row * @param $showData * @param $showId * @param $userId * @param $repeatType * @param $isRecorded * @param $showDay ccShowDay object we are setting values on */ private function setCcShowDays($showData) { $showId = $this->ccShow->getDbId(); $startDateTime = new DateTime($showData['add_show_start_date'] . " " . $showData['add_show_start_time'], new DateTimeZone($showData['add_show_timezone'])); $endDateTime = $this->calculateEndDate($showData); if (!is_null($endDateTime)) { $endDate = $endDateTime->format("Y-m-d"); } else { $endDate = null; } //Our calculated start DOW must be used for non repeating since a day has not been selected. //For all repeating shows, only the selected days of the week will be repeated on. $startDow = $startDateTime->format("w"); if (!$showData['add_show_repeats']) { $showData['add_show_day_check'] = array($startDow); } // Don't set day for monthly repeat type, it's invalid if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($this->isUpdate) { $showDay = CcShowDaysQuery::create()->filterByDbShowId($showId)->filterByDbRepeatType($showData['add_show_repeat_type'])->findOne(); } else { $showDay = new CcShowDays(); } $showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTime->format("H:i:s")); $showDay->setDbTimezone($showData['add_show_timezone']); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbRepeatType($this->repeatType); $showDay->setDbShowId($showId); $showDay->setDbRecord($this->isRecorded); //in case we are editing a show we need to set this to the first show //so when editing, the date period iterator will start from the beginning $showDay->setDbNextPopDate($startDateTime->format("Y-m-d")); $showDay->save(); } else { foreach ($showData['add_show_day_check'] as $day) { $daysAdd = 0; $startDateTimeClone = clone $startDateTime; if ($startDow !== $day) { if ($startDow > $day) { $daysAdd = 6 - $startDow + 1 + $day; } else { $daysAdd = $day - $startDow; } $startDateTimeClone->add(new DateInterval("P" . $daysAdd . "D")); } if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if ($this->isUpdate) { $showDay = CcShowDaysQuery::create()->filterByDbShowId($showId)->filterByDbRepeatType($this->repeatType)->filterByDbDay($day)->findOne(); if (!$showDay) { //if no show day object was found it is because a new //repeating day of the week was added $showDay = new CcShowDays(); } } else { $showDay = new CcShowDays(); } $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTimeClone->format("H:i")); $showDay->setDbTimezone($showData['add_show_timezone']); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbDay($day); $showDay->setDbRepeatType($this->repeatType); $showDay->setDbShowId($showId); $showDay->setDbRecord($this->isRecorded); //in case we are editing a show we need to set this to the first show //so when editing, the date period iterator will start from the beginning $showDay->setDbNextPopDate($startDateTimeClone->format("Y-m-d")); $showDay->save(); } } } }