Пример #1
0
 public function actionIndex()
 {
     $videoCr = new CDbCriteria();
     $videoCr->order = 'displayOrder ASC';
     $videoCr->scopes = ['publicAvailableInstruction'];
     $videoCr->limit = 6;
     $this->render('index', array('latestProperties' => Deal::model()->getLatest(6), 'featuredVideo' => InstructionVideo::model()->with('instruction')->findByAttributes(['featuredVideo' => 1]), 'mostViewed' => Deal::model()->getMostViewed(1, date("Y-m-d H:i:s", strtotime("-15 days"))), 'instructionVideos' => InstructionVideo::model()->with('instruction')->findAllByAttributes(['displayOnSite' => 1], $videoCr), 'propertyCategories' => PropertyCategory::model()->active()->displayOnHome()->findAll()));
 }
 public function actionRearrange()
 {
     $newOrder = isset($_POST['newOrder']) ? $_POST['newOrder'] : '';
     if ($newOrder) {
         $cases = '';
         foreach ($newOrder as $orderNum => $id) {
             $cases .= " WHEN id = " . $id . " THEN " . ($orderNum + 1) . "";
         }
         $sql = "UPDATE " . InstructionVideo::model()->tableName() . "\n\t\t\t\tSET displayOrder = CASE " . $cases . " END";
         Yii::app()->db->createCommand($sql)->execute();
     }
 }
 /**
  * @param $instructionId
  * @param $video
  * @throws CException
  * @return bool
  */
 private function saveVideo($instructionId, $video)
 {
     if (!$instructionId) {
         throw new CException("Instruction id must be passed");
     }
     $videoId = $video['videoId'];
     if (isset($video['featureVideo'])) {
         $featureVideo = $video['featureVideo'];
     }
     if (isset($video['displayOnSite'])) {
         $displayOnSite = $video['displayOnSite'];
     }
     $instructionVideo = InstructionVideo::model()->findByAttributes(['instructionId' => $instructionId]);
     if ($instructionVideo) {
         InstructionVideo::model()->findByAttributes(['instructionId' => $instructionId])->delete();
     }
     if (!isset($videoId) || !$videoId) {
         return false;
     }
     if (!($data = @file_get_contents('http://vimeo.com/api/v2/video/' . $videoId . '.json'))) {
         return false;
     }
     $data = json_decode($data, true);
     if (!$data[0]) {
         return false;
     }
     $newInstructionVideo = new InstructionVideo();
     $newInstructionVideo->instructionId = $instructionId;
     $newInstructionVideo->videoId = $videoId;
     if (!empty($featureVideo)) {
         InstructionVideo::model()->updateAll(['featuredVideo' => 0]);
         $newInstructionVideo->featuredVideo = 1;
     }
     if (!empty($displayOnSite)) {
         $newInstructionVideo->displayOnSite = 1;
     }
     $newInstructionVideo->host = 'vimeo';
     $newInstructionVideo->videoData = json_encode(str_replace(["\n", "\r"], "", $data[0]));
     return $newInstructionVideo->save();
 }