/**
  * Format form data
  * @param integer $requiredRows
  * @param array $formValues
  * @param string $errMsg
  * @return array $data
  */
 public static function formatFormData($requiredRows, $formValues, &$errMsg)
 {
     // set displayTitle = categoryName if displayTitle is empty
     foreach ($formValues['displayTitle'] as $order => &$value) {
         if (empty($value)) {
             $value = $formValues['categoryName'][$order];
         }
     }
     // Remove rows where categoryName is empty
     $resetRows = false;
     $rows = count($formValues['categoryName']);
     $helper = new VideoPageToolHelper();
     for ($i = $rows - 1; $i >= $helper->getRequiredRowsMin('category'); $i--) {
         if (!empty($formValues['categoryName'][$i])) {
             break;
         }
         foreach (STATIC::$dataFields as $formFieldName => $varName) {
             unset($formValues[$formFieldName][$i]);
         }
         $resetRows = true;
     }
     // update required rows
     if ($resetRows) {
         $requiredRows = $helper->getRequiredRows('category', $formValues);
     }
     return parent::formatFormData($requiredRows, $formValues, $errMsg);
 }
 /**
  * Get asset data (used in template)
  * @param array $thumbOptions An optional array of options to pass to the thumbnailer
  * @return array An associative array of video metadata for the video named by $this->title
  *
  * The associative array data returned has the keys:
  *     videoTitle      => Human readable title, e.g. "Soul Bubbles Nintendo DS Trailer - Bubbles"
  *     videoKey        => DBKey of the title, e.g. "Soul_Bubbles_Nintendo_DS_Trailer_-_Bubbles"
  *     displayTitle    => Preferred title entered via Admin tool, e.g. "Bubbles from "Soul Bubbles" on Nintendo DS"
  *     videoThumb      => Embed code for the video thumbnail.
  *     largeThumbUrl   => Large version of the video thumbnail image.  Does not include the embed code.
  *     altThumbName    => Human readable title of the thumbnail that will replace original thumbnail
  *     altThumbKey     => DBKey of the thumbnail that will replace original thumbnail
  *     description     => Description of this video given in the Admin tool, e.g. "All about Bubbles!"
  *     videoTitleClass =>
  *     altThumbClass   =>
  *     updatedBy       => User who updated this asset last, e.g. "Garthwebb"
  *     updatedAt       => Date this asset was last updated, e.g. "17:04, September 13, 2013"
  */
 public function getAssetData($thumbOptions = array())
 {
     // Allow defaults to be overridden by options passed into us
     $thumbOptions = array_merge($this::$defaultThumbOptions, $thumbOptions);
     $helper = new VideoPageToolHelper();
     $data = $helper->getVideoData($this->title, $this->altThumbTitle, $this->displayTitle, $this->description, $thumbOptions);
     if (empty($data)) {
         return self::getDefaultAssetData();
     }
     // This needs to be set to an empty string when there is a real asset rather than default asset data
     $data['videoTitleClass'] = '';
     $data['altThumbClass'] = '';
     $assetData = array_merge($data, parent::getAssetData());
     return $assetData;
 }
 /**
  * Hook: Clear cache (videos by category) when video is deleted. We only need
  * to check if the file is a local video, we don't need the rest of the parameters
  * OnFileDeleteComplete passes in by default. Instead, after verifying the file is
  * a local video we find the latest program and clear the cache for the category
  * names defined in the category assets for that program.
  * @param LocalFile $file
  * @param $oldimage
  * @param $article
  * @param User $user
  * @param $reason
  * @return true
  */
 public static function onFileDeleteComplete(&$file, $oldimage, $article, $user, $reason)
 {
     if (WikiaFileHelper::isFileTypeVideo($file) && $file->isLocal()) {
         $controller = new VideoHomePageController();
         $program = $controller->getProgram();
         $assets = $program->getAssetsBySection(VideoHomePageController::MODULE_CATEGORY);
         $helper = new VideoPageToolHelper();
         foreach ($assets as $asset) {
             $title = Title::newFromText($asset->getCategoryName(), NS_CATEGORY);
             $helper->invalidateCacheVideosByCategory($title->getDBkey());
         }
     }
     return true;
 }
 /**
  * Get videos by category
  * @requestParam string categoryName
  * @responseParam string $result [ok/error]
  * @responseParam string $msg - result message
  * @responseParam array thumbnails - the list of videos in the category
  * @responseParam integer total - the number of videos in the category
  * @responseParam string url - the url of the category page
  * @responseParam string seeMoreLabel
  */
 public function getVideosByCategory()
 {
     $categoryName = $this->getVal('categoryName', '');
     if (empty($categoryName)) {
         $this->result = 'error';
         $this->msg = wfMessage('videopagetool-error-invalid-category')->plain();
         return;
     }
     $title = Title::newFromText($categoryName, NS_CATEGORY);
     if (empty($title)) {
         $this->result = 'error';
         $this->msg = wfMessage('videopagetool-error-unknown-category')->plain();
         return;
     }
     $helper = new VideoPageToolHelper();
     $this->result = 'ok';
     $this->msg = '';
     $this->thumbnails = $helper->getVideosByCategory($title);
     $this->total = $helper->getVideosByCategoryCount($title);
     $this->url = $title->escapeLocalURL();
     $this->seeMoreLabel = wfMessage('videopagetool-see-more-label')->plain();
 }
 /**
  * Displays the fan module
  * @responseParam array $assets
  */
 public function fan()
 {
     $helper = new VideoPageToolHelper();
     $this->assets = $helper->renderAssetsBySection($this->getProgram(), self::MODULE_FAN);
 }
 /**
  * Format form data
  * @param integer $requiredRows
  * @param array $formValues
  * @param string $errMsg
  * @return array $data
  */
 public static function formatFormData($requiredRows, $formValues, &$errMsg)
 {
     $data = array();
     for ($i = 0; $i < $requiredRows; $i++) {
         foreach (static::$dataFields as $formFieldName => $varName) {
             // validate form
             $helper = new VideoPageToolHelper();
             $helper->validateFormField($formFieldName, $formValues[$formFieldName][$i], $errMsg);
             // format data
             $order = $i + 1;
             // because input data start from 0
             $data[$order][$varName] = $formValues[$formFieldName][$i];
         }
     }
     return $data;
 }