예제 #1
0
 /**
  * Запускаем отрисовку виджета
  *
  * @return void
  */
 public function run()
 {
     // Авторизован ли пользователь
     if (Yii::app()->user->isAuthenticated() === false) {
         return;
     }
     if (($user = Yii::app()->user->getProfile()) === null) {
         return;
     }
     $poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active'), 'questions.variants' => array('scopes' => 'active')))->findByPK((int) $this->model_id);
     if ($poll === null) {
         return;
     }
     // Подгружаем результаты пользователя
     $userId = $user->id;
     if (Yii::app()->user->isSuperUser() && Yii::app()->user->getState('adminUserId') !== null) {
         // Для администратора показываем результаты опроса пользователя в случае подмены
         $viewedUser = User::model()->findByPK((int) Yii::app()->user->getState('adminUserId'));
         if ($viewedUser) {
             $userId = $viewedUser->id;
         }
     }
     $result = Result::model()->with('answers')->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $userId, ':poll_id' => $poll->id));
     $this->render($this->view, array('model' => $poll, 'result' => $result));
 }
 public function actionimportExcelTable($id, $issueId)
 {
     //step id
     if (isset($_FILES['Excel'])) {
         $post = Result::model()->importExcelTable($_FILES['Excel']);
         //throw new CHttpException(403,$_FILES['File']);
         Yii::import('ext.phpexcel.IOFactory');
         Yii::import('ext.phpexcel.*');
         Yii::import('ext.phpexcel.XPHPExcel');
         Yii::import('ext.phpexcel.shared.string');
         $newsheet = XPHPExcel::createPHPExcel();
         //$inputFileName='c:\inetpub\wwwroot\vector2014\protected\extensions\examples\reader\sampledata\book1.xlsx';
         $inputFileName = $post["tmp_name"];
         Result::model()->alsjkd($inputFileName);
         //var_dump($post);
         try {
             $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
         } catch (PHPExcel_Reader_Exception $e) {
             die('Error loading file: ' . $e->getMessage());
         }
         $sheet = $objPHPExcel->getSheet(0);
         $highestRow = $sheet->getHighestRow();
         $highestColumnIndex = $sheet->getHighestColumn();
         $index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
         $highestColumn = $index[$highestColumnIndex];
         $index = array_slice($index, 0, $highestColumn);
         $element = new Element();
         $element->stepId = $id;
         $element->typeId = 13;
         $element->save();
         $elementId = $element->id;
         $step = $this->loadModel($id);
         for ($row = 1; $row <= $highestRow; $row++) {
             $rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
         }
         $columns = array();
         //for ($column =1 ; $column<=$highestColumn; $column++){
         foreach ($index as $key => $position) {
             $columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
         }
         $salida = $step->addGrid($element, $rows, $columns);
         $issue = new Issue();
         //$travelerId= $step->travelerId;
         for ($row = 1; $row <= $highestRow; $row++) {
             foreach ($index as $key => $position) {
                 if ($row >= 1 && $position > 0) {
                     $result = new Result();
                     $result->elementId = $elementId;
                     $result->issueId = $issueId;
                     $result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
                     //throw new CHttpException(403, 'row: '.$row.'. Columna: '.$position.'.Value: '.$result->value);
                     $result->colonne = $position - 1;
                     $result->ligne = $row - 2;
                     $result->save();
                 }
                 //throw new CHttpException (403,"exception: ". $iasdasdeId);
                 //$objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A',$row)->getValue();
             }
         }
         $alsdjk = $LKSJAD;
     } else {
         $alsdjk = $LKSJAD;
         throw new CHttpException(403, "Error in the file");
     }
 }
예제 #3
0
 /**
  * Получение кода для нового результата
  *
  * @param string $attributeCode
  *
  * @return string
  */
 public function getResultCode($attributeCode)
 {
     $index = 1;
     $code = Result::model()->find(array('select' => 't.code', 'condition' > 't.code LIKE ":code-%%"', 'params' => array(':code' => $attributeCode), 'sort' => 't.id DESC'));
     if ($code) {
         $tempArr = explode('-', $code);
         $index = (int) $tempArr[1] + 1;
     }
     return $attributeCode . '-' . $index;
 }
 /**
  * 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 Result the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Result::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #5
0
 public function actionSave($id)
 {
     // Получаем куки для опроса
     /*
             define('COOKIE_NAME', 'poll_genplanmos_ru');
             $isCookie = isset(Yii::app()->request->cookies[COOKIE_NAME]->value);
             
             $pollCookie = $isCookie ? 
            Yii::app()->request->cookies[COOKIE_NAME] :  
            new CHttpCookie(COOKIE_NAME, ''); 
            
             $pollCookieValue = $isCookie? CJSON::decode($pollCookie->value) : array();
     * 
     */
     // Авторизован ли пользователь
     if (Yii::app()->user->isAuthenticated() === false) {
         $this->redirect(Yii::app()->user->loginUrl);
     }
     if (($user = Yii::app()->user->getProfile()) === null) {
         Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
         Yii::app()->user->logout();
         $this->redirect((array) '/user/account/login');
     }
     $poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active')))->findByPK((int) $id);
     if (!$poll) {
         throw new CHttpException(404, Yii::t('PollModule.poll', 'Страница не найдена'));
     }
     // Поиск результата
     $result = Result::model()->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $user->id, ':poll_id' => $poll->id));
     if ($result !== null) {
         throw new CHttpException(403, Yii::t('PollModule.poll', 'Вы уже проходили данный опрос'));
     }
     $result = new Result();
     $result->user_id = $user->id;
     $result->poll_id = $poll->id;
     // Обработка результата
     if (($data = Yii::app()->getRequest()->getPost('question')) !== null) {
         // Формирование списка ответов
         $answers = array();
         foreach ($poll->questions as $question) {
             $formValue = isset($data[$question->id]) ? $data[$question->id] : null;
             switch ($question->type) {
                 case Question::TYPE_VARIANT:
                     $answer = new Answer();
                     $answer->question_id = $question->id;
                     $answer->variant_id = $formValue !== null ? (int) $formValue : $formValue;
                     $answers[] = $answer;
                     break;
                 case Question::TYPE_MULTIPLE:
                     // Просматриваем полученные ответы
                     if (!isset($formValue) || !is_array($formValue)) {
                         break;
                     }
                     foreach ($formValue as $value) {
                         $answer = new Answer();
                         $answer->question_id = $question->id;
                         $answer->variant_id = (int) $value;
                         $answers[] = $answer;
                     }
                     break;
                 default:
                     $answer = new Answer();
                     $answer->question_id = $question->id;
                     $answer->value = $formValue !== null ? $formValue : '';
                     $answers[] = $answer;
                     break;
             }
             $result->answers = $answers;
         }
         if ($result->validate()) {
             $result->save();
             Yii::app()->ajax->success(array('html' => $this->widget('application.modules.poll.widgets.PollWidget', array('model_id' => $poll->id), true)));
         } else {
             Yii::app()->ajax->failure(array('message' => '', 'errors' => $result->getErrors()));
         }
     }
 }
 /**
  * Poll results.
  *
  * @return void
  */
 public function actionResults($id, $format = null)
 {
     $model = $this->loadModel($id);
     $results = Result::model()->with(array('answers', 'user', 'user.profile'))->findAll('t.poll_id = :poll_id', array(':poll_id' => $id));
     $this->render('results', array('model' => $model, 'results' => $results));
 }
예제 #7
0
 /**
  * Метод перед удалением:
  * 
  * @return void
  */
 public function beforeDelete()
 {
     if (User::model()->admin()->count() === 1 && $this->_oldRole === User::getSuperuserRole()) {
         $this->addError('role', Yii::t('UserModule.user', 'You can\'t make this changes!'));
         return false;
     }
     // убираем связь удаленного пользователя с ролью
     //$auth = Yii::app()->authManager;
     //$auth->revoke($this->role, $this->id);
     //$auth->save();
     // Удаляем токены
     foreach ($this->tokens as $token) {
         $token->delete();
     }
     // Обнуляем связанные элементы обратной связи
     Yii::import("application.modules.feedback.models.Feedback");
     foreach (Feedback::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
         $item->user_id = null;
         $item->save(false, array('user_id'));
     }
     // Обнуляем связанные подписки
     Yii::import("application.modules.subscription.models.Subscription");
     foreach (Subscription::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
         $item->user_id = null;
         $item->save(false, array('user_id'));
     }
     // Обнуляем связанные результаты голосования
     Yii::import("application.modules.poll.models.*");
     foreach (Result::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
         $item->user_id = null;
         $item->save(false, array('user_id'));
     }
     // Удаляем интересные мысли пользователя
     Yii::import("application.modules.classroom.models.Quote");
     Quote::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Удаляем последние прочитанные страницы пользователя
     Yii::import("application.modules.classroom.models.LastReadPage");
     LastReadPage::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Удаляем настройки пользователя
     foreach (yupe\models\Settings::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
         $item->delete();
     }
     // Удаляем профиль
     $this->profile->delete();
     return parent::beforeDelete();
 }
예제 #8
0
 public function doesExist($elementId, $issueId, $value)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "issueId = {$issueId} and elementId = {$elementId} and value like '{$value}'";
     $modelo = Result::model()->count($criteria);
     return $modelo;
     /*
     		if($modelo) return false;
     		else return true;*/
 }
 public function actionimportExcelTable($id, $issueId)
 {
     //step id
     if (isset($_FILES['Excel'])) {
         $post = Result::model()->importExcelTable($_FILES['Excel']);
         //var_dump($post);
         Yii::import('ext.phpexcel.IOFactory');
         Yii::import('ext.phpexcel.*');
         Yii::import('ext.phpexcel.XPHPExcel');
         Yii::import('ext.phpexcel.shared.string');
         $newsheet = XPHPExcel::createPHPExcel();
         $inputFileName = $post;
         try {
             $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
         } catch (PHPExcel_Reader_Exception $e) {
             die('Error loadinng file: ' . $post);
             //$e->getMessage());
         }
         $sheet = $objPHPExcel->getSheet(0);
         $highestRow = $sheet->getHighestRow();
         $highestColumnIndex = $sheet->getHighestColumn();
         $index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
         $highestColumn = $index[$highestColumnIndex];
         $index = array_slice($index, 0, $highestColumn);
         $element = new Element();
         $element->stepId = $id;
         $element->typeId = 13;
         $element->save();
         $elementId = $element->id;
         $step = $this->loadModel($id);
         for ($row = 1; $row <= $highestRow; $row++) {
             $rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
         }
         $columns = array();
         foreach ($index as $key => $position) {
             $columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
         }
         //$salida=$step->addGrid($element, $rows, $columns);
         $issue = new Issue();
         for ($row = 1; $row <= $highestRow; $row++) {
             foreach ($index as $key => $position) {
                 if ($row >= 1 && $position > 0) {
                     $result = new Result();
                     $result->elementId = $elementId;
                     $result->issueId = $issueId;
                     $result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
                     $result->colonne = $position - 1;
                     $result->ligne = $row - 2;
                     throw new CHttpException(403, 'row: ' . $result->ligne . '. Columna: ' . $result->colonne . '.Value: ' . $result->value);
                     $result->save();
                 }
             }
         }
         //$this->redirect(array('view','id'=>$id));
     } else {
         throw new CHttpException(403, "Failure loading file");
     }
 }
예제 #10
0
 public function setTableOFF($id)
 {
     $results = Result::model()->with('element')->findAll("issueId = {$id} and typeId IN(13,14)");
     foreach ($results as $result) {
         $result->value = "off";
         $result->save();
     }
 }
예제 #11
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;
     }
 }
예제 #12
0
 protected function beforeDelete()
 {
     foreach (Nonconformity::model()->findAll("issueId = {$this->id}") as $discrepancy) {
         $discrepancy->delete();
     }
     foreach (Comment::model()->findAll("issueId = {$this->id}") as $comment) {
         $comment->delete();
     }
     foreach (Result::model()->findAll("issueId = {$this->id}") as $result) {
         $result->delete();
     }
     return parent::beforeDelete();
 }