Assignation of event to several users is on a very good way for 3.7

This commit is contained in:
Laurent Destailleur 2014-09-26 12:27:18 +02:00
parent 396bae21d6
commit bf4b99fa64
5 changed files with 67 additions and 41 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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 '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?maxprint=0&month='.$monthshown.'&year='.$year;
print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action='.$action.'&maxprint=0&month='.$monthshown.'&year='.$year;
print ($status?'&status='.$status:'').($filter?'&filter='.$filter:'');
print ($filtera?'&filtera='.$filtera:'').($filtert?'&filtert='.$filtert:'').($filterd?'&filterd='.$filterd:'');
print ($actioncode!=''?'&actioncode='.$actioncode:'');

View File

@ -398,13 +398,14 @@ if ($resql)
$event->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 '<td class="cal_current_month">' . $username->getNomUrl(1). '</td>';
$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

View File

@ -1318,7 +1318,9 @@ class Form
{
$assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
}
if (count($assignedtouser) && $action != 'view') $out.='<br>';
$numassignetouser=count($assignedtouser);
if ($numassignetouser && $action != 'view') $out.='<br>';
$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.=' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
if ($numassignetouser > 1 && $action != 'view') $out.=' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
$out.='<br>';