Example #1
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();
 }
Example #2
0
 protected function beforeDelete()
 {
     try {
         foreach ($this->fotos as $foto) {
             $v = Foto::model()->findByPk($foto->id);
             $v->delete();
         }
         return parent::beforeDelete();
     } catch (Exception $e) {
         return false;
     }
 }
 public function actionUploadFoto()
 {
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $id = Yii::app()->request->getParam('id');
     $file = Yii::app()->request->getParam('filename');
     $folder = Yii::app()->getBasePath() . "/../images/checklist/images/checklist_" . $id . "/";
     // folder for uploaded files
     $allowedExtensions = array("jpg", "png", "pdf");
     //array("jpg","jpeg","gif","exe","mov" and etc...
     $sizeLimit = 5 * 1024 * 1024;
     // maximum file size in bytes
     $checklist = Foto::model()->findByAttributes(array('checklist_id' => $id));
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit, $checklist->{$file}, $file);
     $result = $uploader->handleUpload($folder, true);
     $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     $fileName = $result['filename'];
     //GETTING FILE NAME
     $checklist->{$file} = $fileName;
     $checklist->update();
     // $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
     echo $return;
     // it's array
 }
Example #4
0
 /**
  * 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);
 }
 public function actionDirectorios()
 {
     $fotos = Foto::model()->findAll();
     foreach ($fotos as $foto) {
         $src = $foto->src;
         $thumb = $foto->thumb;
         $ps = array_reverse(explode('/', $src));
         $pt = array_reverse(explode('/', $thumb));
         $foto->src = $ps[0];
         $foto->thumb = $pt[0];
         $foto->save();
     }
 }
Example #6
0
 /** @return GalleryPhoto[] Photos from associated gallery */
 public function getGalleryPhotos()
 {
     $criteria = new CDbCriteria();
     //$criteria->condition = 'gallery_id = :gallery_id';
     $criteria->condition = 'album_foto_id = :album_foto_id';
     //$criteria->params[':gallery_id'] = $this->getOwner()->{$this->idAttribute};
     $criteria->params[':album_foto_id'] = $this->getOwner()->{$this->idAttribute};
     //$criteria->order = '`rank` asc';
     $criteria->order = '`orden` asc';
     //return GalleryPhoto::model()->findAll($criteria);
     return Foto::model()->findAll($criteria);
 }