Skip to content

Commit

Permalink
Evarisk#221 [Lib] add: clean lib files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Apr 7, 2023
1 parent c98445d commit fe62e04
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 100 deletions.
37 changes: 21 additions & 16 deletions lib/dolisirh.lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2023 EVARISK <dev@evarisk.com>
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,22 +26,25 @@
*
* @return array
*/
function dolisirhAdminPrepareHead(): array
function dolisirh_admin_prepare_head(): array
{
// Global variables definitions
global $conf, $langs;

$langs->load("dolisirh@dolisirh");
// Load translation files required by the page
saturne_load_langs();

// Initialize values
$h = 0;
$head = array();
$head = [];

$head[$h][0] = dol_buildpath("/dolisirh/admin/project.php", 1);
$head[$h][1] = '<i class="fas fa-project-diagram pictofixedwidth" style="padding-right: 4px;"></i>' . $langs->trans("ProjectsAndTasks");
$head[$h][0] = dol_buildpath('/dolisirh/admin/project.php', 1);
$head[$h][1] = '<i class="fas fa-project-diagram pictofixedwidth"></i>' . $langs->trans('ProjectsAndTasks');
$head[$h][2] = 'projecttasks';
$h++;

$head[$h][0] = dol_buildpath("/dolisirh/admin/timesheet.php", 1);
$head[$h][1] = '<i class="fas fa-calendar-check pictofixedwidth"></i>' . $langs->trans("TimeSheet");
$head[$h][0] = dol_buildpath('/dolisirh/admin/timesheet.php', 1);
$head[$h][1] = '<i class="fas fa-calendar-check pictofixedwidth"></i>' . $langs->trans('TimeSheet');
$head[$h][2] = 'timesheet';
$h++;

Expand All @@ -50,22 +53,24 @@ function dolisirhAdminPrepareHead(): array
// $head[$h][2] = 'certificate';
// $h++;

$head[$h][0] = dol_buildpath("/dolisirh/admin/dolisirhdocuments.php", 1);
$head[$h][1] = '<i class="fas fa-file-alt pictofixedwidth"></i>' . $langs->trans("YourDocuments");
$head[$h][2] = 'dolisirhdocuments';
$head[$h][0] = dol_buildpath('/dolisirh/admin/dolisirhdocuments.php', 1);
$head[$h][1] = '<i class="fas fa-file-alt pictofixedwidth"></i>' . $langs->trans('YourDocuments');
$head[$h][2] = 'documents';
$h++;

$head[$h][0] = dol_buildpath("/dolisirh/admin/setup.php", 1);
$head[$h][1] = '<i class="fas fa-cog pictofixedwidth"></i>' . $langs->trans("Settings");
$head[$h][0] = dol_buildpath('/dolisirh/admin/setup.php', 1);
$head[$h][1] = '<i class="fas fa-cog pictofixedwidth"></i>' . $langs->trans('ModuleSettings');
$head[$h][2] = 'settings';
$h++;

$head[$h][0] = dol_buildpath("/dolisirh/admin/about.php", 1);
$head[$h][1] = '<i class="fab fa-readme pictofixedwidth" style="padding-right: 4px;"></i>' . $langs->trans("About");
$head[$h][0] = dol_buildpath('/dolisirh/admin/about.php', 1);
$head[$h][1] = '<i class="fab fa-readme pictofixedwidth"></i>' . $langs->trans('About');
$head[$h][2] = 'about';
$h++;

complete_head_from_modules($conf, $langs, null, $head, $h, 'dolisirh');
complete_head_from_modules($conf, $langs, null, $head, $h, 'dolisirh@dolisirh');

complete_head_from_modules($conf, $langs, null, $head, $h, 'dolisirh@dolisirh', 'remove');

return $head;
}
149 changes: 100 additions & 49 deletions lib/dolisirh_certificate.lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2023 EVARISK <dev@evarisk.com>
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -24,64 +24,115 @@
/**
* Prepare array of tabs for Certificate
*
* @param Certificate $object Certificate
* @return array Array of tabs
* @param Certificate $object Certificate
* @return array Array of tabs
* @throws Exception
*/
function certificatePrepareHead($object)
function certificate_prepare_head(Certificate $object): array
{
global $db, $langs, $conf;
// Global variables definitions
global $conf, $db, $moduleName, $moduleNameLowerCase, $langs, $user;

$langs->load("dolisirh@dolisirh");
// Load translation files required by the page
saturne_load_langs();

$h = 0;
$head = array();
// Initialize values
$h = 0;
$head = [];
$objectType = $object->element;

$head[$h][0] = dol_buildpath("/dolisirh/view/certificate/certificate_card.php", 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-info-circle pictofixedwidth"></i>' . $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
$head[$h][0] = dol_buildpath('/' . $moduleNameLowerCase . '/view/' . $objectType . '/' . $objectType . '_card.php', 1) . '?id=' . $object->id;
$head[$h][1] = '<i class="fas fa-info-circle pictofixedwidth"></i>' . $langs->trans(ucfirst($objectType));
$head[$h][2] = 'card';
$h++;

if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = dol_buildpath('/dolisirh/view/certificate/certificate_note.php', 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-comment pictofixedwidth"></i>' . $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}
require_once __DIR__ . '/../class/saturnesignature.class.php';

// require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
// $upload_dir = $conf->dolisirh->dir_output."/certificate/".dol_sanitizeFileName($object->ref);
// $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
// $nbLinks = Link::count($db, $object->element, $object->id);
// $head[$h][0] = dol_buildpath("/dolisirh/view/certificate/certificate_document.php", 1).'?id='.$object->id;
// $head[$h][1] = $langs->trans('Documents');
// if (($nbFiles + $nbLinks) > 0) {
// $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
// }
// $head[$h][2] = 'document';
// $h++;
$signatory = new SaturneSignature($db);

$head[$h][0] = dol_buildpath("/dolisirh/view/certificate/certificate_agenda.php", 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-calendar-alt pictofixedwidth"></i>' . $langs->trans("Events");
$head[$h][2] = 'agenda';
$h++;
$signatoriesArray = $signatory->fetchSignatories($object->id, $objectType);
if (is_array($signatoriesArray) && !empty($signatoriesArray)) {
$nbAttendants = count($signatoriesArray);
} else {
$nbAttendants = 0;
}

$head[$h][0] = dol_buildpath("/dolisirh/view/certificate/certificate_attendants.php", 1) . '?id=' . $object->id;
$head[$h][1] = '<i class="fas fa-file-signature pictofixedwidth"></i>' . $langs->trans("Attendants");
$head[$h][2] = 'attendants';
$h++;
$head[$h][0] = dol_buildpath('/' . $moduleNameLowerCase . '/view/saturne_attendants.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-file-signature pictofixedwidth"></i>' . $langs->trans('Attendants');
if ($nbAttendants > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbAttendants . '</span>';
}
$head[$h][2] = 'attendants';
$h++;

complete_head_from_modules($conf, $langs, $object, $head, $h, 'certificate@dolisirh');
if ($user->rights->$moduleNameLowerCase->$objectType->read) {
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = dol_buildpath('/saturne/view/saturne_note.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-comment pictofixedwidth"></i>' . $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}

require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->$moduleNameLowerCase->dir_output . '/' . $objectType . '/' . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $objectType, $object->id);
$head[$h][0] = dol_buildpath('/saturne/view/saturne_document.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-file-alt pictofixedwidth"></i>' . $langs->trans('Documents');
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
}
$head[$h][2] = 'document';
$h++;

$head[$h][0] = dol_buildpath('/saturne/view/saturne_agenda.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-calendar-alt pictofixedwidth"></i>' . $langs->trans('Events');
if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
$nbEvent = 0;
// Enable caching of object type count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
$cacheKey = 'count_events_' . $objectType . '_' . $object->id;
$dataRetrieved = dol_getcache($cacheKey);
if (!is_null($dataRetrieved)) {
$nbEvent = $dataRetrieved;
} else {
$sql = 'SELECT COUNT(id) as nb';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm';
$sql .= ' WHERE fk_element = ' . $object->id;
$sql .= " AND elementtype = '" . $objectType . '@' . $moduleNameLowerCase . "'";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbEvent = $obj->nb;
} else {
dol_syslog('Failed to count actioncomm ' . $db->lasterror(), LOG_ERR);
}
dol_setcache($cacheKey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
}
$head[$h][1] .= '/';
$head[$h][1] .= $langs->trans('Agenda');
if ($nbEvent > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>';
}
}
$head[$h][2] = 'agenda';
$h++;
}

complete_head_from_modules($conf, $langs, $object, $head, $h, $objectType . '@' . $moduleNameLowerCase);

complete_head_from_modules($conf, $langs, $object, $head, $h, $objectType . '@' . $moduleNameLowerCase, 'remove');

return $head;
}
134 changes: 99 additions & 35 deletions lib/dolisirh_timesheet.lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2023 EVARISK <dev@evarisk.com>
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,49 +26,113 @@
*
* @param TimeSheet $object TimeSheet
* @return array Array of tabs
* @throws Exception
*/
function timesheetPrepareHead(TimeSheet $object): array
function timesheet_prepare_head(TimeSheet $object): array
{
global $conf, $langs;
// Global variables definitions
global $conf, $db, $moduleName, $moduleNameLowerCase, $langs, $user;

$langs->load("dolisirh@dolisirh");
// Load translation files required by the page
saturne_load_langs();

$h = 0;
$head = array();
// Initialize values
$h = 0;
$head = [];
$objectType = $object->element;

$head[$h][0] = dol_buildpath("/dolisirh/view/timesheet/timesheet_card.php", 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-info-circle pictofixedwidth"></i>' . $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
$head[$h][0] = dol_buildpath('/' . $moduleNameLowerCase . '/view/' . $objectType . '/' . $objectType . '_card.php', 1) . '?id=' . $object->id;
$head[$h][1] = '<i class="fas fa-info-circle pictofixedwidth"></i>' . $langs->trans(ucfirst($objectType));
$head[$h][2] = 'card';
$h++;

if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = dol_buildpath('/dolisirh/view/timesheet/timesheet_note.php', 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-comment pictofixedwidth"></i>' . $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}
// require_once __DIR__ . '/../class/saturnesignature.class.php';
//
// $signatory = new SaturneSignature($db);
//
// $signatoriesArray = $signatory->fetchSignatories($object->id, $objectType);
// if (is_array($signatoriesArray) && !empty($signatoriesArray)) {
// $nbAttendants = count($signatoriesArray);
// } else {
// $nbAttendants = 0;
// }
//
// $head[$h][0] = dol_buildpath('/' . $moduleNameLowerCase . '/view/saturne_attendants.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
// $head[$h][1] = '<i class="fas fa-file-signature pictofixedwidth"></i>' . $langs->trans('Attendants');
// if ($nbAttendants > 0) {
// $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbAttendants . '</span>';
// }
// $head[$h][2] = 'attendants';
// $h++;

$head[$h][0] = dol_buildpath("/dolisirh/view/timesheet/timesheet_agenda.php", 1).'?id='.$object->id;
$head[$h][1] = '<i class="fas fa-calendar-alt pictofixedwidth"></i>' . $langs->trans("Events");
$head[$h][2] = 'agenda';
$h++;
if ($user->rights->$moduleNameLowerCase->$objectType->read) {
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = dol_buildpath('/saturne/view/saturne_note.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-comment pictofixedwidth"></i>' . $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}

$head[$h][0] = dol_buildpath("/dolisirh/view/timesheet/timesheet_attendants.php", 1) . '?id=' . $object->id;
$head[$h][1] = '<i class="fas fa-file-signature pictofixedwidth"></i>' . $langs->trans("Attendants");
$head[$h][2] = 'attendants';
$h++;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->$moduleNameLowerCase->dir_output . '/' . $objectType . '/' . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $objectType, $object->id);
$head[$h][0] = dol_buildpath('/saturne/view/saturne_document.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-file-alt pictofixedwidth"></i>' . $langs->trans('Documents');
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
}
$head[$h][2] = 'document';
$h++;

complete_head_from_modules($conf, $langs, $object, $head, $h, 'timesheet@dolisirh');
$head[$h][0] = dol_buildpath('/saturne/view/saturne_agenda.php', 1) . '?id=' . $object->id . '&module_name=' . $moduleName . '&object_type=' . $objectType;
$head[$h][1] = '<i class="fas fa-calendar-alt pictofixedwidth"></i>' . $langs->trans('Events');
if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
$nbEvent = 0;
// Enable caching of object type count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
$cacheKey = 'count_events_' . $objectType . '_' . $object->id;
$dataRetrieved = dol_getcache($cacheKey);
if (!is_null($dataRetrieved)) {
$nbEvent = $dataRetrieved;
} else {
$sql = 'SELECT COUNT(id) as nb';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm';
$sql .= ' WHERE fk_element = ' . $object->id;
$sql .= " AND elementtype = '" . $objectType . '@' . $moduleNameLowerCase . "'";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbEvent = $obj->nb;
} else {
dol_syslog('Failed to count actioncomm ' . $db->lasterror(), LOG_ERR);
}
dol_setcache($cacheKey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
}
$head[$h][1] .= '/';
$head[$h][1] .= $langs->trans('Agenda');
if ($nbEvent > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>';
}
}
$head[$h][2] = 'agenda';
$h++;
}

complete_head_from_modules($conf, $langs, $object, $head, $h, $objectType . '@' . $moduleNameLowerCase);

complete_head_from_modules($conf, $langs, $object, $head, $h, $objectType . '@' . $moduleNameLowerCase, 'remove');

return $head;
}

0 comments on commit fe62e04

Please sign in to comment.