diff --git a/include/class.thread.php b/include/class.thread.php index f6dffd7a88b3fd9436c6bc9b530563ac6186547a..532a100f5e608c5c868d59a877e1be4762845d6e 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -278,12 +278,53 @@ implements Searchable { function getReferral($id, $type) { return $this->referrals->findFirst(array( - 'object_id' => $id, - 'object_type' => $type)); + 'object_id' => $id, + 'object_type' => $type)); + } + + function isReferred($to=null, $strict=false) { + + if (is_null($to)) + return ($this->referrals); + + switch (true) { + case $to instanceof Staff: + // Referred to the staff + if ($this->getReferral($to->getId(), + ObjectModel::OBJECT_TYPE_STAFF)) + return true; + + // Strict check only checks the Agent + if ($strict) + return false; + + // Referred to staff's department + if ($this->referrals->findFirst(array( + 'object_id__in' => $to->getDepts(), + 'object_type' => ObjectModel::OBJECT_TYPE_DEPT))) + return true; + // Referred to staff's team + if ($this->referrals->findFirst(array( + 'object_id__in' => $to->getTeams(), + 'object_type' => ObjectModel::OBJECT_TYPE_TEAM))) + return true; + break; + case $to instanceof Dept: + // Refered to the dept + if ($this->getReferral($to->getId, + ObjectModel::OBJECT_TYPE_DEPT)) + return true; + break; + } + + return false; } function refer($to) { + if ($this->isReferred($to, true)) + return true; + $vars = array('thread_id' => $this->getId()); switch (true) { case $to instanceof Staff: diff --git a/include/class.ticket.php b/include/class.ticket.php index d98d504a31674148620afab39f66a5eb3ae427bb..c73b897fac858dbc4e719044cef0ce1639141503 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -286,8 +286,7 @@ implements RestrictedAccess, Threadable, Searchable { && $this->isOpen() && $staff->getId() != $this->getStaffId() && !$staff->isTeamMember($this->getTeamId()) - && !$this->thread->getReferral($staff->getId(), - ObjectModel::OBJECT_TYPE_STAFF) + && !$this->thread->isReferred($staff) ) { return false; }