/** * Ajoute les données des graphiques de supervision * * @param CTemplateManager $template The template manager * @param CMbObject $object The host object * @param string $name The field name * * @return void */ static function addObservationDataToTemplate(CTemplateManager $template, CMbObject $object, $name) { $prefix = "Supervision"; $group_id = CGroups::loadCurrent()->_id; $results = array(); $times = array(); if ($object->_id) { list($results, $times) = CObservationResultSet::getResultsFor($object, false); $times = array_combine($times, $times); } // CSupervisionGraphAxis $axis = new CSupervisionGraphAxis(); $ds = $axis->getDS(); $where = array("supervision_graph_axis.in_doc_template" => "= '1'", "supervision_graph.owner_class" => "= 'CGroups'", "supervision_graph.owner_id" => $ds->prepare("= ?", $group_id)); $ljoin = array("supervision_graph" => "supervision_graph.supervision_graph_id = supervision_graph_axis.supervision_graph_id"); $order = array("supervision_graph.title", "supervision_graph_axis.title"); /** @var CSupervisionGraphAxis[] $axes */ $axes = $axis->loadList($where, $order, null, null, $ljoin); CStoredObject::massLoadFwdRef($axes, "supervision_graph_id", null, true); foreach ($axes as $_axis) { $_graph = $_axis->loadRefGraph(); $_series = $_axis->loadRefsSeries(); $_axis->loadRefsLabels(); $_data = array_fill_keys($times, array()); foreach ($_series as $_serie) { $_unit_id = $_serie->value_unit_id ?: "none"; $_unit_label = $_serie->loadRefValueUnit(); if (!isset($results[$_serie->value_type_id][$_unit_id])) { continue; } foreach ($results[$_serie->value_type_id][$_unit_id] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } $_value["unit"] = $_unit_label->label; $_data["{$_time}"][$_serie->_id] = $_value; break; } } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("series", $_series); $smarty->assign("times", $times); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_graph->title} - {$_axis->title}", trim($view), "", false); } // CSupervisionTimedPicture // CSupervisionTimedData $data = array("CSupervisionTimedPicture", "CSupervisionTimedData"); foreach ($data as $_class) { /** @var CSupervisionTimedPicture|CSupervisionTimedData $_object */ $_object = new $_class(); $_table = $_object->_spec->table; $_ds = $_object->getDS(); $where = array("{$_table}.in_doc_template" => "= '1'", "{$_table}.owner_class" => "= 'CGroups'", "{$_table}.owner_id" => $_ds->prepare("= ?", $group_id)); $order = "title"; /** @var CSupervisionTimedPicture[]|CSupervisionTimedData[] $_objects */ $_objects = $_object->loadList($where, $order); foreach ($_objects as $_timed) { $_data = array_fill_keys($times, null); if (!isset($results[$_timed->value_type_id])) { continue; } foreach ($results[$_timed->value_type_id]["none"] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } if ($_value["file_id"]) { $_file = new CFile(); $_file->load($_value["file_id"]); $_value["datauri"] = $_file->getDataURI(); $_value["file"] = $_file; } $_data["{$_time}"] = $_value; break; } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("times", $times); $smarty->assign("timed_data", true); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_timed->title}", trim($view), "", false); } } }
/** * Adds the list of forms to a template manager * * @param CTemplateManager $template The template manager * @param CMbObject $object The host object * @param string $name The field name * * @return void */ static function addFormsToTemplate(CTemplateManager $template, CMbObject $object, $name) { static $ex_classes = null; if (!CAppUI::conf("forms CExClassField doc_template_integration")) { return; } $params = array("detail" => 3, "reference_id" => $object->_id, "reference_class" => $object->_class, "target_element" => "ex-objects-{$object->_id}", "print" => 1, "limit" => null); $formulaires = ""; $params["limit"] = 1; if ($object->_id) { $formulaires = CApp::fetch("forms", "ajax_list_ex_object", $params); $formulaires = preg_replace('/\\s+/', " ", $formulaires); // Remove CRLF which CKEditor transform to <br /> } $template->addProperty("{$name} - Formulaires - Dernier", $formulaires, null, false); $params["limit"] = 5; if ($object->_id) { $formulaires = CApp::fetch("forms", "ajax_list_ex_object", $params); $formulaires = preg_replace('/\\s+/', " ", $formulaires); // Remove CRLF which CKEditor transform to <br /> } $template->addProperty("{$name} - Formulaires - 5 derniers", $formulaires, null, false); $params["limit"] = 1; $params["only_host"] = 1; if ($object->_id) { $formulaires = CApp::fetch("forms", "ajax_list_ex_object", $params); $formulaires = preg_replace('/\\s+/', " ", $formulaires); // Remove CRLF which CKEditor transform to <br /> } $template->addProperty("{$name} - Formulaires - Liés", $formulaires, null, false); self::$_multiple_load = true; CExObject::initLocales(); if ($ex_classes === null) { $group_id = CGroups::loadCurrent()->_id; $where = array("ex_class.group_id = '{$group_id}' OR group_id IS NULL", "ex_class_field.in_doc_template" => "= '1'"); $ljoin = array("ex_class_field_group" => "ex_class_field_group.ex_class_id = ex_class.ex_class_id", "ex_class_field" => "ex_class_field.ex_group_id = ex_class_field_group.ex_class_field_group_id"); $ex_class = new CExClass(); /** @var CExClass[] $ex_classes */ $ex_classes = $ex_class->loadList($where, "name", null, "ex_class.ex_class_id", $ljoin); foreach ($ex_classes as $_ex_class) { $_ex_class->_all_fields = $_ex_class->loadRefsAllFields(); } } foreach ($ex_classes as $_ex_class) { $_name = "Form. " . str_replace(" - ", " ", $_ex_class->name); $fields = $_ex_class->_all_fields; $_class_name = $_ex_class->getExClassName(); $_ex_object = null; if ($object->_id) { $_ex_object = $_ex_class->getLatestExObject($object); } if ($template->valueMode && (!$_ex_object || !$_ex_object->_id)) { continue; } $template->addDateProperty("Sejour - {$_name} - Date de saisie du form.", $_ex_object ? $_ex_object->datetime_create : null); $template->addTimeProperty("Sejour - {$_name} - Heure de saisie du form.", $_ex_object ? $_ex_object->datetime_create : null); foreach ($fields as $_field) { if (!$_field->in_doc_template) { continue; } $_field_name = str_replace(" - ", " ", CAppUI::tr("{$_class_name}-{$_field->name}")); $_template_field_name = "Sejour - {$_name} - {$_field_name}"; $_template_key_name = "CExObject|{$_ex_class->_id}|{$_field->name}"; $_has_value = $_ex_object && $_ex_object->_id && $_field->name != ""; $_template_value = $_has_value ? $_ex_object->getFormattedValue($_field->name) : ""; $template->addAdvancedData($_template_field_name, $_template_key_name, $_template_value); } } self::$_multiple_load = false; }