/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return AwayMentor the loaded model * @throws CHttpException */ public function loadModel($id) { $model = AwayMentor::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function reassignTicket($domain_id, $sub, $oldMentorId, $tier, $ticket_id) { /*Query to the User_Domain model */ $awayMentors = AwayMentor::model()->findAllBySql("SELECT * FROM away_mentor"); if ($sub) { $userDomain = UserDomain::model()->findAllBySql("SELECT * FROM user_domain left join (select assign_user_id, assigned_date from (select * from ticket order by assigned_date desc)x group by assign_user_id)x on assign_user_id = user_id WHERE subdomain_id =:id and user_id !=:id2 and user_id not in (select userID as user_id from away_mentor) and user_id not in (select old_value as user_id from ticket_events where ticket_id =:tid and event_type_id = 3) order by assigned_date ASC ", array(":id" => $domain_id, ":id2" => $oldMentorId, ":tid" => $ticket_id)); $subdomain = Subdomain::model()->findByPk($domain_id); $validator = $subdomain->validator; } else { $userDomain = UserDomain::model()->findAllBySql("SELECT * FROM user_domain left join (select assign_user_id, assigned_date from (select * from ticket order by assigned_date desc)x group by assign_user_id)x on assign_user_id = user_id WHERE domain_id =:id and user_id !=:id2 and user_id not in (select userID as user_id from away_mentor) and user_id not in (select old_value as user_id from ticket_events where ticket_id =:tid and event_type_id = 3) order by assigned_date ASC ", array(":id" => $domain_id, ":id2" => $oldMentorId, ":tid" => $ticket_id)); $domain = Domain::model()->findByPk($domain_id); $validator = $domain->validator; } if ($userDomain != null && is_array($userDomain)) { foreach ($userDomain as $auserDomain) { /** @var UserDomain $auserDomain */ if ($auserDomain->tier_team == $tier) { if ($auserDomain->rate >= $validator) { /*Query to the domain mentor to see how many tickets is allowed to be assigned */ $domainMentor = DomainMentor::model()->findAllBySql("SELECT * FROM domain_mentor WHERE user_id =:id", array(":id" => $auserDomain->user_id)); /** @var Ticket $count */ if (is_array($domainMentor)) { foreach ($domainMentor as $adomainMentor) { /** @var DomainMentor $adomainMentor */ $count = Ticket::model()->findBySql("SELECT COUNT(id) as `id` FROM ticket WHERE assign_user_id =:id", array(":id" => $adomainMentor->user_id)); if ($count->id < $adomainMentor->max_tickets) { /*return the first available domain mentor on queue */ return $auserDomain->user_id; } } } } } } } return self::$admin; /* Assign the ticket to the admin for reassign */ }