NEW Implement MAIN_ACTIVATE_FILECACHE on bithday widget

This commit is contained in:
Laurent Destailleur
2023-05-05 13:16:29 +02:00
parent fc1fd81c82
commit 57a9ef35ae
8 changed files with 175 additions and 112 deletions

View File

@@ -171,6 +171,7 @@ NEW: use more recent model by default
NEW: VAT can be modified during add of line NEW: VAT can be modified during add of line
NEW: write all fields and their properties in asciidoc format NEW: write all fields and their properties in asciidoc format
NEW: Can add an array of several links in date selector NEW: Can add an array of several links in date selector
NEW: Implement MAIN_ACTIVATE_FILECACHE on bithday widget
For developers or integrators: For developers or integrators:
------------------------------ ------------------------------

View File

@@ -627,6 +627,25 @@ if (!in_array($conf->browser->name, array('chrome', 'opera', 'safari', 'firefox'
} }
print '<br>'; print '<br>';
// Options
print '<br>';
print '<strong>'.$langs->trans("Options").'</strong>:<br>';
if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
print 'MAIN_ACTIVATE_FILECACHE = '.getDolGlobalInt('MAIN_ACTIVATE_FILECACHE').' '.img_picto('', 'tick.png');
} else {
print 'MAIN_ACTIVATE_FILECACHE = '.getDolGlobalInt('MAIN_ACTIVATE_FILECACHE', 0);
//.' '.img_picto('', 'warning.png');
}
print '<br>';
if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
print 'MAIN_ENABLE_AJAX_TOOLTIP = '.getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP').' '.img_picto('', 'tick.png');
} else {
print 'MAIN_ENABLE_AJAX_TOOLTIP = '.getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP', 0);
//.' '.img_picto('', 'warning.png');
}
print '<br>';
// End of page // End of page
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@@ -83,11 +83,12 @@ class box_activity extends ModeleBoxes
$totalnb = 0; $totalnb = 0;
$line = 0; $line = 0;
$cachetime = 3600;
$fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'-r'.($user->hasRight("societe", "client", "voir") ? '1' : '0').'.cache';
$now = dol_now(); $now = dol_now();
$nbofperiod = 3; $nbofperiod = 3;
$cachetime = 3600;
$fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'-r'.($user->hasRight("societe", "client", "voir") ? '1' : '0').'.cache';
if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) { if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) {
$nbofperiod = $conf->global->MAIN_BOX_ACTIVITY_DURATION; $nbofperiod = $conf->global->MAIN_BOX_ACTIVITY_DURATION;
} }
@@ -134,12 +135,13 @@ class box_activity extends ModeleBoxes
if ($result) { if ($result) {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$j = 0; $line = 0;
while ($j < $num) { while ($line < $num) {
$data[$j] = $this->db->fetch_object($result); $data[$line] = $this->db->fetch_object($result);
$j++;
$line++;
} }
if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
dol_filecache($cachedir, $filename, $data); dol_filecache($cachedir, $filename, $data);
} }
$this->db->free($result); $this->db->free($result);
@@ -188,7 +190,7 @@ class box_activity extends ModeleBoxes
if (count($data) == 0) { if (count($data) == 0) {
$this->info_box_contents[$line][0] = array( $this->info_box_contents[$line][0] = array(
'td' => 'class="center"', 'td' => 'class="center"',
'text'=>$langs->trans("NoRecordedProposals"), 'text'=>'<span class="opacitymedium">'.$langs->trans("NoRecordedProposals").'</span>',
); );
$line++; $line++;
} }
@@ -234,7 +236,7 @@ class box_activity extends ModeleBoxes
$data[$j] = $this->db->fetch_object($result); $data[$j] = $this->db->fetch_object($result);
$j++; $j++;
} }
if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
dol_filecache($cachedir, $filename, $data); dol_filecache($cachedir, $filename, $data);
} }
$this->db->free($result); $this->db->free($result);
@@ -329,7 +331,7 @@ class box_activity extends ModeleBoxes
$data[$j] = $this->db->fetch_object($result); $data[$j] = $this->db->fetch_object($result);
$j++; $j++;
} }
if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
dol_filecache($cachedir, $filename, $data); dol_filecache($cachedir, $filename, $data);
} }
$this->db->free($result); $this->db->free($result);
@@ -411,7 +413,7 @@ class box_activity extends ModeleBoxes
$data[$j] = $this->db->fetch_object($result); $data[$j] = $this->db->fetch_object($result);
$j++; $j++;
} }
if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
dol_filecache($cachedir, $filename, $data); dol_filecache($cachedir, $filename, $data);
} }
$this->db->free($result); $this->db->free($result);

View File

@@ -71,96 +71,113 @@ class box_birthdays extends ModeleBoxes
*/ */
public function loadBox($max = 20) public function loadBox($max = 20)
{ {
global $user, $langs; global $conf, $user, $langs;
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$langs->load("boxes"); $langs->load("boxes");
$this->max = $max; $this->max = $max;
$cachetime = 3600;
$fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'.cache';
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$userstatic = new User($this->db); $userstatic = new User($this->db);
$this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth")); $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth"));
if ($user->rights->user->user->lire) { if ($user->hasRight('user', 'user', 'lire')) {
$tmparray = dol_getdate(dol_now(), true); $cachedir = DOL_DATA_ROOT.'/users/temp';
$filename = '/boxbirthdays-'.$fileid;
$refresh = dol_cache_refresh($cachedir, $filename, $cachetime);
$data = array();
if ($refresh) {
$tmparray = dol_getdate(dol_now(), true);
$sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status"; $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.entity IN (".getEntity('user').")"; $sql .= " WHERE u.entity IN (".getEntity('user').")";
$sql .= " AND u.statut = ".User::STATUS_ENABLED; $sql .= " AND u.statut = ".User::STATUS_ENABLED;
$sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
$sql .= ' UNION '; $sql .= ' UNION ';
$sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status"; $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.entity IN (".getEntity('user').")"; $sql .= " WHERE u.entity IN (".getEntity('user').")";
$sql .= " AND u.statut = ".User::STATUS_ENABLED; $sql .= " AND u.statut = ".User::STATUS_ENABLED;
$sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0); $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0);
$sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
$sql .= $this->db->plimit($max, 0); $sql .= $this->db->plimit($max, 0);
dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
$result = $this->db->query($sql); $resql = $this->db->query($sql);
if ($result) { if ($resql) {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($resql);
$line = 0; $line = 0;
while ($line < $num) { while ($line < $num) {
$objp = $this->db->fetch_object($result); $data[$line] = $this->db->fetch_object($resql);
$userstatic->id = $objp->rowid; $line++;
$userstatic->firstname = $objp->firstname; }
$userstatic->lastname = $objp->lastname;
$userstatic->email = $objp->email;
$userstatic->statut = $objp->status;
$dateb = $this->db->jdate($objp->datea); if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
dol_filecache($cachedir, $filename, $data);
}
$this->db->free($resql);
}
} else {
$data = dol_readcachefile($cachedir, $filename);
}
if (!empty($data)) {
$j = 0;
while ($j < count($data)) {
$userstatic->id = $data[$j]->rowid;
$userstatic->firstname = $data[$j]->firstname;
$userstatic->lastname = $data[$j]->lastname;
$userstatic->email = $data[$j]->email;
$userstatic->statut = $data[$j]->status;
$dateb = $this->db->jdate($data[$j]->datea);
$age = date('Y', dol_now()) - date('Y', $dateb); $age = date('Y', dol_now()) - date('Y', $dateb);
$picb = '<i class="fas fa-birthday-cake inline-block"></i>'; $picb = '<i class="fas fa-birthday-cake inline-block"></i>';
$pice = '<i class="fas fa-briefcase inline-block"></i>'; $pice = '<i class="fas fa-briefcase inline-block"></i>';
$typea = ($objp->typea == 'birth') ? $picb : $pice; $typea = ($data[$j]->typea == 'birth') ? $picb : $pice;
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][0] = array(
'td' => '', 'td' => '',
'text' => $userstatic->getNomUrl(1), 'text' => $userstatic->getNomUrl(1),
'asis' => 1, 'asis' => 1,
); );
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][1] = array(
'td' => 'class="center nowraponall"', 'td' => 'class="center nowraponall"',
'text' => dol_print_date($dateb, "day", 'tzserver') 'text' => dol_print_date($dateb, "day", 'tzserver')
); );
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][2] = array(
'td' => 'class="right nowraponall"', 'td' => 'class="right nowraponall"',
'text' => $age.' '.$langs->trans('DurationYears') 'text' => $age.' '.$langs->trans('DurationYears')
); );
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][3] = array(
'td' => 'class="center nowraponall"', 'td' => 'class="right nowraponall"',
'text' => $typea, 'text' => $typea,
'asis' => 1 'asis' => 1
); );
/*$this->info_box_contents[$line][] = array( $j++;
'td' => 'class="right" width="18"',
'text' => $userstatic->LibStatut($objp->status, 3)
);*/
$line++;
} }
}
if ($num == 0) { if (is_array($data) && count($data) == 0) {
$this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>');
}
$this->db->free($result);
} else {
$this->info_box_contents[0][0] = array( $this->info_box_contents[0][0] = array(
'td' => '', 'td' => 'class="center"',
'maxlength'=>500, 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
'text' => ($this->db->error().' sql='.$sql)
); );
} }
} else { } else {

View File

@@ -71,84 +71,108 @@ class box_birthdays_members extends ModeleBoxes
*/ */
public function loadBox($max = 20) public function loadBox($max = 20)
{ {
global $user, $langs; global $conf, $user, $langs;
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$langs->load("boxes"); $langs->load("boxes");
$this->max = $max; $this->max = $max;
$cachetime = 3600;
$fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'.cache';
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$memberstatic = new Adherent($this->db); $memberstatic = new Adherent($this->db);
$this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays")); $this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays"));
if ($user->rights->adherent->lire) { if ($user->hasRight('adherent', 'lire')) {
$tmparray = dol_getdate(dol_now(), true); $cachedir = DOL_DATA_ROOT.'/users/temp';
$filename = '/boxbirthdays-members'.$fileid;
$refresh = dol_cache_refresh($cachedir, $filename, $cachetime);
$data = array();
if ($refresh) {
$tmparray = dol_getdate(dol_now(), true);
$sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin"; $sql = "SELECT u.rowid, u.firstname, u.lastname, u.societe, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as u"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u";
$sql .= " WHERE u.entity IN (".getEntity('adherent').")"; $sql .= " WHERE u.entity IN (".getEntity('adherent').")";
$sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED; $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED;
$sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0);
$sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year
$sql .= $this->db->plimit($max, 0); $sql .= $this->db->plimit($max, 0);
dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
$result = $this->db->query($sql); $resql = $this->db->query($sql);
if ($result) { if ($resql) {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($resql);
$line = 0; $line = 0;
while ($line < $num) { while ($line < $num) {
$objp = $this->db->fetch_object($result); $data[$line] = $this->db->fetch_object($resql);
$memberstatic->id = $objp->rowid;
$memberstatic->firstname = $objp->firstname; $line++;
$memberstatic->lastname = $objp->lastname; }
$memberstatic->email = $objp->email;
$memberstatic->status = $objp->status; if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) {
$memberstatic->statut = $memberstatic->status; dol_filecache($cachedir, $filename, $data);
$memberstatic->datefin = $this->db->jdate($objp->datefin); }
//$memberstatic->need_subscription = 1;
$dateb = $this->db->jdate($objp->birth); $this->db->free($resql);
}
} else {
$data = dol_readcachefile($cachedir, $filename);
}
if (!empty($data)) {
$j = 0;
while ($j < count($data)) {
$memberstatic->id = $data[$j]->rowid;
$memberstatic->firstname = $data[$j]->firstname;
$memberstatic->lastname = $data[$j]->lastname;
$memberstatic->company = $data[$j]->societe;
$memberstatic->email = $data[$j]->email;
$memberstatic->status = $data[$j]->status;
$memberstatic->statut = $data[$j]->status;
$memberstatic->datefin = $this->db->jdate($data[$j]->datefin);
$dateb = $this->db->jdate($data[$j]->birth);
$age = date('Y', dol_now()) - date('Y', $dateb); $age = date('Y', dol_now()) - date('Y', $dateb);
$typea = '<i class="fas fa-birthday-cake inline-block"></i>'; $typea = '<i class="fas fa-birthday-cake inline-block"></i>';
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][0] = array(
'td' => '', 'td' => '',
'text' => $memberstatic->getNomUrl(1), 'text' => $memberstatic->getNomUrl(1),
'asis' => 1, 'asis' => 1,
); );
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][1] = array(
'td' => 'class="center nowraponall"', 'td' => 'class="center nowraponall"',
'text' => dol_print_date($dateb, "day", 'tzserver').' - '.$age.' '.$langs->trans('DurationYears') 'text' => dol_print_date($dateb, "day", 'tzserver').' - '.$age.' '.$langs->trans('DurationYears')
); );
$this->info_box_contents[$line][] = array( $this->info_box_contents[$j][2] = array(
'td' => 'class="center nowraponall"', 'td' => 'class="right nowraponall"',
'text' => $typea, 'text' => $typea,
'asis' => 1 'asis' => 1
); );
/*$this->info_box_contents[$line][] = array( /*$this->info_box_contents[$j][3] = array(
'td' => 'class="right" width="18"', 'td' => 'class="right" width="18"',
'text' => $memberstatic->LibStatut($objp->status, 3) 'text' => $memberstatic->LibStatut($objp->status, 3)
);*/ );*/
$line++; $j++;
} }
}
if ($num == 0) { if (is_array($data) && count($data) == 0) {
$this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>');
}
$this->db->free($result);
} else {
$this->info_box_contents[0][0] = array( $this->info_box_contents[0][0] = array(
'td' => '', 'td' => 'class="center"',
'maxlength'=>500, 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>',
'text' => ($this->db->error().' sql='.$sql)
); );
} }
} else { } else {

View File

@@ -719,7 +719,7 @@ abstract class CommonObject
} }
/** /**
* getTooltipContentArray * Return array of datas to show into a tooltip. This method must be implemented in each object class.
* *
* @since v18 * @since v18
* @param array $params params to construct tooltip data * @param array $params params to construct tooltip data

View File

@@ -3342,9 +3342,9 @@ function dol_cache_refresh($directory, $filename, $cachetime)
/** /**
* Read object from cachefile. * Read object from cachefile.
* *
* @param string $directory Directory of cache * @param string $directory Directory of cache
* @param string $filename Name of filecache * @param string $filename Name of filecache
* @return mixed Unserialise from file * @return mixed Unserialise from file
*/ */
function dol_readcachefile($directory, $filename) function dol_readcachefile($directory, $filename)
{ {

View File

@@ -2746,7 +2746,7 @@ class User extends CommonObject
} }
/** /**
* getTooltipContentArray * Return array of data to show into tooltips
* *
* @param array $params ex option, infologin * @param array $params ex option, infologin
* @since v18 * @since v18