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');
 }
 public function actionMef($idTestContext)
 {
     $sql = "SELECT COUNT(*) FROM test_context_seq WHERE id_test_context = " . $idTestContext;
     $numSeqs = Yii::app()->db->createCommand($sql)->queryScalar();
     if ($numSeqs > 0) {
         $this->redirect("/mtcontrool/index.php/testContext/inidashboard?idTestContext=" . $idTestContext);
     }
     /*
     ESTA MATRIZ SERÁ PREENCHIDA NESTA FUNÇÃO E ENCAMINHA PARA O ALGORITIMO.
     */
     $matrixElementsInstances = array();
     //AQUI É FEITA UMA BUSCA POR TODOS OS ELEMENTOS CADASTRADOS NO BANCO.
     $elements = Element::model()->findAll();
     $sql_countElements = "SELECT * FROM test_context JOIN element_inst ON (test_context.id = element_inst.id_test_context)  WHERE test_context.id={$idTestContext} GROUP BY id_element";
     $result_countElements = Yii::app()->db->createCommand($sql_countElements)->queryAll();
     $totalElements = 0;
     foreach ($result_countElements as $item) {
         $totalElements = $totalElements + 1;
     }
     /*
     ESTE FOREACH, PERCORRE TODOS OS ELEMENTOS ENCONTRADOS NA BUSCA ACIMA, E PARA CADA
     ELEMENTO, ELE BUSCA TODOS AS INSTANCIAS DE ELEMENTOS QUE ESTÃO RELACIONADAS
     AO ELEMENTO DA VEZ NO FOREACH E AO TESTCONTEXT EM QUESTÃO CUJO SEU ID É REEBIDO NESTA
     FUNÇÃO POR PARÂMETRO.
     */
     foreach ($elements as $item) {
         $instances = ElementInst::model()->FindAllByAttributes(array("id_element" => $item->id, "id_test_context" => $idTestContext));
         if (sizeof($instances) > 0) {
             $matrixElementsInstances[$item->description] = $instances;
         }
     }
     /*
     		A PARTIR DAQUI VOCÊ PODE COMEÇAR A IMPLEMENTAR SEU ALGORÍTIMO.
     */
     # code ....
     /*
     		AQUI É APENAS UM TESTE DE EXIBIÇÃO, PARA QUE VOCÊ VEJA O COMPORTAMENTO DA MATRIZ.
     		AQUI VOCÊ PODE ENTENDER COMO PERCORRER ESTE ARRAY E CONSEGUIR EXTRAI AS INFORMAÇÕES.
     */
     $modelTestContext = TestContext::model()->findByPk($idTestContext);
     $vector = new ArrayObject();
     foreach ($matrixElementsInstances as $key => $element) {
         $vectorHelper = new Vetores();
         $vectorHelper->title = $key;
         foreach ($element as $model) {
             $vectorHelper->putElement($model);
         }
         $vector->append($vectorHelper);
     }
     //GERAR TABELA e XML
     //Inicializa Class Helper passando os vetores para estruturar o xml e a tabela
     $xmlGerator = new Helper($vector);
     $rawData = array();
     //condição que espera um parametro xml na URL
     if (isset($_GET['xml'])) {
         //ElementsParalax() retorna um array com o schema do xml já trabalhado
         $schema = $xmlGerator->ElementsParalax();
         //prepara o xml e inicia o download passando o schema e o título
         $this->BuildXml($schema, $modelTestContext->description);
     } else {
         //ElementsParalaxTable() retorna um array com os objetos já trabalhados contendo todo o modelo passado pelo BD
         $schema = $xmlGerator->ElementsParalaxTable();
         //mostrar para o raphael a construção da tabela
         //
         //inicia a construção da tabela
         $part1 = '<table border="1" style="width:100%">';
         $part2 = $part1 . "<tr><th>Variations</th><th>Behavior</th><th>Screenshots</th></th>";
         $totalTests = 0;
         $partBody = null;
         $contaOrdem = 1;
         foreach ($schema as $row) {
             $variatins = "";
             $behavior = "";
             $screen = "";
             $x = 1;
             foreach ($row as $model) {
                 //print_r($model);
                 //$model é uuma instância de ELEMENT_INST
                 //echo $model->iDELEMENT->DESCRIPTION;
                 $variatins .= $model->iDELEMENT->description . ": " . $model->description;
                 if ($model->element_type == "interval") {
                     $variatins .= " (START = " . $model->start_param . "; END = " . $model->end_param . ")";
                 }
                 $variatins .= "\n";
                 $behavior .= $model->behavior . ", ";
                 if ($model->behavior_screen != "") {
                     $screen .= $model->behavior_screen;
                 }
                 $x++;
             }
             $rowData = array($contaOrdem, $xmlGerator->str_lreplace(",", "", $variatins), "", "");
             $contaOrdem = $contaOrdem + 1;
             array_push($rawData, $rowData);
         }
         $part4 = $part2 . $partBody . "</table>";
     }
     /*
     ARQUI SERÁ A CHAMADA PARA A FUNÇÃO QUE MONTARA O XML.
     */
     $nomePlataforma = Platforms::model()->findByPk($modelTestContext->id_platform);
     $nomeApp = App::model()->findByPk($modelTestContext->id_app);
     $device = Device::model()->findByPk($modelTestContext->id_device);
     $user = Users::model()->findByPk($modelTestContext->id_user);
     $jsonPrint = json_encode($rawData);
     $dados_dashboard = array('model' => $modelTestContext, 'totalElements' => $totalElements, 'totalTests' => $totalTests, 'table' => $part4, 'nomeApp' => $nomeApp->name, 'nomePlataforma' => $nomePlataforma->name, 'dados' => $rawData, 'device' => $device, 'Image' => $nomePlataforma->image, 'json' => $jsonPrint, 'user' => $user->name);
     Yii::app()->user->setState('id_test_context', $idTestContext);
     Yii::app()->user->setState('sequencias_geradas', $rawData);
     Yii::app()->user->setState('dados_dashboard', $dados_dashboard);
     $this->redirect('/mtcontrool/index.php/testContextSeq/create');
 }
    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <div>
        
        <?php 
$j = 0;
$tamanho = sizeof($arrayModels);
$anterior = "";
$proximo = "";
?>
        <?php 
for ($i = 0; $i < $tamanho; $i++) {
    ?>
            <?php 
    $name = Element::model()->findByPK($arrayModels[$i]->id_element);
    ?>
            <?php 
    if ($name->description != $anterior) {
        ?>
                <p class="labelCapiroto"><?php 
        echo $name->description . "  (" . $arrayModels[$i]->element_type . ")";
        ?>
</p>

                <table class="table_do_capiroto">
            <?php 
    }
    ?>
                    <?php 
    echo $form->errorSummary($arrayModels[$i]);
 public function getElement($id)
 {
     return Element::model()->findByPk($id);
 }
Exemplo n.º 5
0
 public function reorder()
 {
     $elements = Element::model()->findAll("stepId = {$this->stepId} AND position > {$this->position}");
     if ($elements) {
         foreach ($elements as $element) {
             $element->position--;
             $element->save();
         }
     }
 }
Exemplo n.º 6
0
    <?php 
    echo $form->errorSummary($model);
    ?>
            <tr>
            <!--<td><input class="input" type="checkbox" name="option" value="estado" unchecked onchange="valida()" id='chk<?php 
    //echo "[$i]";
    ?>
' /> </td>-->
            <td><input type="checkbox" name="option" value="estado" unchecked onchange="valida($(this).parent().parent())" id='chk<?php 
    echo "[{$i}]";
    ?>
' /> </td>
            <td> 
            <?php 
    $name = Element::model()->findByPK($model->ID_ELEMENT);
    echo "<b>" . $name->DESCRIPTION . "<b/>";
    ?>
</td> 
            
            <td><?php 
    echo $form->dropDownListControlGroup($model, "[{$i}]ELEMENT_TYPE", $arrayElementType, array('id' => "type_field[{$i}]", 'empty' => '--- Choose a type ---', 'onchange' => "Hab({$i})"));
    ?>
</td>
            <!-- <td><?php 
    echo $form->textFieldControlGroup($model, "[{$i}]ID_ELEMENT", array('id' => "id_element_field[{$i}]", 'span' => 5));
    ?>
</td>

            <td><?php 
    echo $form->textFieldControlGroup($model, "[{$i}]ID_TEST_CONTEXT", array('id' => "id_test_context_field[{$i}]", 'span' => 5));
 public function actionUpdate1()
 {
     //SEGUNDA TELA NO UPDATE DE UM TEST CONTEXT
     //VERIFICA SE EXISTEM ELEMENTOS QUE AINDA NÃO FORAM USADOS.
     //CASO NÃO EXISTAM MAIS ELEMENTOS DISPONÍVEIS, ELE REDIRECIONA AUTOMATICAMNETE PARA A TERCEIRA TELA.
     $idTestContext = Yii::app()->user->getState('idTestContext');
     $idDevice = Yii::app()->user->getState('idDevice');
     //BOTÃO CANCELAR
     if (isset($_POST['buttonCancel'])) {
         $this->redirect("/mtcontrool/index.php/testContext/admin");
     }
     $arrayModels = ElementInst::model()->findAll('id_test_context=' . $idTestContext);
     $arrayTypes = array();
     foreach ($arrayModels as $item) {
         $item->sent = $item->behavior_screen;
         $arrayTypes[$item->id_element] = $item->element_type;
     }
     //FUNÇÃO CALLBACK DE ORDENAÇÃO.
     function order($a, $b)
     {
         $retval = strnatcmp($a['id_element'], $b['id_element']);
         if (!$retval) {
             return strnatcmp($b['description'], $a['description']);
         }
         return $retval;
     }
     //VERIFICA QUAIS ELEMENTOS ESTÃO ASSICIADOS AO DEVIDE.
     //E CRIA UM NOVO FORM PARA CADA UM DESSES ELEMENTOS
     //ISSO PERMITIRÁ QUE NOVAS INSTANCIA DE ELEMENTOS SEJAM CRIADAS.
     $arrayExclude = array();
     $flag = 0;
     $exclude = null;
     $elements = new Element();
     $elements = Element::model()->with('elementDevices')->findAll('ID_DEVICE=' . $idDevice);
     if (sizeof($arrayModels) > 0) {
         //$elements=Element::model()->with('elementDevices')->findAll('ID_DEVICE=' . $idDevice);
         foreach ($elements as $i => $element) {
             $model = new ElementInst();
             $model->id_element = $element->id;
             $model->id_test_context = $idTestContext;
             foreach ($arrayTypes as $key => $value) {
                 if ($model->id_element == $key) {
                     $model->element_type = $value;
                 }
             }
             if ($model->element_type != '') {
                 array_push($arrayExclude, $element->id);
             } else {
                 $flag = 1;
             }
             array_push($arrayModels, $model);
         }
         //ORDENA O ARRAY DE MODELOS DE FORMA QUE OS MODELOS NÃO PREENCHIDOS FIQUEM POR ULTIMO.
         usort($arrayModels, 'order');
         $exclude = json_encode($arrayExclude);
         if (sizeof($arrayExclude) > 0 and $flag == 1) {
             //$this->redirect(Yii::app()->createUrl("/elementInst/create", array("idTestContext"=>$idTestContext,"idDevice"=>$idDevice,"exclude"=>$arrayExclude)));
         }
     } else {
         //$this->redirect(Yii::app()->createUrl("/elementInst/create", array("idTestContext"=>$idTestContext,"idDevice"=>$idDevice)));
     }
     $arrayExcluded = array();
     if ($exclude != null) {
         $exclude = json_decode($exclude);
         foreach ($elements as $key => $item) {
             foreach ($exclude as $value) {
                 if ($item->id == $value) {
                     array_push($arrayExcluded, $elements[$key]);
                     unset($elements[$key]);
                 }
             }
         }
         $elements = array_values($elements);
     }
     $listElements = CHtml::listData($elements, 'id', 'description');
     $dataProvider = new CActiveDataProvider('Element');
     $dataProvider->setData($elements);
     //ORDENA O ARRAY DE MODELOS DE FORMA QUE OS MODELOS NÃO PREENCHIDOS FIQUEM POR ULTIMO.
     usort($arrayModels, 'order');
     $count_elements = 0;
     foreach (array_keys($_POST) as $key) {
         if (strpos($key, "ElementInst") === 0) {
             //Key matches, test value.
             $count_elements++;
         }
     }
     //SALVA OS DADOS NO BANCO DE DADOS
     $count_saved = 0;
     if ($count_elements > 0) {
         foreach ($arrayModels as $key => $model) {
             if (isset($_POST["description" . $key])) {
                 if (trim($_POST["description" . $key]) != "") {
                     $model->description = $_POST["description" . $key];
                     if ($model->element_type == "interval") {
                         $model->start_param = $_POST["start_param" . $key];
                         $model->end_param = $_POST["end_param" . $key];
                     }
                     if ($model->save()) {
                         $count_saved++;
                     } else {
                         print_r($model->getErrors());
                     }
                 } else {
                 }
             }
         }
     }
     if (isset($_POST['confirm'])) {
         $totalElements = $_POST['total_elements'];
         $flagSelecionados = 0;
         $i = 0;
         $typeNull = 0;
         $arraySelected = null;
         while ($i < $totalElements) {
             if (isset($_POST['ID_' . $i])) {
                 if ($_POST['type_' . $i] != "") {
                     $arraySelected[$_POST['ID_' . $i]] = $_POST['type_' . $i];
                     $flagSelecionados = 1;
                 } else {
                     $flagSelecionados = 1;
                     $typeNull = 1;
                 }
             }
             $i = $i + 1;
         }
         $json = null;
         if ($arraySelected != null) {
             $json = json_encode($arraySelected);
         }
         //salva dados para a próxima action
         //RENDER DA TERCEIRA TELA APÓS SELECIONAR OS ELEMENTOS.
         Yii::app()->user->setState('json', $json);
         Yii::app()->user->setState('idTestContext', $idTestContext);
         Yii::app()->user->setState('idDevice', $idDevice);
         $this->redirect("/mtcontrool/index.php/elementInst/create2");
     }
     if (sizeof($listElements) == 0) {
         //SE NÃO EXISTEM MAIS ELEMENTOS DISPONIVEIS, REDIRECIONA PARA A TERCEIRA TELA
         Yii::app()->user->setState('json', null);
         Yii::app()->user->setState('idTestContext', $idTestContext);
         Yii::app()->user->setState('idDevice', $idDevice);
         $this->redirect("/mtcontrool/index.php/elementInst/create2");
     } else {
         //PRIMEIRO RENDER AO ABRIR A TELA A PRIMEIRA VEZ
         $this->render('create_pre', array('listElements' => $listElements, 'models' => $elements, 'dataProvider' => $dataProvider, 'arrayExcluded' => $arrayExcluded, 'idTestContext' => $idTestContext));
     }
 }
Exemplo n.º 8
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;
     }
 }
?>
        <?php 
$listRemove = array();
?>
        <?php 
$listOpen = array();
?>
        <?php 
foreach ($arrayModels as $key => $model) {
    ?>
            <input type="hidden" name="ElementInst<?php 
    echo $acc_id;
    ?>
">
            <?php 
    $name = Element::model()->findByPK($model->id_element);
    ?>
            <?php 
    if ($name->description != $anterior) {
        ?>
                <div class="labels">
                    <?php 
        if ($key > 0) {
            ?>
                        <br>
                        <?php 
            $contaLinha = 1;
            ?>
                    <?php 
        }
        ?>
 /**
  * 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 Element the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Element::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 11
0
 public function sortElement($position)
 {
     $i = 1;
     foreach ($position as $id) {
         $element = Element::model()->findByPk($id);
         $element->position = $i;
         $element->save();
         $i++;
     }
 }