示例#1
0
 /**
  * (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;
 }