public function getInstructor_assignments() { return InstructorAssignment::model()->findAllBySql('select instructor_assignment.* from instructor_assignment left join class_info on instructor_assignment.class_id = class_info.id where instructor_assignment.instructor_id = :iid and class_info.session_id = :sid', array('sid' => ClassSession::savedSessionId(), 'iid' => $this->id)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. */ public function loadModel() { if ($this->_model === null) { if (isset($_GET['instructor_id']) && isset($_GET['class_id'])) { // XXX this is stupid and tedious. fix. $this->_model = InstructorAssignment::model()->findbyPk(array('instructor_id' => $_GET['instructor_id'], 'class_id' => $_GET['class_id'])); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
public static function copyClass($old_cid, $new_sid) { $transaction = Yii::app()->db->beginTransaction(); try { /* XXX I HATE ACTIVERECORD HATE HATE HATE this stupid hack required in order to override the "default scope" which isn't actually default, it's REQUIRED, there's no way to override it, and all findbypks fail. */ $old = self::model()->findBySql('select class_info.* from class_info where id = :cid', array('cid' => $old_cid)); if (!isset($old)) { return false; } $new = new self(); $new->attributes = $old->attributes; $new->session_id = $new_sid; // by default, if i'm copying it, it's not new anymore! // and i'll assume it's active $new->status = 'Active'; if ($new->save()) { foreach ($old->instructor_assignments as $oa) { $na = new InstructorAssignment(); $na->attributes = $oa->attributes; $na->class_id = $new->id; $na->save(); } foreach ($old->extra_fees as $of) { $nf = new ExtraFee(); $nf->attributes = $of->attributes; $nf->class_id = $new->id; $nf->save(); } } $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); // TODO: report the error somehow! flash? } return true; }