public function getStudentById($id, $term) { PHPWS_Core::initModClass('hms', 'Student.php'); $db = new PHPWS_DB('hms_student_cache'); $db->addWhere('banner_id', $id); $db->addWhere('term', $term); $db->addWhere('timestamp', time() - $this->ttl, '>'); //$db->setTestMode(); $result = $db->select('row'); // If there's an error, fail gracefully to the fall-back provider if (PHPWS_Error::logIfError($result)) { $provider = $this->getFallbackProvider(); return $provider->getStudentById($id, $term); } // If the result was empty, use the fallback if (is_null($result)) { $provider = $this->getFallbackProvider(); $result = $provider->getStudentById($id, $term); // Refresh the cache using the result $this->refreshCache($result, $term); } else { // Do some hackery to make a CachedStudent object out of the db array $result = CachedStudent::plugData($result); self::getAddresses($result); self::getPhoneNumbers($result); $result->setDataSource(get_class($this)); } return $result; }
public static function toCachedStudent(Student $student) { $varsArray = get_object_vars($student); return CachedStudent::plugData($varsArray); }