Exemple #1
0
 /** Render widget */
 public function run()
 {
     /** @var $cs CClientScript */
     $cs = Yii::app()->clientScript;
     $cs->registerCssFile($this->assets . '/galleryManager.css');
     $cs->registerCoreScript('jquery');
     $cs->registerCoreScript('jquery.ui');
     if (YII_DEBUG) {
         $cs->registerScriptFile($this->assets . '/jquery.iframe-transport.js', CClientScript::POS_END);
         $cs->registerScriptFile($this->assets . '/jquery.galleryManager.js', CClientScript::POS_END);
     } else {
         $cs->registerScriptFile($this->assets . '/jquery.iframe-transport.min.js', CClientScript::POS_END);
         $cs->registerScriptFile($this->assets . '/jquery.galleryManager.min.js', CClientScript::POS_END);
     }
     if ($this->controllerRoute === null) {
         throw new CException('$controllerRoute must be set.', 500);
     }
     $photos = array();
     foreach ($this->gallery->galleryPhotos as $photo) {
         $af = AlbumFoto::model()->findByPk($photo->album_foto_id);
         $photos[] = array('id' => $photo->id, 'rank' => $photo->orden, 'nombre' => (string) $photo->nombre, 'descripcion' => (string) $photo->descripcion, 'preview' => bu('images/galeria/' . $af->directorio . $photo->thumb));
     }
     $opts = array('hasName' => true, 'hasDesc' => true, 'uploadUrl' => Yii::app()->createUrl($this->controllerRoute . '/ajaxUpload', array('album_foto_id' => $this->gallery->id)), 'deleteUrl' => Yii::app()->createUrl($this->controllerRoute . '/delete'), 'updateUrl' => Yii::app()->createUrl($this->controllerRoute . '/changeData'), 'arrangeUrl' => Yii::app()->createUrl($this->controllerRoute . '/order'), 'nameLabel' => Yii::t('galleryManager.main', 'Name'), 'descriptionLabel' => Yii::t('galleryManager.main', 'Description'), 'photos' => $photos);
     if (Yii::app()->request->enableCsrfValidation) {
         $opts['csrfTokenName'] = Yii::app()->request->csrfTokenName;
         $opts['csrfToken'] = Yii::app()->request->csrfToken;
     }
     $opts = CJavaScript::encode($opts);
     $cs->registerScript('galleryManager#' . $this->id, "\$('#{$this->id}').galleryManager({$opts});");
     $this->htmlOptions['id'] = $this->id;
     $this->htmlOptions['class'] = 'GalleryEditor';
     $this->render('galleryManager');
 }
Exemple #2
0
 /** @return Gallery Returns gallery associated with model */
 public function getGallery()
 {
     if (empty($this->_gallery)) {
         //$this->_gallery = Gallery::model()->findByPk($this->getOwner()->{$this->idAttribute});
         $this->_gallery = AlbumFoto::model()->findByPk($this->getOwner()->{$this->idAttribute});
     }
     return $this->_gallery;
 }
Exemple #3
0
 public function actionFoto()
 {
     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 == 5) {
         $url_id = $url->id;
         $af = AlbumFoto::model()->findByAttributes(array('url_id' => $url_id, 'micrositio_id' => $micrositio));
     } else {
         if ($url->tipo_id == 6) {
             $foto = Foto::model()->findByAttributes(array('url_id' => $url->id));
             $af = AlbumFoto::model()->findByPk($foto->album_foto_id);
         }
     }
     if (!$af) {
         throw new CHttpException(404, 'No se encontró la página solicitada');
     }
     $dependencia = new CDbCacheDependency("SELECT GREATEST(MAX(creado), MAX(modificado)) FROM foto WHERE album_foto_id = {$af->id} AND estado <> 0");
     $f = Foto::model()->cache(86400, $dependencia)->findAllByAttributes(array('album_foto_id' => $af->id), array('condition' => 't.estado <> 0', 'order' => 'orden ASC, destacado DESC'));
     $json = '';
     $json .= '[';
     foreach ($f as $foto) {
         $json .= '{';
         $json .= '"id":"' . $foto->id . '",';
         $json .= '"album_foto":"' . CHtml::encode($foto->albumFoto->nombre) . '",';
         $json .= '"url":"' . $foto->url->slug . '",';
         $json .= '"nombre":"' . CHtml::encode($foto->nombre) . '",';
         $json .= '"src":"' . bu('images/galeria/' . $foto->albumFoto->directorio . $foto->src) . '",';
         $json .= '"thumb":"' . bu('images/galeria/' . $foto->albumFoto->directorio . $foto->thumb) . '",';
         $json .= '"ancho":"' . $foto->ancho . '",';
         $json .= '"alto":"' . $foto->alto . '"';
         $json .= '},';
     }
     $json = substr($json, 0, -1);
     $json .= ']';
     $this->_sendResponse(200, $json, 'application/json');
     Yii::app()->end();
 }
 public function loadModel($id)
 {
     $model = AlbumFoto::model()->with('micrositio')->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Method to update images name/description via AJAX.
  * On success returns JSON array od objects with new image info.
  * @throws CHttpException
  */
 public function actionChangeData()
 {
     if (!isset($_POST['photo'])) {
         throw new CHttpException(400, 'Nothing, to save');
     }
     $data = $_POST['photo'];
     $criteria = new CDbCriteria();
     $criteria->index = 'id';
     $criteria->addInCondition('id', array_keys($data));
     /** @var $models GalleryPhoto[] */
     $models = Foto::model()->findAll($criteria);
     foreach ($data as $id => $attributes) {
         if (isset($attributes['name'])) {
             $models[$id]->nombre = $attributes['name'];
         }
         if (isset($attributes['description'])) {
             $models[$id]->descripcion = $attributes['description'];
         }
         $models[$id]->save();
     }
     $resp = array();
     foreach ($models as $model) {
         $af = AlbumFoto::model()->findByPk($model->album_foto_id);
         $resp[] = array('id' => $model->id, 'rank' => $model->orden, 'nombre' => (string) $model->nombre, 'description' => (string) $model->descripcion, 'preview' => $this->galleryDir . '/' . $af->directorio . $model->thumb);
     }
     echo CJSON::encode($resp);
 }
Exemple #6
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $album_foto = AlbumFoto::model()->findByPk($this->album_foto_id);
         $url = new Url();
         $slug = '#imagenes/' . $this->slugger($album_foto->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();
 }
Exemple #7
0
 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;
     }
 }