Esempio n. 1
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.
  * @param integer the ID of the model to be loaded
  */
 public static function loadModelByPid($type, $id)
 {
     if ($type == 'Employees') {
         $model = EmployeeSchedule::model()->findAllByAttributes(array('pid' => $id));
     } elseif ($type == 'Hardware') {
         $model = HardwareSchedule::model()->findAllByAttributes(array('pid' => $id));
     } elseif ($type == 'Facilities') {
         $model = FacilitySchedule::model()->findAllByAttributes(array('pid' => $id));
     } elseif ($type == 'CustomResources') {
         $model = CustomResources::model()->findAllByAttributes(array('pid' => $id));
     }
     return $model;
 }
Esempio n. 2
0
 /**
  * Updates a particular Resource-Schedule-model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $critearia = new CDbCriteria();
     $critearia->addCondition("pid = " . $id);
     $projectId = $_GET['id'];
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     //	if(isset($_POST['EmployeeSchedule0']) || isset($_POST['HardwareSchedule']) || isset($_POST['FacilitiesSchedule']) || isset($_POST['CustomResources0']))
     if ($_POST) {
         $ecounter = 0;
         $hcounter = 0;
         $fcounter = 0;
         $ccounter = 0;
         foreach ($_POST as $key => $value) {
             $type = $key;
             if ($type == 'EmployeeSchedule' . $ecounter) {
                 $resource = EmployeeSchedule::model()->findByPk((int) $value['id']);
                 $resource->attributes = $_POST[$key];
                 $ecounter++;
             } elseif ($type == 'HardwareSchedule' . $hcounter) {
                 $resource = HardwareSchedule::model()->findByPk((int) $value['id']);
                 $resource->attributes = $_POST[$key];
                 $hcounter++;
             } elseif ($type == 'FacilitiesSchedule' . $fcounter) {
                 $resource = FacilitySchedule::model()->findByPk((int) $value['id']);
                 $resource->attributes = $_POST[$key];
                 $fcounter++;
             } elseif ($type == 'CustomResources' . $ccounter) {
                 $resource = CustomResources::model()->findByPk((int) $value['id']);
                 $resource->attributes = $_POST[$key];
                 $ccounter++;
             }
             if ($value['delete']) {
                 $resource->delete();
             } else {
                 $resource->save();
             }
         }
         $this->redirect(array('project/view', 'id' => $projectId));
     }
     $this->render('update', array('employee' => EmployeeSchedule::model()->findAll($critearia), 'hardware' => HardwareSchedule::model()->findAll($critearia), 'facility' => FacilitySchedule::model()->findAll($critearia), 'customResources' => CustomResources::model()->findAll($critearia)));
 }