public function tearDown()
 {
     if (!empty($this->program)) {
         $this->program->delete();
     }
     parent::tearDown();
 }
 /**
  * Get the current program object or load it if it hasn't been loaded yet
  * @return VideoPageToolProgram
  */
 public function getProgram()
 {
     if (!$this->program) {
         $lang = F::App()->wg->LanguageCode;
         $this->program = VideoPageToolProgram::loadProgramNearestDate($lang);
     }
     return $this->program;
 }
 /**
  * Render assets by section (used in VideoHomePageController)
  * @param VideoPageToolProgram $program
  * @param string $section [featured/category/fan]
  * @param array $thumbOptions An optional array of thumbnail options to override the defaults for the given asset.
  * @return array
  */
 public function renderAssetsBySection($program, $section, $thumbOptions = array())
 {
     $data = array();
     if ($program instanceof VideoPageToolProgram) {
         $assets = $program->getAssetsBySection($section);
         foreach ($assets as $asset) {
             /** @var VideoPageToolAsset $asset */
             $data[] = $asset->getAssetData($thumbOptions);
         }
     }
     return $data;
 }
 /**
  * get calendar info
  * @requestParam string language
  * @requestParam string startTime [timestamp]
  * @requestParam string endTime [timestamp]
  * @responseParam array info [array( date => status ); date = yyyy-mm-dd; status = 0 (not published)/ 1 (published)]
  * @responseParam string result [ok/error]
  * @responseParam string msg - result message
  */
 public function getCalendarInfo()
 {
     $errMsg = '';
     if (!$this->validateUser($errMsg)) {
         $this->result = 'error';
         $this->msg = $errMsg;
         return;
     }
     $language = $this->getVal('language', VideoPageToolHelper::DEFAULT_LANGUAGE);
     $startTime = $this->getVal('startTime', strtotime('first day of this month'));
     $endTime = $this->getVal('endTime', strtotime('first day of next month'));
     $helper = new VideoPageToolHelper();
     // validate language
     $languages = $helper->getLanguages();
     if (!array_key_exists($language, $languages)) {
         $this->result = 'error';
         $this->msg = wfMessage('videopagetool-error-invalid-language')->plain();
         $this->info = array();
         return;
     }
     // validate date
     $sDate = getdate($startTime);
     $eDate = getdate($endTime);
     if (!checkdate($sDate['mon'], $sDate['mday'], $sDate['year']) || !checkdate($eDate['mon'], $eDate['mday'], $eDate['year'])) {
         $this->result = 'error';
         $this->msg = wfMessage('videopagetool-error-invalid-date')->plain();
         $this->info = array();
         return;
     }
     // Make sure the end date comes after the start date
     if ($startTime > $endTime) {
         $this->result = 'error';
         $this->msg = wfMessage('videopagetool-error-invalid-date')->plain();
         $this->info = array();
         return;
     }
     // Get the first day of the month for the requested start
     $requestTime = strtotime('first day of this month', $startTime);
     $requestDate = date('Y-m-d', $requestTime);
     // Get the first day of them month for the end date in the range
     $endDate = date('Y-m-d', strtotime('first day of this month', $endTime));
     // Get one month worth of data starting at $requestDate
     $info = VideoPageToolProgram::getProgramsForMonth($language, $requestDate);
     // If we have more than one month to retrieve, keep fetching them.  We only fetch per
     // month so that we can easily determine what to invalidate when we update programs
     while ($requestDate != $endDate) {
         $requestTime = strtotime('first day of next month', $requestTime);
         $requestDate = date('Y-m-d', $requestTime);
         $nextInfo = VideoPageToolProgram::getProgramsForMonth($language, $requestDate);
         $info = array_merge($info, $nextInfo);
     }
     $this->result = 'ok';
     $this->msg = '';
     $this->info = $info;
 }
 /**
  * Get program object
  * @return VideoPageToolProgram
  */
 public function getProgram()
 {
     $program = VideoPageToolProgram::newFromId($this->programId);
     return $program;
 }