public function findDepartmentName($comp_code = null) { //function to find all company name App::import("Model", "Departments"); $model = new Departments(); $query = $model->find('list', array('fields' => array('dept_code', 'dept_name'), 'conditions' => array('comp_code' => $comp_code))); if (empty($query)) { return 0; } else { return $query; } }
public function updateDepartment() { $validator = Validator::make(Input::all(), array('name' => 'required', 'id' => 'required', 'shortname' => 'required', 'head' => 'required', 'description' => 'required', 'facultyId' => 'required|numeric')); if ($validator->fails()) { // If not inform user of errors. return Response::json(array('success' => false, 'errors' => $validator->messages())); } else { // Check user has permission to create department. if (Auth::user()->rank == 3) { // Load the Department. $department = Departments::find(Input::get('id')); // Save changes. $department->departmentname = Input::get('name'); $department->departmentshort = Input::get('shortname'); $department->departmenthead = Input::get('head'); $department->departmentdescription = Input::get('description'); $department->facultyid = Input::get('facultyId'); $department->save(); // If not inform user of errors. return Response::json(array('success' => true)); } } }
/** * Function that updates specified department. */ protected function updateDepartment($id, $expected) { if ($expected) { $response = $this->call('POST', '/account/update-department', ['name' => 'phpunitDepartment123', 'shortname' => 'phpunitDepartment', 'head' => 'headofdepartment', 'description' => str_random(60), 'facultyId' => 1, 'id' => $id]); $json = json_decode($response->getContent()); $this->assertEquals(true, $json->success); // Verify that the change was made. $d = Departments::find($id); $this->assertEquals('phpunitDepartment123', $d->departmentname); return $d; } else { $response = $this->call('POST', '/account/update-department', ['name' => 'phpunitDepartment123', 'shortname' => 'phpunitDepartment', 'head' => 'headofdepartment', 'description' => str_random(60), 'facultyId' => 'one', 'id' => $id]); $json = json_decode($response->getContent()); $this->assertEquals(false, $json->success); } }
public function loadClass() { // Get the Class and it's students. $class = Classes::where('classId', Input::get('classId'))->first(); $studentIds = json_decode($class->classstudents); $students = array(); // Loop through all studentIds and get relevant info. foreach ($studentIds as $s) { // Get current student. $user = User::find($s); // Save name and username. $name = $user->name; $username = $user->username; $email = $user->email; // Get the major. $major = Departments::find($user->department)->name(); // Push to students array. array_push($students, array('id' => $s, 'name' => $name, 'username' => $username, 'major' => $major, 'email' => $email)); } return Response::json(array('success' => true, 'limit' => $class->classlimit, 'space' => $class->classlimit - $class->classcurrent, 'students' => $students)); }