예제 #1
0
 /**
  * Method to handle file upload thought XHR2
  * On success returns JSON object with image info.
  * @param $album_foto_id string Gallery Id to upload images
  * @throws CHttpException
  */
 public function actionAjaxUpload($album_foto_id = null)
 {
     $album_foto = AlbumFoto::model()->findByPk($album_foto_id);
     $imageFile = CUploadedFile::getInstanceByName('image');
     $time = time() + rand();
     $base = Yii::getPathOfAlias('webroot') . '/' . $this->galleryDir . '/' . $album_foto->directorio;
     $src = $time . '.' . $this->galleryExt;
     $thumb = $time . '_thumb.' . $this->galleryExt;
     $image = new Image($imageFile->getTempName());
     $image->save($base . $src);
     $image_thumb = new Image($imageFile->getTempName());
     $image_thumb->resize(300, null);
     $image_thumb->save($base . $thumb);
     //Yii::app()->image->load($imageFile->getTempName())->save($src);
     //Yii::app()->image->load($imageFile->getTempName())->resize(300, null)->save($thumb);
     $model = new Foto();
     $model->album_foto_id = $album_foto_id;
     $url = new Url();
     $slug = '#imagenes/' . $this->slugger($album_foto->nombre) . '/' . $this->slugger($time);
     $slug = $this->verificarSlug($slug);
     $url->slug = $slug;
     $url->tipo_id = 6;
     //Foto
     $url->estado = 1;
     $url->save();
     $model->url_id = $url->getPrimaryKey();
     $model->src = $src;
     $model->thumb = $thumb;
     $model->nombre = $time;
     $model->descripcion = '';
     $model->ancho = $image->width;
     $model->alto = $image->height;
     $model->orden = 0;
     $model->estado = 1;
     $model->destacado = 0;
     $model->save();
     header("Content-Type: application/json");
     echo CJSON::encode(array('id' => $model->id, 'rank' => $model->orden, 'name' => (string) $model->nombre, 'description' => (string) $model->descripcion, 'preview' => bu($this->galleryDir . '/' . $album_foto->directorio . $thumb)));
 }
예제 #2
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $url = new Url();
             $slug = '#imagenes/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->tipo_id = 5;
             //Álbum de fotos
             $url->estado = 1;
             $url->save();
             $this->url_id = $url->getPrimaryKey();
             $this->creado = date('Y-m-d H:i:s');
         } else {
             $this->modificado = date('Y-m-d H:i:s');
         }
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
파일: Video.php 프로젝트: Telemedellin/tm
 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();
 }
예제 #4
0
파일: Pagina.php 프로젝트: Telemedellin/tm
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $micrositio = Micrositio::model()->findByPk($this->micrositio_id);
         $url = new Url();
         if ($micrositio->seccion->nombre == 'sin-seccion') {
             $slug = $this->slugger($micrositio->nombre) . '/' . $this->slugger($this->nombre);
         } else {
             $slug = $this->slugger($micrositio->seccion->nombre) . '/' . $this->slugger($micrositio->nombre) . '/' . $this->slugger($this->nombre);
         }
         $slug = $this->verificarSlug($slug);
         $url->slug = $slug;
         $url->tipo_id = 3;
         //Página
         $url->estado = 1;
         if ($url->save()) {
             $this->url_id = $url->getPrimaryKey();
         } else {
             return false;
         }
         $this->usuario_id = Yii::app()->user->getState('usuario_id');
         $this->revision_id = NULL;
         $this->creado = date('Y-m-d H:i:s');
         if (!$this->estado) {
             $this->estado = 0;
         }
     } else {
         //Crear la revisión
         $this->revision_id = NULL;
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }
예제 #5
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $seccion = Seccion::model()->findByPk($this->seccion_id);
         $url = new Url();
         $slug = $this->slugger($seccion->nombre) . '/' . $this->slugger($this->nombre);
         $slug = $this->verificarSlug($slug);
         $url->slug = $slug;
         $url->tipo_id = 2;
         //Micrositio
         $url->estado = 1;
         $url->save();
         $this->url_id = $url->getPrimaryKey();
         $this->usuario_id = Yii::app()->user->getState('usuario_id');
         $this->pagina_id = NULL;
         $this->menu_id = NULL;
         $this->creado = date('Y-m-d H:i:s');
     } else {
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }
예제 #6
0
파일: Carpeta.php 프로젝트: Telemedellin/tm
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $parent = Carpeta::model()->with('url')->findByPk($this->item_id);
         $this->pagina_id = $parent->pagina_id;
         $this->hijos = 0;
         $url = new Url();
         $nombre_slug = $this->slugger($this->carpeta);
         $url->slug = $this->verificarSlug($parent->url->slug . '/' . $nombre_slug);
         $url->tipo_id = 10;
         //Carpeta
         $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();
 }