Skip to content

Commit

Permalink
#172 [Session] add: clean list file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Feb 10, 2023
1 parent d1f4b84 commit aed6e39
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 205 deletions.
3 changes: 2 additions & 1 deletion core/modules/modDoliMeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function __construct($db)
'projectOverview',
'printOverviewDetail',
'admincompany',
'saturnecard'
'saturnecard',
'sessioncard'
],
// Set this to 1 if features of module are opened to external users
'moduleforexternal' => 0,
Expand Down
94 changes: 0 additions & 94 deletions lib/dolimeet_functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,100 +59,6 @@ function llxHeaderSignature($title, $head = "", $disablejs = 0, $disablehead = 0
}
}

/**
* Load list of objects in memory from the database.
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit limit
* @param int $offset Offset
* @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
* @param string $filtermode Filter mode (AND or OR)
* @return array|int int <0 if KO, array of pages if OK
* @throws Exception
*/
function fetchAllSocPeople($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
{
global $db;

dol_syslog(__METHOD__, LOG_DEBUG);

$records = array();
$errors = array();

$sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
$sql .= " c.address, c.statut, c.zip, c.town,";
$sql .= " c.fk_pays as country_id,";
$sql .= " c.fk_departement as state_id,";
$sql .= " c.birthday,";
$sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
$sql .= " c.socialnetworks,";
$sql .= " c.photo,";
$sql .= " c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
$sql .= " c.fk_prospectcontactlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
$sql .= " c.import_key,";
$sql .= " c.datec as date_creation, c.tms as date_modification,";
$sql .= " co.label as country, co.code as country_code,";
$sql .= " d.nom as state, d.code_departement as state_code,";
$sql .= " u.rowid as user_id, u.login as user_login,";
$sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
$sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON c.fk_pays = co.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_departements as d ON c.fk_departement = d.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON c.rowid = u.fk_socpeople";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON c.fk_soc = s.rowid";
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
$sql .= " WHERE c.entity IN (" . getEntity('socpeople') . ")";
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . '=' . $value;
} elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key . ' = \'' . $db->idate($value) . '\'';
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
} else {
$sqlwhere[] = $key . ' LIKE \'%' . $db->escape($value) . '%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' ' . $filtermode . ' ', $sqlwhere) . ')';
}

if ( ! empty($sortfield)) {
$sql .= $db->order($sortfield, $sortorder);
}
if ( ! empty($limit)) {
$sql .= ' ' . $db->plimit($limit, $offset);
}
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < ($limit ? min($limit, $num) : $num)) {
$obj = $db->fetch_object($resql);

$record = new Contact($db);
$record->setVarsFromFetchObj($obj);

$records[$record->id] = $record;

$i++;
}
$db->free($resql);

return $records;
} else {
$errors[] = 'Error ' . $db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $errors), LOG_ERR);

return -1;
}
}

/**
* Load dictionnary from database
*
Expand Down
19 changes: 10 additions & 9 deletions view/session/session_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
$langs->loadLangs(['dolimeet@dolimeet', 'other@saturne']);

// Get parameters
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $objectType . 'card'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $objectType . 'card'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');

// Initialize technical objects
$classname = ucfirst($objectType);
Expand All @@ -72,7 +73,7 @@
// Initialize view objects
$form = new Form($db);

$hookmanager->initHooks([$objectType . 'card', 'saturnecard', 'globalcard']); // Note that conf->hooks_modules contains array
$hookmanager->initHooks([$objectType . 'card', 'sessioncard', 'saturnecard', 'globalcard']); // Note that conf->hooks_modules contains array

// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
Expand Down Expand Up @@ -353,7 +354,7 @@
// Tags-Categories
if (isModEnabled('categorie')) {
print '<tr><td>' . $langs->trans('Categories') . '</td><td>';
$cate_arbo = $form->select_all_categories($object->element, '', 'parent', 64, 0, 1);
$cate_arbo = $form->select_all_categories('session', '', 'parent', 64, 0, 1);
$c = new Categorie($db);
$cats = $c->containing($object->id, 'session');
$arrayselected = [];
Expand Down
170 changes: 69 additions & 101 deletions view/session/session_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
// Get module parameters
$objectType = GETPOST('object_type', 'alpha');

// Libraries @todo
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
// Libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/propal.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/contact.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/contract.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php';

require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
Expand All @@ -53,12 +48,8 @@
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}

// load session libraries
require_once __DIR__ . '/../../lib/dolimeet_functions.lib.php';
require_once __DIR__ . '/../../class/' . $objectType . '.class.php';

// @fin todo

// Global variables definitions
global $conf, $db, $hookmanager, $langs, $user;

Expand Down Expand Up @@ -105,17 +96,12 @@
$usertmp = new User($db);
$thirdparty = new Societe($db);
$contact = new Contact($db);
$project = new Project($db);

// Initialize view objects
$form = new Form($db);
$formproject = new FormProjets($db);
$formcontrat = new FormContract($db);

if (!$fromtype || !$fromid) {
unset($object->fields['type']);
}

if ($objectType != 'trainingsession' && GETPOST('fromtype') != 'contrat') {
unset($object->fields['fk_contrat']);
}
Expand All @@ -136,36 +122,6 @@
$sortorder = 'ASC';
}

// @todo merge switch
if (!empty($fromtype)) {
switch ($fromtype) {
case 'thirdparty' :
$objectLinked = new Societe($db);
$prehead = 'societe_prepare_head';
break;
case 'project' :
$objectLinked = new Project($db);
$prehead = 'project_prepare_head';
break;
case 'socpeople' :
$objectLinked = new Contact($db);
$prehead = 'contact_prepare_head';
break;
case 'contrat' :
$objectLinked = new Contrat($db);
$prehead = 'contract_prepare_head';
break;
case 'user' :
$objectLinked = new User($db);
$prehead = 'user_prepare_head';
break;
}
$objectLinked->fetch($fromid);
$head = $prehead($objectLinked);
$linkedObjectsArray = ['project', 'contrat'];
$signatoryObjectsArray = ['user', 'thirdparty', 'socpeople'];
}

// Initialize array of search criterias
$search_all = GETPOST('search_all') ? GETPOST('search_all') : GETPOST('sall');
$search = [];
Expand All @@ -185,28 +141,42 @@

if (!empty($fromtype)) {
switch ($fromtype) {
// case 'thirdparty':
// $search['fk_soc'] = $fromid;
// break;
// case 'contact':
// $search['fk_contact'] = $fromid;
// break;
case 'project':
case 'thirdparty' :
$objectLinked = new Societe($db);
$prehead = 'societe_prepare_head';
$search['fk_soc'] = $fromid;
$search['search_attendant_thirdparties'] = $fromid;
break;
case 'project' :
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
$objectLinked = new Project($db);
$prehead = 'project_prepare_head';
$search['fk_project'] = $fromid;
break;
case 'contrat':
case 'contact' :
require_once DOL_DOCUMENT_ROOT . '/core/lib/contact.lib.php';
$objectLinked = new Contact($db);
$prehead = 'contact_prepare_head';
$search['fk_contact'] = $fromid;
$search['search_external_attendants'] = $fromid;
break;
case 'contrat' :
require_once DOL_DOCUMENT_ROOT . '/core/lib/contract.lib.php';
$objectLinked = new Contrat($db);
$prehead = 'contract_prepare_head';
$search['fk_contrat'] = $fromid;
break;
case 'user':
case 'user' :
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php';
$objectLinked = new User($db);
$prehead = 'user_prepare_head';
$search['search_society_attendants'] = $fromid;
break;
case 'socpeople':
$search['search_external_attendants'] = $fromid;
break;
case 'thirdparty':
$search['search_attendant_thirdparties'] = $fromid;
break;
}
$objectLinked->fetch($fromid);
$head = $prehead($objectLinked);
$linkedObjectsArray = ['project', 'contrat'];
$signatoryObjectsArray = ['user', 'thirdparty', 'socpeople'];
}

// List of fields to search into when doing a "search in all"
Expand Down Expand Up @@ -300,8 +270,6 @@

$title = $langs->trans(ucfirst($objectType) . 'List');
$help_url = 'FR:Module_DoliMeet';
//$morejs = ['/dolimeet/js/dolimeet.js.php'];
//$morecss = ['/dolimeet/css/dolimeet.css'];

// Build and execute select
// --------------------------------------------------------------------
Expand Down Expand Up @@ -466,7 +434,7 @@
// Output page
// --------------------------------------------------------------------

llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
saturne_header(0, '', $title, $help_url, '', 0, 0, [], [], '', 'bodyforlist');

require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
$contract = new Contrat($db);
Expand Down Expand Up @@ -875,44 +843,44 @@
}
} elseif ($key == 'Custom') {
foreach ($val as $resource) {
if ($resource['checked']) {
if ($resource['label'] == 'SocietyAttendants') {
$signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_SOCIETY_ATTENDANT', $object->id, $objectType);
print '<td>';
if (is_array($signatories) && !empty($signatories)) {
foreach ($signatories as $object_signatory) {
$usertmp = $user;
$usertmp->fetch($object_signatory->element_id);
print $usertmp->getNomUrl(1);
print '<br>';
}
}
print '</td>';
} elseif ($resource['label'] == 'ExternalAttendants') {
$signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_EXTERNAL_ATTENDANT', $object->id, $objectType);
print '<td>';
if (is_array($signatories) && !empty($signatories)) {
foreach ($signatories as $object_signatory) {
$contact->fetch($object_signatory->element_id);
print $contact->getNomUrl(1);
print '<br>';
}
}
print '</td>';
} elseif ($resource['label'] == 'AttendantThirdparties') {
$signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_EXTERNAL_ATTENDANT', $object->id, $objectType);
print '<td>';
if (is_array($signatories) && !empty($signatories)) {
foreach ($signatories as $object_signatory) {
$contact->fetch($object_signatory->element_id);
$thirdparty->fetch($contact->fk_soc);
print $thirdparty->getNomUrl(1);
print '<br>';
}
}
print '</td>';
}
}
// if ($resource['checked']) {
// if ($resource['label'] == 'SocietyAttendants') {
// $signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_SOCIETY_ATTENDANT', $object->id, $objectType);
// print '<td>';
// if (is_array($signatories) && !empty($signatories)) {
// foreach ($signatories as $object_signatory) {
// $usertmp = $user;
// $usertmp->fetch($object_signatory->element_id);
// print $usertmp->getNomUrl(1);
// print '<br>';
// }
// }
// print '</td>';
// } elseif ($resource['label'] == 'ExternalAttendants') {
// $signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_EXTERNAL_ATTENDANT', $object->id, $objectType);
// print '<td>';
// if (is_array($signatories) && !empty($signatories)) {
// foreach ($signatories as $object_signatory) {
// $contact->fetch($object_signatory->element_id);
// print $contact->getNomUrl(1);
// print '<br>';
// }
// }
// print '</td>';
// } elseif ($resource['label'] == 'AttendantThirdparties') {
// $signatories = $signatory->fetchSignatory(strtoupper($objectType) . '_EXTERNAL_ATTENDANT', $object->id, $objectType);
// print '<td>';
// if (is_array($signatories) && !empty($signatories)) {
// foreach ($signatories as $object_signatory) {
// $contact->fetch($object_signatory->element_id);
// $thirdparty->fetch($contact->fk_soc);
// print $thirdparty->getNomUrl(1);
// print '<br>';
// }
// }
// print '</td>';
// }
// }
}
}
}
Expand Down

0 comments on commit aed6e39

Please sign in to comment.