Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 /**
  * 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['id'])) {
             $this->_model = ExtraFee::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }