NEW Add hooks to allow an external module to complete list of events

into calendar views.
This commit is contained in:
Laurent Destailleur 2015-06-30 17:09:52 +02:00
parent 276f057acf
commit 57a267a30f
2 changed files with 43 additions and 14 deletions

View File

@ -341,11 +341,14 @@ dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup); print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup);
dol_fiche_end(); dol_fiche_end();
// Define the legend/list of calendard to show
$s=''; $link='';
$showextcals=$listofextcals; $showextcals=$listofextcals;
// Legend
if (! empty($conf->use_javascript_ajax)) if (! empty($conf->use_javascript_ajax)) // If javascript on
{ {
$s='';
$s.='<script type="text/javascript">' . "\n"; $s.='<script type="text/javascript">' . "\n";
$s.='jQuery(document).ready(function () {' . "\n"; $s.='jQuery(document).ready(function () {' . "\n";
$s.='jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n"; $s.='jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n";
@ -358,7 +361,10 @@ if (! empty($conf->use_javascript_ajax))
$s.='});' . "\n"; $s.='});' . "\n";
$s.='</script>' . "\n"; $s.='</script>' . "\n";
// Local calendar
$s.='<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>'; $s.='<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>';
// External calendars
if (is_array($showextcals) && count($showextcals) > 0) if (is_array($showextcals) && count($showextcals) > 0)
{ {
$s.='<script type="text/javascript">' . "\n"; $s.='<script type="text/javascript">' . "\n";
@ -377,13 +383,23 @@ if (! empty($conf->use_javascript_ajax))
$s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val['name'] . ' &nbsp; </div>'; $s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val['name'] . ' &nbsp; </div>';
} }
} }
// Birthdays
$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>'; $s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
// Calendars from hooks
$parameters=array(); $object=null;
$reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
if (empty($reshook))
{
$s.= $hookmanager->resPrint;
} }
elseif ($reshook > 1)
{
$link=''; $s = $hookmanager->resPrint;
// Add link to show birthdays }
if (empty($conf->use_javascript_ajax)) }
else // If javascript off
{ {
$newparam=$param; // newparam is for birthday links $newparam=$param; // newparam is for birthday links
$newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam); $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
@ -399,7 +415,7 @@ if (empty($conf->use_javascript_ajax))
print_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, ''); print_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, '');
// Get event in an array // Load events from database into $eventarray
$eventarray=array(); $eventarray=array();
$sql = 'SELECT '; $sql = 'SELECT ';
@ -470,6 +486,7 @@ if ($filtert > 0 || $usergroup > 0)
$sql.= ' ORDER BY datep'; $sql.= ' ORDER BY datep';
//print $sql; //print $sql;
dol_syslog("comm/action/index.php", LOG_DEBUG); dol_syslog("comm/action/index.php", LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
@ -571,6 +588,7 @@ else
dol_print_error($db); dol_print_error($db);
} }
// Complete $eventarray with birthdates
if ($showbirthday) if ($showbirthday)
{ {
// Add events in array // Add events in array
@ -638,6 +656,7 @@ if ($showbirthday)
} }
} }
// Complete $eventarray with external import Ical
if (count($listofextcals)) if (count($listofextcals))
{ {
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
@ -878,6 +897,15 @@ if (count($listofextcals))
} }
} }
// Complete $eventarray with events coming from external module
$parameters=array(); $object=null;
$reshook=$hookmanager->executeHooks('getCalendarEvents',$parameters,$object,$action);
if (! empty($hookmanager->resArray['eventarray'])) $eventarray=array_merge($eventarray, $hookmanager->resArray['eventarray']);
$maxnbofchar=18; $maxnbofchar=18;
$cachethirdparties=array(); $cachethirdparties=array();
$cachecontacts=array(); $cachecontacts=array();

View File

@ -116,8 +116,8 @@ class HookManager
* @param array $parameters Array of parameters * @param array $parameters Array of parameters
* @param Object $object Object to use hooks on * @param Object $object Object to use hooks on
* @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* @return mixed For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. * @return mixed For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray.
* For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray.
* All types can also return some values into an array ->results. * All types can also return some values into an array ->results.
* $this->error or this->errors are also defined by class called by this function if error. * $this->error or this->errors are also defined by class called by this function if error.
*/ */
@ -128,7 +128,7 @@ class HookManager
$parameters['context']=join(':',$this->contextarray); $parameters['context']=join(':',$this->contextarray);
dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']); dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
// Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated). // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
$hooktype='output'; $hooktype='output';
if (in_array( if (in_array(
$method, $method,
@ -146,7 +146,8 @@ class HookManager
'paymentsupplierinvoices', 'paymentsupplierinvoices',
'printAddress', 'printAddress',
'printSearchForm', 'printSearchForm',
'formatEvent' 'formatEvent',
'addCalendarChoice'
) )
)) $hooktype='addreplace'; )) $hooktype='addreplace';
// Deprecated hook types ('returnvalue') // Deprecated hook types ('returnvalue')