public function actionExport($id)
 {
     $filepath = dirname(__FILE__) . '/../runtime/result.docx';
     $template_filepath = dirname(__FILE__) . '/../runtime/templates/Template.docx';
     if (file_exists($template_filepath)) {
         $resource = Resource::findOne($id);
         $filename = $resource->name . '.docx';
         $coordinates = json_decode($resource->coordinates);
         $owner = PersonalData::findOne($resource->owner_data_id);
         $owner_name = $owner->last_name . ' ' . $owner->first_name . ' ' . $owner->middle_name;
         $resource_class = ResourceClass::findOne($resource->class_id)->name;
         $parameters = Parameter::find()->where(['resource_id' => $id])->all();
         $attributes = [];
         foreach ($parameters as $parameter) {
             $parameter_name = ResourceAttribute::findOne($parameter->attribute_id);
             $attributes[$parameter_name->name] = $parameter->value;
         }
         $linear_size = $attributes['length'];
         if ($attributes['width']) {
             $linear_size .= ':' . $attributes['width'];
         }
         if ($attributes['height']) {
             $linear_size .= ':' . $attributes['height'];
         }
         \PhpOffice\PhpWord\Autoloader::register();
         $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template_filepath);
         // Template processing
         $templateProcessor->setValue('name', htmlspecialchars($resource->name, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('class', htmlspecialchars($resource_class, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('subclass', htmlspecialchars($subclass, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('owner', htmlspecialchars($owner_name, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('linear_size', htmlspecialchars($linear_size, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('area', htmlspecialchars($attributes['square'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('weight', htmlspecialchars($attributes['weight'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('perimeter', htmlspecialchars($attributes['perimeter'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('volume', htmlspecialchars($attributes['volume'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('reason', htmlspecialchars($reason, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar_address', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registration_number', htmlspecialchars($registration_number, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registration_date', htmlspecialchars($creation_date, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar_shortname', htmlspecialchars($registrar_short_name, ENT_COMPAT, 'UTF-8'));
         for ($i = 1; $i <= 20; $i++) {
             $lat = "";
             $lng = "";
             if (count($coordinates) >= $i) {
                 $lat = $coordinates[$i - 1][0];
                 $lng = $coordinates[$i - 1][1];
             }
             $templateProcessor->setValue('lat#' . $i, htmlspecialchars($lat, ENT_COMPAT, 'UTF-8'));
             $templateProcessor->setValue('lng#' . $i, htmlspecialchars($lng, ENT_COMPAT, 'UTF-8'));
         }
         // Saving the document as OOXML file...
         $templateProcessor->saveAs($filepath);
         if (file_exists($filepath)) {
             return \Yii::$app->response->sendFile($filepath, $filename, ['inline' => false])->send();
         }
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Parameter::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['parameter_id' => $this->parameter_id, 'parameter_name_fk' => $this->parameter_name_fk]);
     $query->andFilterWhere(['like', 'parameter_value', $this->parameter_value]);
     return $dataProvider;
 }
 public function actionExport($id)
 {
     $templateFilepath = dirname(__FILE__) . '/../runtime/templates/Template2.docx';
     $source = dirname(__FILE__) . '/../runtime/temp.docx';
     \PhpOffice\PhpWord\Autoloader::register();
     $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($templateFilepath);
     $months = ['Січня', 'Лютого', 'Березня', 'Квітня', 'Травня', 'Червня', 'Липня', 'Серпня', 'Вересня', 'Жовтня', 'Листопада', 'Грудня'];
     $date = getdate();
     $currentDate = $date['mday'] . ' ' . $months[$date['mon'] - 1] . ' ' . $date['year'] . ' року';
     $extractNumber = '№' . $date['mday'] . ($date['mon'] - 1) . substr($date['year'], -2);
     $templateProcessor->setValue('date', $currentDate);
     $templateProcessor->setValue('number', $extractNumber);
     $templateProcessor->saveAs($source);
     $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
     //$phpWord = new \PhpOffice\PhpWord\PhpWord();
     $phpWord->setDefaultFontName('Times New Roman');
     $phpWord->setDefaultFontSize(11);
     $sectionStyle = ['marginTop' => 1000];
     $tableStyle = ['borderSize' => 6, 'borderColor' => '000', 'cellMargin' => 0];
     $innerTableStyle = ['cellMargin' => 20];
     $boldFontStyle = ['bold' => true];
     $italicFontStyle = ['italic' => true];
     $styleCell = ['valign' => 'center'];
     $styleCellBTLR = ['valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR];
     $innerTableCellStyle = ['borderRightSize' => 6, 'borderRightColor' => '000', 'borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000'];
     $innerTableRightCellStyle = ['borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000'];
     $innerTableFontStyle = ['size' => 9];
     $innerTableParagraphStyle = ['align' => 'center'];
     // Get resource data
     $resource = Resource::findOne($id);
     $filename = $resource->name . '.docx';
     $coordinates = json_decode($resource->coordinates);
     $owner_name = 'народ України (Український народ)';
     $resource_class = 'природний ресурс';
     $resource_subclass = ResourceClass::findOne($resource->class_id)->name;
     $creation_date = $resource->date;
     $registrar = PersonalData::findOne($resource->registrar_data_id);
     $registrar_info = $registrar->last_name . ' ' . $registrar->first_name . ' ' . $registrar->middle_name . ' ' . $registrar->address;
     $registrar_shortname = $registrar->last_name . $registrar->first_name[0] . '. ' . $registrar->middle_name[0] . '.';
     $parameters = Parameter::find()->where(['resource_id' => $id])->all();
     $attributes = [];
     foreach ($parameters as $parameter) {
         $parameter_name = ResourceAttribute::findOne($parameter->attribute_id);
         $attributes[$parameter_name->name] = $parameter->value;
     }
     $length = $attributes['length'];
     $width = $attributes['width'];
     $height = $attributes['height'];
     if ($length || $width || $height) {
         if (!$length) {
             $length = '0';
         }
         if (!$width) {
             $width = '0';
         }
         if (!$height) {
             $height = '0';
         }
         $attributes['linear_size'] = $length . ':' . $width . ':' . $height;
     }
     $reason = $resource->reason;
     function formatCoords($num)
     {
         $num = round($num, 4, PHP_ROUND_HALF_DOWN);
         $degrees = floor($num);
         $minfloat = ($num - $degrees) * 60;
         $minutes = floor($minfloat);
         $secfloat = ($minfloat - $minutes) * 60;
         $seconds = round($secfloat);
         if ($seconds == 60) {
             $minutes++;
             $seconds = 0;
         }
         if ($minutes == 60) {
             $degrees++;
             $minutes = 0;
         }
         return (string) $degrees . '°' . (string) $minutes . '\'' . (string) $seconds . '"';
     }
     $tableFields = ['Найменування об’єкту' => $resource->name, 'Клас об’єкту' => $resource_class, 'Підклас об’єкту' => $resource_subclass, 'Власник об’єкту' => $owner_name, 'Географічні координати кутів (вершин) об’єкту у форматі ГГ°ММ\'СС,СС". ' => $coordinates, 'Лінійні розміри об’єкту, Д:Ш:В, м' => $attributes['linear_size'], 'Загальна площа об’єкту, га' => $attributes['square'] / 10000, 'Маса (вага) об’єкту, кг' => $attributes['weight'], 'Периметр об’єкту, м' => $attributes['perimeter'], 'Об’єм об’єкту, м3' => $attributes['volume'], 'Підстава для внесення відомостей до Реєстру' => $reason, 'ПІБ та поштова адреса народного реєстратора' => $registrar_info, 'Реєстраційний номер об’єкту' => $registration_number, 'Дата створення запису' => $creation_date];
     $tableUnitalicFields = ['Клас об’єкту', 'Власник об’єкту'];
     $sections = $phpWord->getSections();
     $section = $sections[0];
     $phpWord->addTableStyle('Resource Table', $tableStyle);
     $table = $section->addTable('Resource Table');
     foreach ($tableFields as $key => $value) {
         if ($value) {
             if (!is_array($value)) {
                 $valueFontStyle = [];
                 if (in_array($key, $tableUnitalicFields)) {
                     $valueFontStyle = $italicFontStyle;
                 }
                 $table->addRow(200);
                 $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle);
                 $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(15))->addText(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'), $valueFontStyle);
             } else {
                 $row = $table->addRow();
                 $row->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle);
                 $cell = $row->addCell();
                 $innerTable = $cell->addTable($innerTableStyle);
                 $innerTable->addRow(10);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Північна широта', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Східна довгота', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars("Північна широта \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars("Східна довгота \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $coordinatesNumber = count($coordinates);
                 for ($i = 1; $i <= round($coordinatesNumber / 2); $i++) {
                     $lat = '';
                     $lng = '';
                     $latCont = '';
                     $lngCont = '';
                     if ($coordinatesNumber >= $i) {
                         $lat = formatCoords($coordinates[$i - 1][0]);
                         $lng = formatCoords($coordinates[$i - 1][1]);
                     }
                     if ($coordinatesNumber >= round($coordinatesNumber / 2) + $i) {
                         $latCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][0]);
                         $lngCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][1]);
                     }
                     $innerTable->addRow(10);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lat, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lng, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($latCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars($lngCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                 }
             }
         }
     }
     $section->addTextBreak(2);
     $section->addText('Народний реєстратор', $boldFontStyle);
     $section->addText(htmlspecialchars($registrar_shortname, ENT_COMPAT, 'UTF-8'));
     header("Content-Description: File Transfer");
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
     header('Content-Transfer-Encoding: binary');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Expires: 0');
     $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
     $xmlWriter->save("php://output");
 }
Beispiel #4
0
 public function getParametersData($role)
 {
     $parametersData = [];
     switch ($role) {
         case Role::CPU:
             $parametersData['cpuSockets'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::cpuSocket])->all(), 'parameter_id', 'parameter_value');
             $parametersData['cpuCores'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::cpuCores])->all(), 'parameter_id', 'parameter_value');
             $parametersData['cpuSpeed'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::cpuSpeed])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::MOTHERBOARD:
             $parametersData['cpuSockets'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::cpuSocket])->all(), 'parameter_id', 'parameter_value');
             $parametersData['mbFormFactor'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::mbFormFactor])->all(), 'parameter_id', 'parameter_value');
             $parametersData['mbChipset'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::mbChipset])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramSlots'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramSlots])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramMax'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramMax])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramSpeed'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramSpeed])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramType'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramType])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::MEMORY:
             $parametersData['ramSize'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramSize])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramSpeed'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramSpeed])->all(), 'parameter_id', 'parameter_value');
             $parametersData['ramType'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::ramType])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::STORAGE:
             $parametersData['storageCapacity'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::storageCapacity])->all(), 'parameter_id', 'parameter_value');
             $parametersData['storageType'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::storageType])->all(), 'parameter_id', 'parameter_value');
             $parametersData['storageInterface'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::storageInterface])->all(), 'parameter_id', 'parameter_value');
             $parametersData['storageFormFactor'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::storageFormFactor])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::VIDEO_CARD:
             $parametersData['vcChipset'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcChipset])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcVram'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcVram])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcInterface'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcInterface])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcSliCrossfire'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcSliCrossfire])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcDisplayPorts'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcDisplayPorts])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcMiniDisplayPorts'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcMiniDisplayPorts])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcHdmi'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcHdmi])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcMiniHdmi'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcMiniHdmi])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcDvi'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcDvi])->all(), 'parameter_id', 'parameter_value');
             $parametersData['vcSlotsWidth'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::vcSlotsWidth])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::PC_CASE:
             $parametersData['mbFormFactor'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::mbFormFactor])->all(), 'parameter_id', 'parameter_value');
             $parametersData['caseType'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::caseType])->all(), 'parameter_id', 'parameter_value');
             break;
         case Role::PSU:
             $parametersData['psuType'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::psuType])->all(), 'parameter_id', 'parameter_value');
             $parametersData['psuModular'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::psuModular])->all(), 'parameter_id', 'parameter_value');
             $parametersData['psuEfficiency'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::psuEfficiency])->all(), 'parameter_id', 'parameter_value');
             $parametersData['psuWatts'] = ArrayHelper::map(Parameter::find()->where(['parameter_name_fk' => Part::psuWatts])->all(), 'parameter_id', 'parameter_value');
             break;
     }
     //$parametersData = array ("Sockets" => $cpuSockets, "Cores" => $cpuCores);
     return $parametersData;
 }