/** * Saves a hub contact * * @apiMethod POST * @apiUri /time/saveContact * @apiParameter { * "name": "name", * "description": "Contact name", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "phone", * "description": "Contact phone", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "email", * "description": "Contact email", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "role", * "description": "Contact role", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "hid", * "description": "Hub id to which the contact belongs", * "type": "integer", * "required": true, * "default": null * } * @return void */ public function saveContactTask() { // Require authentication and authorization $this->requiresAuthentication(); $this->authorizeOrFail(); // Incoming posted data (grab individually for added security) $c = []; $c['name'] = Request::getString('name'); $c['phone'] = Request::getString('phone'); $c['email'] = Request::getString('email'); $c['role'] = Request::getString('role'); $c['hub_id'] = Request::getInt('hid'); // Create object and store new content $contact = Contact::blank()->set($c); if (!$contact->save()) { App::abort(500, 'Contact creation failed'); } // Return message (include $contact object for use again by the javascript) $this->send($contact->id, 201); }
/** * Delete a contact * * @return void */ public function deletecontactTask() { $contact = Contact::oneOrFail(Request::getInt('id')); // Get the hub id for the return $hid = $contact->hub_id; // Delete the contact $contact->destroy(); // Set the redirect App::redirect(Route::url($this->base . '&task=edit&id=' . $hid), Lang::txt('COM_TIME_HUBS_CONTACT_DELETE_SUCCESSFUL'), 'passed'); }