add new task for sending statistics

This commit is contained in:
Uwe Steinmann 2023-03-24 11:17:32 +01:00
parent 057abec09c
commit f4ee945ab1

View File

@ -615,6 +615,113 @@ class SeedDMS_CalendarTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
public function getAdditionalParams() {
return array(
array(
'name'=>'days',
'type'=>'integer',
'description'=> 'Number of days to look ahead starting from today. Negative values will look into the past ending today. 0 will just check for events of the current day.',
),
);
}
} /* }}} */
/**
* Class containing methods for running a scheduled task
*
* @author Uwe Steinmann <uwe@steinmann.cx>
* @package SeedDMS
* @subpackage core
*/
class SeedDMS_StatisticTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
/**
* Run the task
*
* @param SeedDMS_SchedulerTask $task task to be executed
* @return boolean true if task was executed succesfully, otherwise false
*/
public function execute(SeedDMS_SchedulerTask $task) {
$dms = $this->dms;
$user = $this->user;
$logger = $this->logger;
$settings = $this->settings;
$taskparams = $task->getParameter();
$tableformat = " %-30s %5d";
$tableformathead = " %-30s %5s";
$tableformathtml = "<tr><td>%s</td><td>%d</td></tr>";
$tableformatheadhtml = "<tr><th>%s</th><th>%s</th></tr>";
require_once('inc/inc.ClassEmailNotify.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
$userstotal = $dms->getStatisticalData('userstotal');
$docstotal = $dms->getStatisticalData('docstotal');
$folderstotal = $dms->getStatisticalData('folderstotal');
$docsaccumulated = $dms->getStatisticalData('docsaccumulated');
$userids = $taskparams['users'];
foreach($userids as $userid) {
if(($auser = $dms->getUser((int) $userid)) && $auser->isAdmin() && !$auser->isDisabled() && $auser->getEmail()) {
/* Create individual mails, because the users may have different
* languages.
*/
$body = ''.$auser->getLogin()." <".$auser->getEmail().">\n\n";
$bodyhtml = '<p>'.$auser->getLogin()." &lt;".$auser->getEmail()."&gt;</p>";
$bodyhtml .= "<table>".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("name", array(), null, $auser->getLanguage()), getMLText("number_count", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("name", array(), ""), getMLText("number_count", array(), null, $auser->getLanguage()));
$body .= "---------------------------------------------------------------------------------\n";
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("users", array(), null, $auser->getLanguage()), $userstotal);
$body .= sprintf($tableformat."\n", getMLText("users", array(), null, $auser->getLanguage()), $userstotal);
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("documents", array(), null, $auser->getLanguage()), $docstotal);
$body .= sprintf($tableformat."\n", getMLText("documents", array(), null, $auser->getLanguage()), $docstotal);
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("folders", array(), null, $auser->getLanguage()), $folderstotal);
$body .= sprintf($tableformat."\n", getMLText("folders", array(), null, $auser->getLanguage()), $folderstotal);
$today = date('Y-m-d');
$yesterday = date('Y-m-d', time()-86400);
if(isset($docsaccumulated[$today])) {
$docstoday = $docsaccumulated[$today];
} else {
$docstoday = 0;
}
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("new_documents_today", array(), null, $auser->getLanguage()), $docstoday);
$body .= sprintf($tableformat."\n", getMLText("new_documents_today", array(), null, $auser->getLanguage()), $docstoday);
if(isset($docsaccumulated[$yesterday])) {
$docsyesterday = $docsaccumulated[$yesterday];
} else {
$docsyesterday = 0;
}
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("new_documents_yesterday", array(), null, $auser->getLanguage()), $docsyesterday);
$body .= sprintf($tableformat."\n", getMLText("new_documents_yesterday", array(), null, $auser->getLanguage()), $docsyesterday);
$bodyhtml .= "</table>".PHP_EOL;
echo $body;
$params = array();
$params['__body__'] = $body;
$params['__body_html__'] = $bodyhtml;
$params['sitename'] = $settings->_siteName;
//$email->toIndividual('', $auser, 'statistics_mail_subject', '', $params);
$logger->log('Task \'statistics\': Sending statistics \'statistics_mail_subject\' to user \''.$auser->getLogin().'\'', PEAR_LOG_INFO);
}
}
return true;
}
public function getDescription() {
return 'Send statistics by email';
}
public function getAdditionalParams() {
return array(
array(
'name'=>'users',
'type'=>'users',
'multiple'=>true,
'description'=> 'Send statistics report to this users',
)
);
}
} /* }}} */
@ -624,3 +731,4 @@ $GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['indexingdocs'] = 'SeedDMS_Indexi
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['checksum'] = 'SeedDMS_CheckSumTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['preview'] = 'SeedDMS_PreviewTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['calendar'] = 'SeedDMS_CalendarTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['statistic'] = 'SeedDMS_StatisticTask';