/** * Associate the student with the provided terms. * * @since 0.1 * * @param array $terms * * @return bool */ public function associateWithTerms(array $terms) { $dbw = wfGetDB(DB_MASTER); $success = true; $dbw->begin(); foreach ($terms as $term) { $success = $dbw->insert('ep_students_per_term', array('spt_student_id' => $this->getId(), 'spt_term_id' => $term->getId())) && $success; } $dbw->commit(); foreach ($terms as $term) { EPCourse::updateSummaryFields('students', array('id' => $term->getField('course_id'))); EPOrg::updateSummaryFields('students', array('id' => $term->getField('org_id'))); EPTerm::updateSummaryFields('students', array('id' => $this->getId())); } return $success; }
/** * (non-PHPdoc) * @see EPDBObject::updateInDB() */ protected function updateInDB() { if ($this->updateSummaries) { $oldOrgId = $this->hasField('org_id') ? self::selectFieldsRow('org_id', array('id' => $this->getId())) : false; $oldCourseId = $this->hasField('course_id') ? self::selectFieldsRow('course_id', array('id' => $this->getId())) : false; } if ($this->hasField('course_id')) { $oldCourseId = self::selectFieldsRow('course_id', array('id' => $this->getId())); if ($this->getField('course_id') !== $oldCourseId) { $this->setField('org_id', EPCourse::selectFieldsRow('org_id', array('id' => $this->getField('course_id')))); } } $success = parent::updateInDB(); if ($this->updateSummaries && $success) { if ($oldOrgId !== false && $oldOrgId !== $this->getField('org_id')) { $conds = array('id' => array($oldOrgId, $this->getField('org_id'))); EPOrg::updateSummaryFields(array('terms', 'students', 'active'), $conds); } if ($oldCourseId !== false && $oldCourseId !== $this->getField('org_id')) { $conds = array('id' => array($oldCourseId, $this->getField('course_id'))); EPCourse::updateSummaryFields(array('active', 'students'), $conds); } } return $success; }