public function execute() { $departmentId = $_REQUEST['department']; if (is_null($departmentId) || !isset($departmentId)) { throw new \InvalidArgumentException('Missing department id.'); } $department = DepartmentFactory::getDepartmentById($departmentId); $faculty = FacultyFactory::getFacultyByDepartmentAssoc($department); echo json_encode($faculty); exit; // Exit since this is called by JSON }
public function execute() { // Check permissions if (!\Current_User::allow('intern', 'create_internship')) { \NQ::simple('intern', NotifyUI::ERROR, 'You do not have permission to create new internships.'); \NQ::close(); \PHPWS_Core::home(); } // Get a list of any missing input the user didn't fill in $missingFieldList = $this->checkForMissingInput(); // If there are missing fields, redirect to the add internship interface if (!empty($missingFieldList)) { $this->redirectToForm(); } // Check that the student Id looks valid $studentId = $_POST['studentId']; // Get the term // TODO Double check that this is reasonable $term = $_POST['term']; // Create the student object $student = StudentProviderFactory::getProvider()->getStudent($studentId, $term); // Get the department ojbect $departmentId = preg_replace("/^_/", '', $_POST['department']); // Remove leading underscore in department id $department = DepartmentFactory::getDepartmentById($departmentId); if (!$department instanceof Department) { throw new \Exception('Could not load department.'); } // Create and save the agency object $agency = new Agency($_POST['agency']); DatabaseStorage::save($agency); // Get the location $location = $_POST['location']; if ($location == 'international') { $state = null; $country = $_POST['country']; } else { $state = $_POST['state']; $country = null; } // Create a new internship object $intern = new Internship($student, $term, $location, $state, $country, $department, $agency); // Save it!! $intern->save(); $t = \Intern\WorkflowTransitionFactory::getTransitionByName('Intern\\WorkflowTransition\\CreationTransition'); $workflow = new \Intern\WorkflowController($intern, $t); $workflow->doTransition(null); $workflow->doNotification(null); // Show a success notice and redirect to the edit page \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "Created internship for {$intern->getFullName()}"); \NQ::close(); return \PHPWS_Core::reroute('index.php?module=intern&action=ShowInternship&internship_id=' . $intern->getId()); }