예제 #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();
     }
 }
예제 #3
0
 /**
  * makes a full copy of an instruction
  *
  * @param string $type
  * @param string $status
  * @return bool|\Deal
  * @throws InvalidArgumentException
  */
 public function copyAs($type = self::TYPE_SALES, $status = self::STATUS_PRODUCTION)
 {
     if (!in_array($type, [self::TYPE_LETTINGS, self::TYPE_SALES])) {
         throw new InvalidArgumentException('type must be one of the following [' . self::TYPE_LETTINGS . ', ' . self::TYPE_SALES . '] actual value is: ' . $type);
     }
     if (!in_array($status, self::getStatuses())) {
         throw new InvalidArgumentException('Status must be in the list [' . implode(', ', self::getStatuses()) . '] actual value is: ' . $status);
     }
     /** @var $property Property */
     $property = Property::model()->findByPk($this->dea_prop);
     $instruction = new Deal('copy');
     $instruction->setAttributes($this->attributes);
     $instruction->dea_type = $type;
     $instruction->dea_status = $status;
     $instruction->dea_marketprice = 0;
     $instruction->dea_launchdate = null;
     $instruction->importFromProperty($property);
     if ($instruction->save(false)) {
         InstructionVideo::copyRecords($this->dea_id, $instruction->dea_id);
         LinkInstructionToFeature::copyRecords($this->dea_id, $instruction->dea_id);
         LinkClientToInstruction::copyRecords($this->dea_id, $instruction->dea_id);
         Media::copyRecords($this->dea_id, $instruction->dea_id);
         return $instruction;
     }
     return false;
 }
 /**
  * @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();
 }