コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Pagina();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Pagina'])) {
         $model->attributes = $_POST['Pagina'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->pagina_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
コード例 #2
0
ファイル: PaginaController.php プロジェクト: munozdaniel/sya
 /**
  * Creates a new pagina
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "pagina", "action" => "index"));
     }
     $pagina = new Pagina();
     $pagina->setPaginaNombrecontrolador($this->request->getPost("pagina_nombreControlador"));
     $pagina->setPaginaNombreaccion($this->request->getPost("pagina_nombreAccion"));
     if (!$pagina->save()) {
         foreach ($pagina->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "pagina", "action" => "new"));
     }
     $this->flash->success("pagina was created successfully");
     return $this->dispatcher->forward(array("controller" => "pagina", "action" => "index"));
 }
コード例 #3
0
ファイル: EspecialesForm.php プロジェクト: Telemedellin/tm
 public function guardar()
 {
     $dir = $this->imageRoute;
     $image_base = Yii::getPathOfAlias('webroot') . '/images/';
     if ($this->validate()) {
         if (isset($this->id)) {
             //Actualizando
             $micrositio = Micrositio::model()->findByPk($this->id);
         } else {
             //Nuevo registro
             $micrositio = new Micrositio();
         }
         $transaccion = $micrositio->dbConnection->beginTransaction();
         $micrositio->seccion_id = 3;
         //Especiales
         $micrositio->nombre = $this->nombre;
         if ($this->imagen != $micrositio->background) {
             if (file_exists($image_base . $micrositio->background)) {
                 @unlink($image_base . $micrositio->background);
             }
             $micrositio->background = $dir . $this->imagen;
         }
         if ($this->imagen_mobile != $micrositio->background_mobile) {
             if (file_exists($image_base . $micrositio->background_mobile)) {
                 @unlink($image_base . $micrositio->background_mobile);
             }
             $micrositio->background_mobile = $dir . $this->imagen_mobile;
         }
         if ($this->miniatura != $micrositio->miniatura) {
             if (file_exists($image_base . $micrositio->miniatura)) {
                 @unlink($image_base . $micrositio->miniatura);
             }
             $micrositio->miniatura = $dir . $this->miniatura;
         }
         $micrositio->destacado = $this->destacado;
         $micrositio->estado = $this->estado;
         if (!$micrositio->save(false)) {
             $transaccion->rollback();
         }
         $micrositio_id = $micrositio->getPrimaryKey();
         if (isset($this->id)) {
             $pagina = Pagina::model()->findByAttributes(array('micrositio_id' => $micrositio_id));
         } else {
             $pagina = new Pagina();
             $pagina->micrositio_id = $micrositio_id;
             $pagina->tipo_pagina_id = 10;
             //Página bloques
         }
         $pagina->nombre = $this->nombre;
         $pagina->meta_descripcion = $this->meta_descripcion;
         $pagina->clase = NULL;
         $pagina->destacado = $this->destacado;
         $pagina->estado = $this->estado == 2 ? 1 : $this->estado;
         if (!$pagina->save(false)) {
             $transaccion->rollback();
         }
         $pagina_id = $pagina->getPrimaryKey();
         if (isset($this->id)) {
             //Actualizando
             $pgB = PgBloques::model()->findByAttributes(array('pagina_id' => $pagina_id));
         } else {
             if (!$micrositio->asignar_pagina($pagina)) {
                 $transaccion->rollback();
             }
             $pgB = new PgBloques();
             $pgB->pagina_id = $pagina_id;
         }
         $pgB->estado = $this->estado;
         if (!$pgB->save(false)) {
             $transaccion->rollback();
             return false;
         } else {
             $transaccion->commit();
             $this->id = $micrositio_id;
             return true;
         }
     } else {
         return false;
     }
 }
コード例 #4
0
 public function test2()
 {
     /**
      * Consultas:
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina ( titulo ,contenido ,class ,deleted ,owner_id ,id ) VALUES ('Pagina raiz' ,'This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don\'t really have to worry about it. It can be useful later on if you\'re trying to...' ,'Pagina' ,'0' ,NULL ,'1' );
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina ( titulo ,contenido ,class ,deleted ,owner_id ,id ) VALUES ('Subpagina de raiz 1' ,'This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don\'t really have to worry about it. It can be useful later on if you\'re trying to...' ,'Pagina' ,'0' ,'1' ,'2' );
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina ( titulo ,contenido ,class ,deleted ,owner_id ,id ) VALUES ('Sub subpagina de raiz 1' ,'This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don\'t really have to worry about it. It can be useful later on if you\'re trying to...' ,'Pagina' ,'0' ,'2' ,'3' );
      *
      * SELECT count(id) as cant FROM test_a004_pagina_subpages_test_a004_pagina WHERE (test_a004_pagina_subpages_test_a004_pagina.owner_id=2 AND test_a004_pagina_subpages_test_a004_pagina.ref_id=3)
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina_subpages_test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina_subpages_test_a004_pagina ( owner_id ,ref_id ,type ,ord ,class ,deleted ,id ) VALUES ('2' ,'3' ,'2' ,NULL ,'ObjectReference' ,'0' ,'1' );
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina ( titulo ,contenido ,class ,deleted ,owner_id ,id ) VALUES ('Sub subpagina de raiz 2' ,'This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don\'t really have to worry about it. It can be useful later on if you\'re trying to...' ,'Pagina' ,'0' ,'2' ,'4' );
      * 
      * SELECT count(id) as cant FROM test_a004_pagina_subpages_test_a004_pagina WHERE (test_a004_pagina_subpages_test_a004_pagina.owner_id=2 AND test_a004_pagina_subpages_test_a004_pagina.ref_id=4)
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina_subpages_test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina_subpages_test_a004_pagina ( owner_id ,ref_id ,type ,ord ,class ,deleted ,id ) VALUES ('2' ,'4' ,'2' ,NULL ,'ObjectReference' ,'0' ,'2' );
      * 
      * SELECT count(id) as cant FROM test_a004_pagina_subpages_test_a004_pagina WHERE (test_a004_pagina_subpages_test_a004_pagina.owner_id=1 AND test_a004_pagina_subpages_test_a004_pagina.ref_id=2)
      * 
      * SELECT MAX(id) AS max FROM test_a004_pagina_subpages_test_a004_pagina
      * 
      * INSERT INTO test_a004_pagina_subpages_test_a004_pagina ( owner_id ,ref_id ,type ,ord ,class ,deleted ,id ) VALUES ('1' ,'2' ,'2' ,NULL ,'ObjectReference' ,'0' ,'3' );
      * 
      * SELECT id FROM test_a004_pagina WHERE id=2
      * 
      * UPDATE test_a004_pagina SET titulo='Subpagina de raiz 1' ,contenido='This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don\'t really have to worry about it. It can be useful later on if you\'re trying to...' ,class='Pagina' ,deleted='0' ,owner_id='1' WHERE id=2
      * 
      * 
      */
     $p1 = new Pagina(array("titulo" => "Pagina raiz", "contenido" => "This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don't really have to worry about it. It can be useful later on if you're trying to..."));
     $p11 = new Pagina(array("titulo" => "Subpagina de raiz 1", "contenido" => "This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don't really have to worry about it. It can be useful later on if you're trying to...", "owner" => $p1));
     $p111 = new Pagina(array("titulo" => "Sub subpagina de raiz 1", "contenido" => "This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don't really have to worry about it. It can be useful later on if you're trying to...", "owner" => $p11));
     $p112 = new Pagina(array("titulo" => "Sub subpagina de raiz 2", "contenido" => "This step is usually done transparently as most compilers perform it and then invoke the assembler themselves, so you don't really have to worry about it. It can be useful later on if you're trying to...", "owner" => $p11));
     // subpaginas de p11
     $p11->addToSubpages($p111);
     $p11->addToSubpages($p112);
     // subpaginas de p1
     $p1->addToSubpages($p11);
     // Guarda en cascada porque el lado con cardinalidad 1 de la relacion
     // es el responsable del lado con cardinalidad *.
     $this->assert($p1->save(), 'TestCaseA004.test2: Test salvar hasMany en cascada', array('errors' => print_r($p1->getErrors(), true)));
     // TODO: en el test verificar que se guardo todo y que puedo cargar las relaciones ok
 }
コード例 #5
0
 /**
  * Action Página : SAVE
  */
 public function actionSalvarPagina()
 {
     $dadosPost = Yii::app()->request->rawBody;
     $parametros = CJSON::decode($dadosPost, true);
     if (isset($parametros['id']) && $parametros['id'] != '') {
         $pagina = Pagina::model()->findByPk($parametros['id']);
     } else {
         $pagina = new Pagina();
     }
     $pagina->nome = $parametros['nome'];
     $pagina->posicao = $parametros['posicao'];
     $response = array();
     if ($pagina->save() === false) {
         $response['success'] = false;
         $response['errors'] = $pagina->errors;
     } else {
         $response['success'] = true;
         $response['pagina'] = $pagina;
     }
     header('Content-type: application/json; charset=utf-8');
     echo CJSON::encode($response);
     Yii::app()->end();
 }
コード例 #6
0
ファイル: PaginaController.php プロジェクト: Telemedellin/tm
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCrear($id, $tipo_pagina_id = 2)
 {
     if (!isset(Yii::app()->session['dirpa'])) {
         Yii::app()->session['dirpa'] = 'backgrounds/paginas/' . date('Y') . '/' . date('m') . '/';
     }
     $micrositio = $id ? Micrositio::model()->with('seccion')->findByPk($id)->id : 0;
     $model = new Pagina();
     $model->micrositio_id = $micrositio;
     $ppc = TipoPagina::model()->findByPk($tipo_pagina_id)->tabla;
     if (!$ppc) {
         throw new Exception(400, "tipo_pagina_id incorrecto");
     }
     $contenido = new $ppc();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Pagina'])) {
         $model->attributes = $_POST['Pagina'];
         $m = Micrositio::model()->with('seccion')->findByPk($_POST['Pagina']['micrositio_id']);
         $model->tipo_pagina_id = $tipo_pagina_id;
         if (isset(Yii::app()->session['dirpa'])) {
             $dirpa = Yii::app()->session['dirpa'];
         }
         $model->background = $_POST['Pagina']['background'] != '' ? $dirpa . $_POST['Pagina']['background'] : NULL;
         $model->background_mobile = $_POST['Pagina']['background_mobile'] != '' ? $dirpa . $_POST['Pagina']['background_mobile'] : NULL;
         $model->miniatura = $_POST['Pagina']['miniatura'] ? $dirpa . $_POST['Pagina']['miniatura'] : NULL;
         if ($model->save()) {
             if (isset($_POST['PgGenericaSt'])) {
                 $contenido->texto = $_POST['PgGenericaSt']['texto'];
             }
             if (isset($_POST['PgArticuloBlog'])) {
                 $contenido->posicion = $_POST['PgArticuloBlog']['posicion'];
                 $contenido->entradilla = $_POST['PgArticuloBlog']['entradilla'];
                 $contenido->texto = $_POST['PgArticuloBlog']['texto'];
                 $contenido->enlace = $_POST['PgArticuloBlog']['enlace'];
                 $contenido->comentarios = $_POST['PgArticuloBlog']['comentarios'];
             }
             if (isset($_POST['PgDocumental'])) {
                 $contenido = PgDocumental::model()->findByPk($_POST['PgDocumental']['id']);
                 $contenido->titulo = $_POST['PgDocumental']['titulo'];
                 $contenido->duracion = $_POST['PgDocumental']['duracion'];
                 $contenido->anio = $_POST['PgDocumental']['anio'];
                 $contenido->sinopsis = $_POST['PgDocumental']['sinopsis'];
             }
             if (isset($_POST['PgFiltro'])) {
                 $contenido->descripcion = $_POST['PgFiltro']['descripcion'];
             }
             if (isset($_POST['PgBloques'])) {
             }
             if (isset($_POST['PgEventos'])) {
                 $contenido->descripcion = $_POST['PgEventos']['descripcion'];
             }
             if (isset($_POST['PgBlog'])) {
                 $contenido->ver_fechas = $_POST['PgBlog']['ver_fechas'];
             }
             if (isset($_POST['PgFormularioJf'])) {
                 $contenido->formulario_id = $_POST['PgFormularioJf']['formulario_id'];
             }
             $contenido->estado = $_POST['Pagina']['estado'];
             $contenido->pagina_id = $model->getPrimaryKey();
             if ($contenido->save()) {
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 $model->delete();
             }
         }
     }
     $this->render('crear', array('model' => $model, 'partial' => $ppc, 'contenido' => $contenido));
 }
コード例 #7
0
ファイル: NovedadesForm.php プロジェクト: Telemedellin/tm
 public function guardar()
 {
     $dir = $this->imageRoute;
     $image_base = Yii::getPathOfAlias('webroot') . '/images/';
     if ($this->validate()) {
         if (isset($this->id)) {
             //Actualizando
             $pagina = Pagina::model()->findByPk($this->id);
         } else {
             //Nuevo registro
             $pagina = new Pagina();
         }
         $transaccion = $pagina->dbConnection->beginTransaction();
         $pagina->micrositio_id = 2;
         //Novedades
         $pagina->tipo_pagina_id = 3;
         //Novedad
         $pagina->nombre = $this->nombre;
         $pagina->clase = NULL;
         $pagina->estado = $this->estado;
         $pagina->destacado = $this->destacado;
         if ($this->imagen != $pagina->background) {
             if (file_exists($image_base . $pagina->background)) {
                 @unlink($image_base . $pagina->background);
             }
             $pagina->background = $dir . $this->imagen;
         }
         if ($this->imagen_mobile != $pagina->background_mobile) {
             if (file_exists($image_base . $pagina->background_mobile)) {
                 @unlink($image_base . $pagina->background_mobile);
             }
             $pagina->background_mobile = $dir . $this->imagen_mobile;
         }
         if ($this->miniatura != $pagina->miniatura) {
             if (file_exists($image_base . $pagina->miniatura)) {
                 @unlink($image_base . $pagina->miniatura);
             }
             $pagina->miniatura = $dir . $this->miniatura;
         }
         if (!$pagina->save(false)) {
             $transaccion->rollback();
         }
         $pagina_id = $pagina->getPrimaryKey();
         if (isset($this->id)) {
             //Actualizando
             $pgAB = PgArticuloBlog::model()->findByAttributes(array('pagina_id' => $pagina_id));
         } else {
             //Nuevo registro
             $pgAB = new PgArticuloBlog();
         }
         $pgAB->pagina_id = $pagina_id;
         $pgAB->entradilla = $this->entradilla;
         $pgAB->texto = $this->texto;
         $pgAB->enlace = $this->enlace;
         $pgAB->comentarios = $this->comentarios;
         $pgAB->posicion = $this->posicion;
         $pgAB->estado = $this->estado ? 1 : 0;
         if (!$pgAB->save(false)) {
             $transaccion->rollback();
             return false;
         } else {
             $transaccion->commit();
             $this->id = $pagina_id;
             return true;
         }
     } else {
         return false;
     }
 }