/** * Assigns a ticket to a user or returns an error message. * It will first check if the ticket isn't already assigned, if not, it will create a new 'assigned' entry. * @param $user_id the id of the user we want to assign to the ticket * @param $ticket_id the id of the ticket. * @return A string, if assigning succeedded "SUCCESS_ASSIGNED" will be returned, else "ALREADY_ASSIGNED" will be returned. */ public static function assignTicket($user_id, $ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is already assigned, if so return "ALREADY ASSIGNED" if (!Assigned::isAssigned($ticket_id)) { $assignation = new Assigned(); $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); $assignation->create(); return "SUCCESS_ASSIGNED"; } else { return "ALREADY_ASSIGNED"; } }
public function run() { Assigned::truncate(); Assigned::create(['id' => '1', 'user_id' => '1', 'role_id' => '3']); Assigned::create(['id' => '2', 'user_id' => '2', 'role_id' => '2']); Assigned::create(['id' => '3', 'user_id' => '3', 'role_id' => '1']); // FOR TESTING PURPOSES Assigned::create(['id' => '4', 'user_id' => '4', 'role_id' => '2']); Assigned::create(['id' => '5', 'user_id' => '5', 'role_id' => '2']); Assigned::create(['id' => '6', 'user_id' => '6', 'role_id' => '2']); Assigned::create(['id' => '7', 'user_id' => '7', 'role_id' => '2']); Assigned::create(['id' => '8', 'user_id' => '8', 'role_id' => '1']); }