/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new InstructorAssignment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['InstructorAssignment'])) {
         $model->attributes = $_POST['InstructorAssignment'];
         if ($model->save()) {
             $this->redirect(array('view', 'instructor_id' => $model->instructor_id, 'class_id' => $model->class_id));
         }
     }
     if (isset($_GET['instructor_id'])) {
         $model->instructor_id = $_GET['instructor_id'];
     }
     if (isset($_GET['class_id'])) {
         $model->class_id = $_GET['class_id'];
         $model->percentage = $model->class->instructor_discrepancy;
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
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;
 }