MzgtpublicacionesController.php 5.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
<?php

class MzgtpublicacionesController extends GxController {

	public function actionView($id) {
		$this->render('view', array(
			'model' => $this->loadModel($id, 'Mzgtpublicaciones'),
		));
	}

	public function actionCreate() {
		$model = new Mzgtpublicaciones;
                $basedatosindexada = new Mzgtbasesdatosindexada;
                
                if (isset($_POST['Mzgtbasesdatosindexada'])) {
			$basedatosindexada->setAttributes($_POST['Mzgtbasesdatosindexada']);
                        if ($basedatosindexada->save()) 
                                $PK_MZGTBASESDATOSINDEXADA = $basedatosindexada->PK_MZGTBASESDATOSINDEXADA;
                        else
                                $PK_MZGTBASESDATOSINDEXADA = null;
                }
                
                //Registro de datos de publicaciones
                if (isset($_POST['Mzgtpublicaciones'])) {
                    $model->setAttributes($_POST['Mzgtpublicaciones']);
                    $relatedData = array(
                            'mzgtbancoautores' => isset($_POST['Mzgtpublicaciones']['mzgtbancoautores']) ? $_POST['Mzgtpublicaciones']['mzgtbancoautores'] : null,
                            );
                    
                    if(isset($PK_MZGTBASESDATOSINDEXADA))
                        $model->FK5_MZGTPUBLICACIONES_INV_MZGTBASESDATOSINDEXADA_PK = $PK_MZGTBASESDATOSINDEXADA;
                    
                    if ($model->saveWithRelated($relatedData)) {
                        if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                            Yii::app()->end();
                        } else {
                            $this->redirect(array('view', 'id' => $model->PK_MZGTPUBLICACIONES));
                        }
                    }
                }
                
                
		$this->render('create', array('model' => $model, 'bdindexada' => $basedatosindexada));
	}
        
	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'Mzgtpublicaciones');
                $basedatosindexada = new Mzgtbasesdatosindexada;
                
                //Verifico se está enviado datos de base de datos indexada
                if (isset($_POST['Mzgtbasesdatosindexada'])&&($_POST['Mzgtbasesdatosindexada']['MZGTBASESDATOSINDEXADA_DESCRIPCION']!='')) {
			$basedatosindexada->setAttributes($_POST['Mzgtbasesdatosindexada']);
                        //Primero se guardan los datos de la nueva base de datos indexada
			if ($basedatosindexada->save()) {
                            //Guardar datos de publicacion
                            if (isset($_POST['Mzgtpublicaciones'])) {
                                    $model->setAttributes($_POST['Mzgtpublicaciones']);
                                    $model->FK5_MZGTPUBLICACIONES_INV_MZGTBASESDATOSINDEXADA_PK = $basedatosindexada->PK_MZGTBASESDATOSINDEXADA;
                                    $relatedData = array(
                                            'mzgtbancoautores' => isset($_POST['Mzgtpublicaciones']['mzgtbancoautores']) ? $_POST['Mzgtpublicaciones']['mzgtbancoautores'] : null,
                                            );

                                    if ($model->saveWithRelated($relatedData)) {
                                            $this->redirect(array('view', 'id' => $model->PK_MZGTPUBLICACIONES));
                                    }
                            }
                        }
                }else{
                    //Guardar datos de publicacion
                    if (isset($_POST['Mzgtpublicaciones'])) {
			$model->setAttributes($_POST['Mzgtpublicaciones']);
			$relatedData = array(
				'mzgtbancoautores' => isset($_POST['Mzgtpublicaciones']['mzgtbancoautores']) ? $_POST['Mzgtpublicaciones']['mzgtbancoautores'] : null,
				);
                        
			if ($model->saveWithRelated($relatedData)) {
                            if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                                Yii::app()->end();
                            } else {
                                $this->redirect(array('view', 'id' => $model->PK_MZGTPUBLICACIONES));
                            }
                        }
                    }
                }
                
		$this->render('update', array(
				'model' => $model,
                                'bdindexada' => $basedatosindexada,
				));
	}

	public function actionDelete($id) {
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'Mzgtpublicaciones')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin'));
		} else
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
	}

	public function actionIndex() {
		$dataProvider = new CActiveDataProvider('Mzgtpublicaciones');
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin() {
		$model = new Mzgtpublicaciones('search');
		$model->unsetAttributes();

		if (isset($_GET['Mzgtpublicaciones'])) {
                    $model->setAttributes($_GET['Mzgtpublicaciones']);}

                $this->render('admin', ['model' => $model,]);
	}
        
        public function actionUpload() {
            Yii::import("ext.EAjaxUpload.qqFileUploader");
            
            $folder = 'protected/uploads/publicaciones/'; // folder for uploaded files
            $path = Yii::app()->getBasePath()."\uploads\publicaciones\\";
            $allowedExtensions = array("pdf"); //array("jpg","jpeg","gif","exe","mov" and etc...
            $sizeLimit = 10 * 1024 * 1024; // maximum file size in bytes
            $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
            $result = $uploader->handleUpload($folder,FALSE,$path);
            
            $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);

            //$fileSize = filesize($folder . $result['filename']); //GETTING FILE SIZE
            //$fileName = $result['filename']; //GETTING FILE NAME

            
            echo $return; // it's array 
        }
        
}