Skip to content

Commit

Permalink
#1660 [ODT] add: ODT v1.1 and doc_survey
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jan 24, 2024
1 parent e83d77b commit 246307d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function info(Translate $langs): string
*/
public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $moreParam): int
{
global $conf, $langs;
global $conf;

$object = $moreParam['object'];

Expand Down Expand Up @@ -194,18 +194,18 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
}
}

// Get answer photos.
// Get answer photos
$foundTagForLines = 1;
try {
$listLines = $odfHandler->setSegment('photos');
} catch (OdfException $e) {
// We may arrive here if tags for lines not present into template.
// We may arrive here if tags for lines not present into template
$foundTagForLines = 0;
$listLines = '';
dol_syslog($e->getMessage());
}

// Loop on previous photos array.
// Loop on previous photos array
if ($foundTagForLines) {
if (is_array($photoArray) && !empty($photoArray)) {
foreach ($photoArray as $photoPath => $answerRef) {
Expand Down Expand Up @@ -236,7 +236,6 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
return 0;
}

//@todo
/**
* Function to build a document on disk
*
Expand Down Expand Up @@ -267,65 +266,56 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
}

$outputLangs->loadLangs(['products', 'bills', 'orders', 'contracts', 'projects', 'companies']);
$sheet = new Sheet($this->db);
$usertmp = new User($this->db);
$projecttmp = new Project($this->db);

$sheet = new Sheet($this->db);
$project = new Project($this->db);

$sheet->fetch($object->fk_sheet);
$usertmp->fetch($object->fk_user_controller);
$projecttmp->fetch($object->projectid);

$object->fetchObjectLinked('', '', $object->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0);
$linkableElements = get_sheet_linkable_objects();

if (is_array($linkableElements) && !empty($linkableElements)) {
foreach ($linkableElements as $linkableElement) {
$nameField[$linkableElement['link_name']] = $linkableElement['name_field'];
$objectInfo[$linkableElement['link_name']] = [
'title' => $linkableElement['langs'],
'className' => $linkableElement['className']
];
}
foreach ($object->linkedObjectsIds as $linkedObjectType => $linkedObjectsIds) {
$className = $objectInfo[$linkedObjectType]['className'];
$linkedObject = new $className($this->db);
$result = $linkedObject->fetch(array_shift($object->linkedObjectsIds[$linkedObjectType]));
if ($result > 0) {
$objectName = '';
$objectNameField = $nameField[$linkedObjectType];
if (strstr($objectNameField, ',')) {
$nameFields = explode(', ', $objectNameField);
if (is_array($nameFields) && !empty($nameFields)) {
foreach ($nameFields as $subnameField) {
$objectName .= $linkedObject->$subnameField . ' ';
}
}
} else {
$objectName = $linkedObject->$objectNameField;
}
$tmpArray['object_label_ref'] .= $objectName . chr(0x0A);
$tmpArray['object_type'] = $outputLangs->transnoentities($objectInfo[$linkedObjectType]['title']) . ' : ';
}
}
}

$tmpArray['control_ref'] = $object->ref;
$tmpArray['object_label_ref'] = rtrim($tmpArray['object_label_ref'], chr(0x0A));
$tmpArray['control_date'] = dol_print_date($object->date_creation, 'dayhour', 'tzuser');
$tmpArray['project_label'] = $projecttmp->ref . ' - ' . $projecttmp->title;
$tmpArray['sheet_ref'] = $sheet->ref;
$tmpArray['sheet_label'] = $sheet->label;
$project->fetch($object->projectid);

$tmpArray['public_note'] = $object->note_public;
$object->fetchObjectLinked('', '', $object->id, 'digiquali_survey', 'OR', 1, 'sourcetype', 0);

$tmpArray['mycompany_name'] = $conf->global->MAIN_INFO_SOCIETE_NOM;
$tmpArray['mycompany_address'] = (!empty($conf->global->MAIN_INFO_SOCIETE_ADRESS) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_ADRESS : '');
$tmpArray['mycompany_website'] = (!empty($conf->global->MAIN_INFO_SOCIETE_WEBSITE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_WEBSITE : '');
$tmpArray['mycompany_mail'] = (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_MAIL : '');
$tmpArray['mycompany_phone'] = (!empty($conf->global->MAIN_INFO_SOCIETE_PHONE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_PHONE : '');
$linkableElements = get_sheet_linkable_objects();
if (is_array($linkableElements) && !empty($linkableElements)) {
foreach ($linkableElements as $linkableElement) {
$nameField[$linkableElement['link_name']] = $linkableElement['name_field'];
$objectInfo[$linkableElement['link_name']] = ['title' => $linkableElement['langs'], 'className' => $linkableElement['className']];
}
foreach ($object->linkedObjectsIds as $linkedObjectType => $linkedObjectsIds) {
$className = $objectInfo[$linkedObjectType]['className'];
$linkedObject = new $className($this->db);
$result = $linkedObject->fetch(array_shift($object->linkedObjectsIds[$linkedObjectType]));
if ($result > 0) {
$objectName = '';
$objectNameField = $nameField[$linkedObjectType];
if (strstr($objectNameField, ',')) {
$nameFields = explode(', ', $objectNameField);
if (is_array($nameFields) && !empty($nameFields)) {
foreach ($nameFields as $subnameField) {
$objectName .= $linkedObject->$subnameField . ' ';
}
}
} else {
$objectName = $linkedObject->$objectNameField;
}
$tmpArray['object_label_ref'] .= $objectName . chr(0x0A);
$tmpArray['object_type'] = $outputLangs->transnoentities($objectInfo[$linkedObjectType]['title']) . ' : ';
}
}
}

$tmpArray['object_ref'] = $object->ref;
$tmpArray['object_label_ref'] = rtrim($tmpArray['object_label_ref'], chr(0x0A));
// @todo
//$tmpArray['actioncom_creation_date'] = dol_print_date($object->date_creation, 'dayhour', 'tzuser');
//$tmpArray['average'] = dol_print_date($object->date_creation, 'dayhour', 'tzuser');
$tmpArray['project_label'] = $project->ref . ' - ' . $project->title;
$tmpArray['sheet_ref'] = $sheet->ref;
$tmpArray['sheet_label'] = $sheet->label;

$tmpArray['public_note'] = $object->note_public;

$moreParam['tmparray'] = $tmpArray;
$moreParam['multipleAttendantsSegment'] = ['controller', 'attendant'];
$moreParam['tmparray'] = $tmpArray;

return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam);
}
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 246307d

Please sign in to comment.