/** * Create and load data for the objects used for this form. * * Create the list object and if this is a form submission load * the data from the form data. It determines the type based on the * {@link $type} member variable. */ protected function loadObjects() { $this->student_registration = STS_PageFormPerson::load_current_registration($this->request("parent")); ###Deny drop semester for completed students### $progObj = $this->factory->createContainer($this->student_registration["training_program"]); $progObj->populate(); if ($this->student_registration["admission_type"] == "admission_type|full-time") { $total_semesters = $progObj->getField("total_semesters_fulltime")->getDBValue(); } else { if ($this->student_registration["admission_type"] == "admission_type|part-time") { $total_semesters = $progObj->getField("total_semesters_parttime")->getDBValue(); } } $completed = IHS_PageFormEnrollcourse::completed_school($this->student_registration["semester"], $total_semesters, $this->request("parent")); if ($completed) { $this->userMessage("You Have Completed The Program"); $this->setRedirect("view?id=" . $this->request("parent")); return; } ###End of denying drop semester for completed students### //check to ensure That A Student Must Resume Before Next Drop if ($this->get_exists("parent")) { $parent = $this->request("parent"); $persObj = $this->factory->createContainer($parent); $persObj->populateChildren("drop_semester"); foreach ($persObj->getChildren("drop_semester") as $dropSemObj) { if ($dropSemObj->getField("registration")->getDBValue() != $this->student_registration["id"]) { continue; } $dropSemObj->populateChildren("resume_semester"); $resSemObj = $dropSemObj->getChildren("resume_semester"); if (count($resSemObj) == 0) { $this->userMessage("This Student Is Currently Dropped In A Semester"); $this->setRedirect("view?id=" . $parent); return; } } //avoid a student to drop a semester when GPA is already there $persObj->populateChildren("registration"); $regObjs = $persObj->getChildren("registration"); foreach ($regObjs as $regObj) { if ($regObj->getField("registration_status")->getDBValue() != "registration_status|ongoing") { continue; } $semester = $regObj->getField("semester")->getDBValue(); } $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $semester)), 1 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $parent)), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $this->student_registration["id"])))); $semGPA = I2CE_FormStorage::search("semester_GPA", false, $where); if (count($semGPA) > 0) { $this->userMessage("You Cant Drop This Semester"); $this->setRedirect("view?id=" . $parent); return; } } if ($this->isPost()) { $primary = $this->factory->createContainer($this->getForm()); if (!$primary instanceof I2CE_Form) { return false; } $primary->load($this->post); } elseif ($this->get_exists('id')) { if ($this->get_exists('id')) { $id = $this->get('id'); if (strpos($id, '|') === false) { I2CE::raiseError("Deprecated use of id variable"); $id = $this->getForm() . '|' . $id; } } else { $id = $this->getForm() . '|0'; } $primary = $this->factory->createContainer($id); if (!$primary instanceof I2CE_Form || $primary->getName() != $this->getForm()) { I2CE::raiseError("Could not create valid " . $this->getForm() . "form from id:{$id}"); return false; } $primary->populate(); } elseif ($this->get_exists('parent')) { $primary = $this->factory->createContainer($this->getForm()); if (!$primary instanceof I2CE_Form) { return; } $parent = $this->get('parent'); if (strpos($parent, '|') === false) { I2CE::raiseError("Deprecated use of parent variable"); $parent = 'person|' . $parent; } $primary->setParent($parent); } if ($this->isGet()) { $primary->load($this->get()); } $person = parent::loadPerson($primary->getParent()); if (!$person instanceof iHRIS_Person) { I2CE::raiseError("Could not create person form from " . $primary->getParent()); return; } $this->applyLimits($primary); $this->setObject($primary, I2CE_PageForm::EDIT_PRIMARY, null, true); $this->setObject($person, I2CE_PageForm::EDIT_PARENT, null, true); return true; }
/** * Save the objects to the database. * * Save the default object being edited and return to the view page. * @global array */ protected function save() { $persObj = $this->factory->createContainer("person"); $persObj->load($this->post); $person_id = $persObj->getField("id")->getDBValue(); $person_id = explode("|", $person_id); $person_id = $person_id[1]; $regObj = $this->factory->createContainer("registration"); $regObj->load($this->post); $registration_number = $regObj->getField("registration_number")->getDBValue(); $training_institution = $regObj->getField("training_institution")->getDBValue(); //save the new reg_number to institution form if ($person_id == 0) { $instObj = $this->factory->createContainer($training_institution); $instObj->populate(); $reg_num = explode("-", $registration_number); $reg_num = $reg_num[2]; $instObj->getField("last_reg_num")->setValue($reg_num); $instObj->save($this->user); $userObj = $this->factory->createContainer("user" . '|' . $registration_number); $userObj->getField("username")->setFromPost($registration_number); $userObj->getField("firstname")->setFromPost($persObj->getField("firstname")->getDBValue()); $userObj->getField("lastname")->setFromPost($persObj->getField("surname")->getDBValue()); $userObj->getField("role")->setFromDB("role|student"); $userObj->getField("password")->setFromPost($persObj->getField("surname")->getDBValue()); $userObj->save($this->user); } $persObj->save($this->user); $person_id = $persObj->getID(); $regObj->setParent("person|" . $person_id); $regObj->save($this->user); $message = "This record has been saved."; I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_save"); $this->userMessage($message); if ($this->generated_regnum) { $ff = I2CE_FormFactory::instance(); $usermapObj = $ff->createContainer("user_map"); $usermapObj->getField("username")->setFromDB("user|" . $registration_number); $usermapObj->getField("parent")->setFromDB("person|" . $person_id); $usermapObj->save($this->user); } //register core courses for this students IHS_PageFormEnrollcourse::enroll_core_courses("person|" . $person_id); $this->setRedirect("view?id=person|" . $person_id); }