/** * 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; }
public static function findAvailableHardwareResource($resourceDb, $start, $end, $name) { //CHECK WETHER THERE IS A RESOURCE OF TYPE $type LEFT (COUNT $booked AGAINST $available??? // NEEDED: // -NR. OF RESOURCES OF TYPE $type // -NR OF RESOUCRES LEFT AFTER SUBTRACTING $booked // -ASSIGN A RESOURCE_ID IF POSSIBLE $hid = 0; $id = Resources::getResourceIdByName($name, $resourceDb); $numberOfResources = HardwareSchedule::getNrOfAvailableResources($id); $reservedResources = HardwareSchedule::getNrOfReservedHardwareResources($start, $end, $id); if ($numberOfResources - $reservedResources > 0) { $hid = HardwareSchedule::getBookableHardwareResources($start, $end, $id); } else { $error = Yii::app()->clientScript; $error->registerScript('error', 'alert("No resource ' . $name . ' Available!");', CClientScript::POS_READY); } return $hid; }
/** * 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))); }
echo '<div class="row">'; $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array('name' => 'EmployeeSchedule' . $counter . '[start_date]', 'model' => $emp, 'value' => $emp->start_date, 'htmlOptions' => array('size' => 18, 'class' => 'date'), 'options' => array('hourGrid' => 4, 'hourMin' => 8, 'hourMax' => 18, 'timeFormat' => 'h:m', 'changeMonth' => true, 'changeYear' => false, 'dateFormat' => 'yy-mm-dd', 'timeFormat' => 'hh:mm:ss', 'showAnim' => 'fold'))); echo '<b> to </b>'; $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array('name' => 'EmployeeSchedule' . $counter . '[end_date]', 'model' => $emp, 'value' => $emp->start_date, 'htmlOptions' => array('size' => 18, 'class' => 'date'), 'options' => array('hourGrid' => 4, 'hourMin' => 9, 'hourMax' => 18, 'timeFormat' => 'h:m', 'changeMonth' => true, 'changeYear' => false, 'dateFormat' => 'yy-mm-dd', 'timeFormat' => 'hh:mm:ss', 'showAnim' => 'fold'))); echo '<input type="checkbox" name="EmployeeSchedule' . $counter . '[delete]" value="delete" />delete'; echo '</div>'; echo '<br />'; $counter++; } ?> <h3>Hardware</h3> <?php $counter = 0; foreach ($hardware as $hard) { echo '<div class="row"><label for="name">'; echo HardwareSchedule::getResourceName($hard->hardware_id) . '<br />'; echo '<input type="hidden" id="HardwareSchedule' . $counter . '[id]" value="' . $hard->id . '" name="HardwareSchedule' . $counter . '[id]" /><br />'; echo '</label>'; echo '</div>'; echo '<div class="row">'; $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array('name' => 'HardwareSchedule' . $counter . '[start_date]', 'model' => $emp, 'value' => $emp->start_date, 'htmlOptions' => array('size' => 18, 'class' => 'date'), 'options' => array('hourGrid' => 4, 'hourMin' => 8, 'hourMax' => 18, 'timeFormat' => 'h:m', 'changeMonth' => true, 'changeYear' => false, 'dateFormat' => 'yy-mm-dd', 'timeFormat' => 'hh:mm:ss', 'showAnim' => 'fold'))); echo '<b> to </b>'; $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array('name' => 'HardwareSchedule' . $counter . '[end_date]', 'model' => $emp, 'value' => $emp->start_date, 'htmlOptions' => array('size' => 18, 'class' => 'date'), 'options' => array('hourGrid' => 4, 'hourMin' => 9, 'hourMax' => 18, 'timeFormat' => 'h:m', 'changeMonth' => true, 'changeYear' => false, 'dateFormat' => 'yy-mm-dd', 'timeFormat' => 'hh:mm:ss', 'showAnim' => 'fold'))); echo '<input type="checkbox" name="HardwareSchedule' . $counter . '[delete]" value="delete" />delete'; echo '</div>'; $counter++; } ?> <h3>Facilities</h3> <?php $counter = 0;