From bf4b99fa641bd4ac00092b2780f3a89aefa09b66 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Sep 2014 12:27:18 +0200 Subject: [PATCH] Assignation of event to several users is on a very good way for 3.7 --- htdocs/comm/action/card.php | 2 + htdocs/comm/action/class/actioncomm.class.php | 31 ++++++++++----- htdocs/comm/action/index.php | 30 +++++++------- htdocs/comm/action/peruser.php | 39 +++++++++++-------- htdocs/core/class/html.form.class.php | 6 ++- 5 files changed, 67 insertions(+), 41 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index aef2d5fad3d..827e2df976a 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -219,6 +219,7 @@ if ($action == 'add') if ($value['id'] > 0) { $usertodo->fetch($value['id']); + $object->userownerid = $usertodo->id; } $object->usertodo = $usertodo; $object->transparency = (GETPOST("transparency")=='on'?1:0); @@ -235,6 +236,7 @@ if ($action == 'add') if ($_POST["doneby"] > 0) { $userdone->fetch($_POST["doneby"]); + $object->userdoneid = $userdone->id; } $object->userdone = $userdone; } diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 1d7cf0efd68..fa7130ec018 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -47,8 +47,10 @@ class ActionComm extends CommonObject var $datec; // Date creation record (datec) var $datem; // Date modification record (tms) - var $author; // Object user that create action - var $usermod; // Object user that modified action + var $author; // Object user that create action //deprecated + var $usermod; // Object user that modified action // deprecated + var $authorid; // Id user that create action + var $usermodid; // Id user that modified action var $datep; // Date action start (datep) var $datef; // Date action end (datep2) @@ -63,8 +65,9 @@ class ActionComm extends CommonObject var $note; // Description var $userassigned = array(); // Array of user ids - var $usertodo; // Object user of owner - var $userdone; // Object user that did action (deprecated) + var $userownerid; // Id of user owner + var $usertodo; // Object user of owner // deprecated + var $userdone; // Object user that did action // deprecated var $socid; var $contactid; @@ -134,6 +137,9 @@ class ActionComm extends CommonObject if ($this->elementtype=='commande') $this->elementtype='order'; if ($this->elementtype=='contrat') $this->elementtype='contract'; + $userownerid=isset($this->usertodo->id)?$this->usertodo->id:$this->userownerid; // For backward compatibility + $userdoneid=isset($this->userdone->id)?$this->userdone->id:$this->userdoneid; // For backward compatibility + if (! $this->type_id && $this->type_code) { // Get id from code @@ -197,8 +203,8 @@ class ActionComm extends CommonObject $sql.= " '".$this->db->escape($this->note)."',"; $sql.= (isset($this->contactid) && $this->contactid > 0?"'".$this->contactid."'":"null").","; $sql.= (isset($user->id) && $user->id > 0 ? "'".$user->id."'":"null").","; - $sql.= (isset($this->usertodo->id) && $this->usertodo->id > 0?"'".$this->usertodo->id."'":"null").","; - $sql.= (isset($this->userdone->id) && $this->userdone->id > 0?"'".$this->userdone->id."'":"null").","; + $sql.= ($userownerid>0?"'".$userownerid."'":"null").","; + $sql.= ($userdoneid>0?"'".$userdoneid."'":"null").","; $sql.= "'".$this->db->escape($this->label)."','".$this->percentage."','".$this->priority."','".$this->fulldayevent."','".$this->db->escape($this->location)."','".$this->punctual."',"; $sql.= "'".$this->transparency."',"; $sql.= (! empty($this->fk_element)?$this->fk_element:"null").","; @@ -351,8 +357,9 @@ class ActionComm extends CommonObject $this->author->lastname = $obj->lastname; $this->usermod->id = $obj->fk_user_mod; - $this->usertodo->id = $obj->fk_user_action; - $this->userdone->id = $obj->fk_user_done; + $this->userownerid = $obj->fk_user_action; + $this->usertodo->id = $obj->fk_user_action; // deprecated + //$this->userdone->id = $obj->fk_user_done; $this->priority = $obj->priority; $this->fulldayevent = $obj->fulldayevent; $this->location = $obj->location; @@ -380,19 +387,25 @@ class ActionComm extends CommonObject /** - * Initialize this->userassigned array + * Initialize this->userassigned array with list of id of user assigned to event * * @return int <0 if KO, >0 if OK */ function fetch_userassigned() { global $langs; + $sql.="SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency"; $sql.=" FROM ".MAIN_DB_PREFIX."actioncomm_resources"; $sql.=" WHERE element_type = 'user' AND fk_actioncomm = ".$this->id; $resql2=$this->db->query($sql); if ($resql2) { + $this->userassigned=array(); + + // If owner is known, we must but id first into list + if ($this->userownerid > 0) $this->userassigned[$this->userownerid]=array('id'=>$this->userownerid); // Set first so will be first into list. + while ($obj = $this->db->fetch_object($resql2)) { $this->userassigned[$obj->fk_element]=array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency); diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 44d1e209694..67d27de66a5 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -484,10 +484,12 @@ if ($resql) $event->type_code=$obj->code; $event->libelle=$obj->label; $event->percentage=$obj->percent; - $event->author->id=$obj->fk_user_author; // user id of creator - $event->usertodo->id=$obj->fk_user_action; // user id of owner - $event->userdone->id=$obj->fk_user_done; // deprecated - // $event->userstodo=... with s after user, in future version, will be an array with all id of user assigned to event + //$event->author->id=$obj->fk_user_author; // user id of creator + $event->authorid=$obj->fk_user_author; // user id of creator + $event->userownerid=$obj->fk_user_action; // user id of owner + $event->fetch_userassigned(); // This load $event->userassigned + //$event->usertodo->id=$obj->fk_user_action; // user id of owner + //$event->userdone->id=$obj->fk_user_done; // deprecated $event->priority=$obj->priority; $event->fulldayevent=$obj->fulldayevent; $event->location=$obj->location; @@ -1132,19 +1134,19 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa { if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { - $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); + $keysofuserassigned=array_keys($event->userassigned); + + $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); // Define $color and $cssclass of event $color=-1; $cssclass=''; $colorindex=-1; - if ((! empty($event->author->id) && $event->author->id == $user->id) - || (! empty($event->usertodo->id) && $event->usertodo->id == $user->id) - || (! empty($event->userdone->id) && $event->userdone->id == $user->id)) - { - $nummytasks++; $cssclass='family_mytasks'; + if (in_array($user->id, $keysofuserassigned)) + { + $nummytasks++; $cssclass='family_mytasks'; // TODO Set a color using user color // Must defined rule to choose color of who to use. - // event->usertodo->id will still contains user id of owner - // event->userstodo will be an array in future. + // event->ownerid will still contains user id of owner + // event->userassigned will be an array in future. // $color=$user->color; } else if ($event->type_code == 'ICALEVENT') @@ -1164,7 +1166,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa if ($color == -1) // Color was not forced. Set color according to color index. { // Define color index if not yet defined - $idusertouse=($event->usertodo->id?$event->usertodo->id:0); + $idusertouse=($event->userownerid?$event->userownerid:0); if (isset($colorindexused[$idusertouse])) { $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user @@ -1344,7 +1346,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa } else { - print 'datep=$db->jdate($obj->datep); // datep and datef are GMT date $event->datef=$db->jdate($obj->datep2); $event->type_code=$obj->code; - $event->libelle=$obj->label; // deprecated + //$event->libelle=$obj->label; // deprecated $event->label=$obj->label; $event->percentage=$obj->percent; - $event->author->id=$obj->fk_user_author; // user id of creator - $event->usertodo->id=$obj->fk_user_action; // user id of owner - $event->userdone->id=$obj->fk_user_done; // deprecated - // $event->userstodo=... with s after user, in future version, will be an array with all id of user assigned to event + //$event->author->id=$obj->fk_user_author; // user id of creator + $event->authorid=$obj->fk_user_author; // user id of creator + $event->userownerid=$obj->fk_user_action; // user id of owner + $event->fetch_userassigned(); // This load $event->userassigned + //$event->userdone->id=$obj->fk_user_done; // deprecated $event->priority=$obj->priority; $event->fulldayevent=$obj->fulldayevent; $event->location=$obj->location; @@ -412,8 +413,8 @@ if ($resql) $event->socid=$obj->fk_soc; $event->contactid=$obj->fk_contact; - $event->societe->id=$obj->fk_soc; - $event->contact->id=$obj->fk_contact; + //$event->societe->id=$obj->fk_soc; // deprecated + //$event->contact->id=$obj->fk_contact; // deprecated // Defined date_start_in_calendar and date_end_in_calendar property // They are date start and end of action but modified to not be outside calendar view. @@ -424,7 +425,7 @@ if ($resql) else $event->date_end_in_calendar=$event->datep; } else - { + { $event->date_start_in_calendar=$event->datep; if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef; else $event->date_end_in_calendar=$event->datep; @@ -442,7 +443,7 @@ if ($resql) // This record is out of visible range } else - { + { if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow; if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow; @@ -598,6 +599,9 @@ else $usernames = $tmpgroup->listUsersForGroup(); } +// Load array of colors by type +// TODO +$colorsbytype=array(); // Loop on each user to show calendar $sav = $tmpday; @@ -608,6 +612,7 @@ foreach ($usernames as $username) echo '' . $username->getNomUrl(1). ''; $tmpday = $sav; + // Lopp on each day of week $i = 0; for ($iter_day = 0; $iter_day < 7; $iter_day++) { @@ -631,7 +636,7 @@ foreach ($usernames as $username) if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1; if ($today) $style='cal_today_peruser'; - show_day_events2($username, $tmpday, $month, $year, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader); + show_day_events2($username, $tmpday, $month, $year, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype); $i++; } @@ -721,8 +726,9 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array(); $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day); - $nextindextouse=count($colorindexused); // At first run this is 0, so fist user has 0, next 1, ... + $nextindextouse=count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ... + // We are in a particular day for $username, now we scan all events foreach ($eventarray as $daykey => $notused) { $annee = date('Y',$daykey); @@ -733,17 +739,18 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & //Tout les events à la même date : foreach ($eventarray[$daykey] as $index => $event) { - if ($username->id != $event->usertodo->id) continue; // We discard record if event is from another user than user we want to show + $keysofuserassigned=array_keys($event->userassigned); + if (! in_array($username->id,$keysofuserassigned)) continue; // We discard record if event is from another user than user we want to show + //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); // Define $color and $cssclass of event $color=-1; $cssclass=''; $colorindex=-1; - if ((! empty($event->author->id) && $event->author->id == $user->id) - || (! empty($event->usertodo->id) && $event->usertodo->id == $user->id) - || (! empty($event->userdone->id) && $event->userdone->id == $user->id)) + if (in_array($user->id, $keysofuserassigned)) { $nummytasks++; $cssclass='family_mytasks'; + // TODO Set color according to event type } else if ($event->type_code == 'ICALEVENT') { @@ -765,7 +772,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & if ($color == -1) // Color was not forced. Set color according to color index. { // Define color index if not yet defined - $idusertouse=($event->usertodo->id?$event->usertodo->id:0); + $idusertouse=($event->userownerid?$event->userownerid:0); if (isset($colorindexused[$idusertouse])) { $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0233706928c..5047d493f08 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1318,7 +1318,9 @@ class Form { $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); } - if (count($assignedtouser) && $action != 'view') $out.='
'; + $numassignetouser=count($assignedtouser); + + if ($numassignetouser && $action != 'view') $out.='
'; $i=0; $ownerid=0; foreach($assignedtouser as $key => $value) { @@ -1326,7 +1328,7 @@ class Form $userstatic->fetch($value['id']); $out.=$userstatic->getNomUrl(1); if ($i == 0) { $ownerid = $value['id']; $out.=' ('.$langs->trans("Owner").')'; } - if ($i > 0 && $action != 'view') $out.=' '; + if ($numassignetouser > 1 && $action != 'view') $out.=' '; //$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional")); //$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy")); $out.='
';