Merge pull request #14520 from TobiasSekan/ShowUserOnExternalCalenderEvents
NEW Show user on external calender events (when found)
This commit is contained in:
commit
9f8d1f0e63
@ -1061,12 +1061,21 @@ if (count($listofextcals))
|
||||
$event->id = $icalevent['UID'];
|
||||
$event->ref = $event->id;
|
||||
|
||||
$userId = $userstatic->findUserIdByEmail($namecal);
|
||||
if (!empty($userId) && $userId > 0)
|
||||
{
|
||||
$event->userassigned[$userId] = $userId;
|
||||
$event->percentage = -1;
|
||||
}
|
||||
else {
|
||||
$event->type_code = "ICALEVENT";
|
||||
}
|
||||
|
||||
$event->icalname = $namecal;
|
||||
$event->icalcolor = $colorcal;
|
||||
$usertime = 0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
|
||||
$event->datep = $datestart + $usertime;
|
||||
$event->datef = $dateend + $usertime;
|
||||
$event->type_code = "ICALEVENT";
|
||||
|
||||
if ($icalevent['SUMMARY']) $event->label = $icalevent['SUMMARY'];
|
||||
elseif ($icalevent['DESCRIPTION']) $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
|
||||
|
||||
@ -3236,5 +3236,65 @@ class User extends CommonObject
|
||||
$this->errors[] = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the SQL results of the function "findUserIdByEmail($email)"
|
||||
*
|
||||
* NOTE: findUserIdByEmailCache[...] === -1 means not found in database
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $findUserIdByEmailCache;
|
||||
|
||||
/**
|
||||
* Find a user by the given e-mail and return it's user id when found
|
||||
*
|
||||
* NOTE:
|
||||
* Use AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR
|
||||
* to disable exact e-mail search
|
||||
*
|
||||
* @param string $email The full e-mail (or a part of a e-mail)
|
||||
* @return int <0 = user was not found, >0 = The id of the user
|
||||
*/
|
||||
public function findUserIdByEmail($email)
|
||||
{
|
||||
if ($this->findUserIdByEmailCache[$email])
|
||||
{
|
||||
return $this->findUserIdByEmailCache[$email];
|
||||
}
|
||||
|
||||
$this->findUserIdByEmailCache[$email] = -1;
|
||||
|
||||
global $conf;
|
||||
|
||||
$sql = 'SELECT rowid';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'user';
|
||||
|
||||
if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR))
|
||||
{
|
||||
$sql .= ' WHERE email LIKE "%'.$email.'%"';
|
||||
}
|
||||
else {
|
||||
$sql .= ' WHERE email = "'.$email.'"';
|
||||
}
|
||||
|
||||
$sql .= ' LIMIT 1';
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if (!$obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
|
||||
|
||||
return $this->findUserIdByEmailCache[$email];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user