/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCrear($id) { $video = new Video(); if (isset($_POST['Video'])) { $video->attributes = $_POST['Video']; if ($video->save()) { Yii::app()->user->setFlash('success', 'Video ' . $video->nombre . ' guardado con éxito'); $this->redirect(array('albumvideo/view', 'id' => $video->album_video_id)); } } //if(isset($_POST['NovedadesForm'])) // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $album_video = $id ? AlbumVideo::model()->findByPk($id) : 0; $video->album_video_id = $album_video; $this->render('crear', array('model' => $video)); }
protected function beforeSave() { if ($this->isNewRecord) { $album_video = AlbumVideo::model()->findByPk($this->album_video_id); $url = new Url(); $slug = '#videos/' . $this->slugger($album_video->nombre) . '/' . $this->slugger($this->nombre); $slug = $this->verificarSlug($slug); $url->slug = $slug; $url->tipo_id = 9; //Video $url->estado = 1; if ($url->save()) { $this->url_id = $url->getPrimaryKey(); } else { return false; } $this->creado = date('Y-m-d H:i:s'); } else { $this->modificado = date('Y-m-d H:i:s'); } return parent::beforeSave(); }
<div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'url-form', 'enableAjaxValidation' => false, 'htmlOptions' => array('role' => 'form', 'class' => 'form-horizontal'))); ?> <?php echo $form->errorSummary($model); ?> <div class="form-group"> <?php echo $form->label($model, 'album_video_id', array('class' => 'col-sm-2 control-label')); ?> <div class="col-sm-6"> <?php echo $form->dropDownList($model, 'album_video_id', CHtml::listData(AlbumVideo::model()->with('micrositio')->findAll(), 'id', function ($av) { return $av->nombre . ' (' . $av->micrositio->nombre . ')'; }), array('class' => 'form-control')); ?> </div> <?php echo $form->error($model, 'album_video_id'); ?> </div> <div class="form-group"> <?php echo $form->label($model, 'proveedor_video_id', array('class' => 'col-sm-2 control-label')); ?> <div class="col-sm-2"> <?php echo $form->dropDownList($model, 'proveedor_video_id', CHtml::listData(ProveedorVideo::model()->findAll(), 'id', 'nombre'), array('class' => 'form-control')); ?> </div>
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Url the loaded model * @throws CHttpException */ public function loadModel($id) { $model = AlbumVideo::model()->with('micrositio')->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
protected function beforeDelete() { $this->transaccion = $this->dbConnection->getCurrentTransaction(); if ($this->transaccion === null) { $this->transaccion = $this->dbConnection->beginTransaction(); } try { $this->pagina_id = NULL; $this->save(NULL); foreach ($this->paginas as $pagina) { $p = Pagina::model()->findByPk($pagina->id); $p->delete(); } foreach ($this->albumFotos as $albumFoto) { $af = AlbumFoto::model()->findByPk($albumFoto->id); $af->delete(); } foreach ($this->albumVideos as $albumVideo) { $av = AlbumVideo::model()->findByPk($albumVideo->id); $av->delete(); } foreach ($this->programacions as $programacion) { $pr = Programacion::model()->findByPk($programacion->id); $pr->delete(); } foreach ($this->redSocials as $redSocial) { $r = RedSocial::model()->findByPk($redSocial->id); $r->delete(); } return parent::beforeDelete(); } catch (Exception $e) { $this->transaccion->rollback(); return false; } }
public function actionVideo() { if (!$_GET['hash']) { throw new CHttpException(404, 'No se encontró la página solicitada'); } if (!$_GET['micrositio']) { throw new CHttpException(404, 'No se encontró la página solicitada'); } $hash = $_GET['hash']; $micrositio = $_GET['micrositio']; $url = Url::model()->findByAttributes(array('slug' => $hash)); if ($url->tipo_id == 8) { $url_id = $url->id; $va = AlbumVideo::model()->find(array('condition' => 'url_id = :u_id AND micrositio_id = :m_id AND t.estado <> 0', 'params' => array(':u_id' => $url_id, ':m_id' => $micrositio))); } else { if ($url->tipo_id == 9) { $video = Video::model()->findByAttributes(array('url_id' => $url->id)); $va = AlbumVideo::model()->findByPk($video->album_video_id, array('condition' => 't.estado <> 0')); } } if (!$va) { throw new CHttpException(404, 'No se encontró la página solicitada'); } $dependencia = new CDbCacheDependency("SELECT GREATEST(MAX(creado), MAX(modificado)) FROM video WHERE album_video_id = {$va->id} AND estado <> 0"); $v = Video::model()->cache(86400, $dependencia)->findAll(array('condition' => 'album_video_id = :av_id AND t.estado <> 0', 'order' => 'destacado DESC, modificado DESC, creado DESC', 'params' => array(':av_id' => $va->id))); $json = ''; $json .= '['; foreach ($v as $video) { $json .= '{'; $json .= '"id":"' . CHtml::encode($video->id) . '",'; $json .= '"album_video":"' . CHtml::encode($video->albumVideo->nombre) . '",'; $json .= '"proveedor_video":"' . CHtml::encode($video->proveedorVideo->nombre) . '",'; $json .= '"url":"' . CHtml::encode($video->url->slug) . '",'; $json .= '"nombre":"' . CHtml::encode($video->nombre) . '",'; $json .= '"descripcion":' . json_encode($video->descripcion) . ','; $json .= '"url_video":"' . $video->url_video . '",'; if ($video->proveedor_video_id == 1) { preg_match("/^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\\/))([^\\?&\"'>]+)/", $video->url_video, $matches); if (isset($matches[1])) { $id_video = $matches[1]; } else { $id_video = 0; } $thumbnail = 'http://img.youtube.com/vi/' . $id_video . '/0.jpg'; } else { if ($video->proveedor_video_id == 2) { $url = 'http://vimeo.com/api/oembed.json?url=' . rawurlencode($video->url_video); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($curl); curl_close($curl); $return = json_decode($return); $id_video = $return->video_id; $thumbnail = $return->thumbnail_url; } else { $id_video = 0; } } $json .= '"id_video":"' . $id_video . '",'; $json .= '"thumbnail":"' . $thumbnail . '",'; $json .= '"duracion":"' . $video->duracion . '"'; $json .= '},'; } $json = substr($json, 0, -1); $json .= ']'; $this->_sendResponse(200, $json, 'application/json'); Yii::app()->end(); }