/**
  * @return \yii\db\ActiveQuery
  */
 public function getParentContentMedia()
 {
     return $this->hasOne(CmsContentMedia::className(), ['id' => 'parent_content_media_id']);
 }
 /**
  * display a thumbnail version for the media browser.
  * Generate it if none could be found in thumbnail repository
  * @menuLabel __HIDDEN__
  * @param integer $mediaItemId        	
  * @throws NotFoundHttpException
  */
 public function actionThumbnail($mediaItemId)
 {
     $mediaItemId = intval($mediaItemId);
     $isWebaccessableFile = false;
     /** 
      * @var $cmsContentMedia CmsContentMedia 
      */
     $cmsContentMedia = CmsContentMedia::findOne($mediaItemId);
     if ($cmsContentMedia == null) {
         // TODO: do logging, maybe inform admin and display failure image instead
         throw new NotFoundHttpException('Media item could not be found', 404);
     }
     //check if thumbnail folder exists
     if (!is_dir($this->module->getThumbnailRepostoryPath())) {
         if (!mkdir($this->module->getThumbnailRepostoryPath(), 0777, true)) {
             throw new \Exception('Thumbnail folder not found and automatic generation failed. Check access rights for base folder.');
         }
     }
     // check if thumbnail exists
     $filePath = FileHelper::normalizePath($this->module->getThumbnailRepostoryPath() . DIRECTORY_SEPARATOR . $this->getThumbnailFileName($cmsContentMedia));
     if (!file_exists($filePath)) {
         // generate thumbnail
         $filePath = $this->createThumbnail($cmsContentMedia, MediaController::$MEDIA_THUMBNAIL_WIDTH, MediaController::$MEDIA_THUMBNAIL_HEIGHT);
         if (!$filePath) {
             throw new \Exception('Thumbnail not found, but automatic generation failed.');
         }
     }
     $webRootFolder = Yii::getAlias('@webroot');
     $isWebaccessableFile = stripos($filePath, $webRootFolder) === 0;
     // check if item is in web folder, then redirect, or send file instead if not
     if ($isWebaccessableFile) {
         $webPath = substr($filePath, strlen($webRootFolder));
         Yii::$app->response->redirect($webPath);
     } else {
         Yii::$app->response->sendFile($filePath, $cmsContentMedia->file_name, ['mimeType' => $cmsContentMedia->mime_type, 'inline' => true])->send();
     }
 }