예제 #1
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $this->loadModel($id)->delete();
     AttributeDescription::model()->deleteAll('attribute_id=' . $id);
     $Attribute2value = $this->loadAttrToValModel('attribute_id=' . $id);
     foreach ($Attribute2value as $record) {
         Value::model()->deleteAll('value_id=' . $record['value_id']);
         ValueDescription::model()->deleteAll('value_id=' . $record['value_id']);
     }
     Attribute2value::model()->deleteAll('attribute_id=' . $id);
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax']))
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
 }
 public function actionexcelFileOutput14($id, $issueId)
 {
     Yii::import('ext.phpexcel.XPHPExcel');
     $columnCont = 1;
     $rowCont = 1;
     $newsheet = XPHPExcel::createPHPExcel();
     $element = Element::model()->findByPk($id);
     $i = 4;
     $r = 0;
     $resCol = Value::model()->findAll("elementId={$id}  and colonne=1");
     foreach ($element->columns as $colonne) {
         $newsheet->getActiveSheet()->setCellValueByColumnAndRow($columnCont, 1, $colonne->value);
         $i++;
         $columnCont++;
     }
     foreach ($element->rows as $row) {
         $rowCont++;
         $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $rowCont, $row->value);
         for ($index = 0; $index < $columnCont; $index++) {
             $res = $element->getResultTableForExcel($issueId, $id, $index, $r);
             switch ($res) {
                 case "off":
                     $newsheet->getActiveSheet()->setCellValueByColumnAndRow($index + 1, $r + 2, "No");
                     break;
                 case "checked":
                     $newsheet->getActiveSheet()->setCellValueByColumnAndRow($index + 1, $r + 2, "Yes");
                     break;
                 default:
             }
         }
         $r++;
     }
     $newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
     $newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
     $newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
     $newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
     $newsheet->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     header('Content-Disposition: attachment;filename="myfile.xlsx');
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
     $objWriter->save('php://output');
 }
예제 #3
0
 public function actionexcelComp($id, $elementId)
 {
     //issueId and elementId
     $element = Element::model()->findByPk($elementId);
     Yii::import('ext.phpexcel.XPHPExcel');
     $title = Element::model()->findByPk($elementId);
     $newsheet = XPHPExcel::createPHPExcel();
     switch ($element->typeId) {
         case 0:
         case 1:
         case 3:
         case 4:
             $criteria = "elementId={$elementId}";
             $results = Result::model()->findAll($criteria);
             //$results=Result::model()->findAll($title->label);
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Issue ID");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "User");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, 1, "Fill date");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, 1, $title->label);
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
             $cont = 2;
             foreach ($results as $result) {
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $result->issueId);
                 $issue = $this->loadIssue($result->issueId);
                 $user = Element::model()->getUserForExcel($result->issueId, $elementId);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
                 //
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, $cont, Yii::app()->dateFormatter->format("HH:mm d/M/y", $result->createTime));
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, $cont, $result->value);
                 $cont++;
             }
             $traveler = Traveler::model()->findByPk($issue->travelerId);
             if (isset($issue)) {
                 if (strlen($traveler->name) > 28) {
                     $traveler->name = substr($traveler->name, 0, 28);
                 }
                 $newsheet->getActiveSheet()->setTitle($traveler->name);
             }
             //else throw new CHttpException(403, 'There is a problem with the data');
             header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
             header('Content-Disposition: attachment;filename="myfile.xlsx');
             header('Cache-Control: max-age=0');
             //metada:
             $newsheet->getProperties()->setCreator(Yii::app()->user->username);
             $objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
             $objWriter->save('php://output');
             break;
         case 5:
             //devuelve el value de result, que es el id de value!!
             //center 1st column
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             //name first column
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Issue ID");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "User");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, 1, "Fill date");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, 1, $title->label);
             //center data cells
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             //color
             $newsheet->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             //size
             $newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
             $criteria = "elementId={$elementId}";
             $preresults = Result::model()->findAll($criteria);
             $cont = 2;
             foreach ($preresults as $preresult) {
                 $issue = $this->loadIssue($preresult->issueId);
                 $user = Element::model()->getUserForExcel($preresult->issueId, $elementId);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $preresult->issueId);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, $cont, Yii::app()->dateFormatter->format("HH:mm d/M/y", $preresult->createTime));
                 $value = Value::model()->findByPk($preresult->value);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, $cont, $value->value);
                 $cont++;
             }
             if (isset($issue)) {
                 $traveler = Traveler::model()->findByPk($issue->travelerId);
                 $newsheet->getActiveSheet()->setTitle($traveler->name);
             }
             header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
             header('Content-Disposition: attachment;filename="myfile.xlsx');
             header('Cache-Control: max-age=0');
             //metada:
             $newsheet->getProperties()->setCreator(Yii::app()->user->username);
             $objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
             $objWriter->save('php://output');
             break;
         case 6:
         case 7:
             //center 1st column
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
             //name first column
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Issue ID");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "User");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, 1, "Fill date");
             $newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, 1, $title->label);
             //center data cells
             $newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             $newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
             //color
             $newsheet->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             $newsheet->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
             //size
             $newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
             $newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
             //saber numero de issues
             $criteria = new CDbCriteria();
             $criteria->distinct = true;
             $criteria->condition = "elementId=" . $elementId;
             $criteria->select = "issueId";
             $issues = Result::model()->findAll($criteria);
             $contCol = 0;
             $cont = array();
             $cont = 1;
             //looping through results by issues!!!
             foreach ($issues as $issue) {
                 $user = null;
                 $cont++;
                 $results = Result::model()->findAll("elementId={$elementId} and issueId={$issue->issueId}");
                 $contCol = 3;
                 $newest = Date('1970-01-21 00:00:00.0');
                 foreach ($results as $result) {
                     //$user=Element::model()->getUserForExcel7($result->issueId, $elementId, $result->value);
                     //$newsheet->getActiveSheet()->setCellValueByColumnAndRow(1+$userColumn,$cont+1,$user);
                     $date = $result->createTime;
                     if ($date > $newest) {
                         $newest = $date;
                         $user = $result->userId;
                         $user = Element::model()->getUserForExcel($result->issueId, $elementId);
                     }
                     if (!is_numeric($result->value)) {
                         $newsheet->getActiveSheet()->setCellValueByColumnAndRow($contCol, $cont, "NULL");
                         $contCol++;
                         $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $result->issueId);
                     } else {
                         $criteria = "elementId={$elementId} and id={$result->value}";
                         $values = Value::model()->find($criteria);
                         $newsheet->getActiveSheet()->setCellValueByColumnAndRow($contCol, $cont, $values->value);
                         $contCol++;
                         $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $result->issueId);
                     }
                     //else  throw new CHttpException(404, 'There is a problem with the data.');
                     $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
                 }
                 $newest = Yii::app()->dateFormatter->format("HH:mm d/M/y", $newest);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, $cont, $newest);
                 /*
                 					
                 					//esto es para cargar el nombre del traveler en el nombre de la hoja de calculo, no funciona porque no está bien cargado el issue
                 					if(isset($issue)){
                 						$traveler=Traveler::model()->findByPk($issue->travelerId);
                 					
                 						$newsheet->getActiveSheet()->setTitle($traveler->name);
                 					}*/
             }
             if ($contCol <= 26 && $contCol > 0) {
                 $columnLookup = array(1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd', 5 => 'e', 6 => 'f', 7 => 'g', 8 => 'h', 9 => 'i', 10 => 'j', 11 => 'k', 12 => 'l', 13 => 'm', 14 => 'n', 15 => 'o', 16 => 'p', 17 => 'q', 18 => 'r', 19 => 's', 20 => 't', 21 => 'u', 22 => 'v', 23 => 'w', 24 => 'x', 25 => 'y', 26 => 'z');
                 $mergeCells = "d1:" . $columnLookup[$contCol] . "1";
                 $newsheet->setActiveSheetIndex(0)->mergeCells($mergeCells);
             }
             header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
             header('Content-Disposition: attachment;filename="myfile.xlsx');
             header('Cache-Control: max-age=0');
             //metada:
             $newsheet->getProperties()->setCreator(Yii::app()->user->username);
             $objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
             $objWriter->save('php://output');
             break;
         case 13:
         case 14:
             $criteria = new CDbCriteria();
             $criteria->distinct = true;
             $criteria->condition = "elementId=" . $elementId;
             $criteria->select = "issueId";
             $issues = Result::model()->findAll($criteria);
             $sheetNumber = 0;
             foreach ($issues as $issue) {
                 $myWorkSheet = new PHPExcel_Worksheet($newsheet, $issue->issueId);
                 $newsheet->addSheet($myWorkSheet);
                 $newsheet->setActiveSheetIndex($sheetNumber + 1);
                 $sheetNumber++;
                 $criteria = "elementId={$elementId}";
                 $results = Result::model()->findAll($criteria);
                 $cont = 1;
                 $contCol = 0;
                 $columnCont = 1;
                 $rowCont = 1;
                 $element = Element::model()->findByPk($elementId);
                 $i = 4;
                 $r = 0;
                 $resCol = Value::model()->findAll("elementId={$elementId}  and colonne=1");
                 foreach ($element->columns as $colonne) {
                     $newsheet->getActiveSheet()->setCellValueByColumnAndRow($columnCont, 1, $colonne->value);
                     $i++;
                     $columnCont++;
                 }
                 foreach ($element->rows as $row) {
                     $rowCont++;
                     $newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $rowCont, $row->value);
                     for ($index = 0; $index < $columnCont; $index++) {
                         $res = $element->getResultTableForExcel($issue->issueId, $elementId, $index, $r);
                         switch ($res) {
                             case "off":
                                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow($index + 1, $r + 2, "No");
                                 break;
                             case "checked":
                                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow($index + 1, $r + 2, "Yes");
                                 break;
                             default:
                                 $newsheet->getActiveSheet()->setCellValueByColumnAndRow($index + 1, $r + 2, $res);
                         }
                     }
                     $r++;
                 }
                 $newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
                 $newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
                 $newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
                 $newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
                 $newsheet->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
             }
             header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml0sheet');
             header('Content-Disposition: attachment;filename="myfile.xlsx');
             header('Cache-Control: max-age=0');
             $newsheet->removeSheetByIndex(0);
             $objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
             $objWriter->save('php://output');
             break;
     }
 }
예제 #4
0
 public function getUserForBox2($issueId = null)
 {
     //var_dump(empty($resultado));
     //$values = $this->values;
     $resultado = "";
     if (is_null($issueId)) {
         return '';
     }
     $criteria = new CDbCriteria();
     $criteria->condition = "issueId = {$issueId} and elementId = {$this->id}";
     $results = Result::model()->findAll($criteria);
     foreach ($results as $result) {
         $label = Value::model()->findByPk($result->value);
         $resultado .= $label->value . ":    " . $result->user->username . ".  " . $result->dateCreated . "\n";
     }
     return $resultado;
 }
예제 #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Value the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Value::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }