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; }
/** * Creates a new Resource. * If creation is successful, the browser will be redirected to the 'view' page. * @param $type */ public function actionAdd($type) { if ($type == 'employee') { $model = new Employees(); } else { if ($type == 'hardware') { $model = new Hardware(); } else { if ($type == 'facilities') { $model = new Facilities(); } } } if (isset($_POST['Employees']) || isset($_POST['Hardware']) || isset($_POST['Facilities'])) { if (get_class($model) == Employees) { $model->attributes = $_POST['Employees']; $model->e_type = Resources::getResourceIdByName($_POST['Employees']['e_type'], Resources::EMPLOYMENT_TYPES_DB); } else { if (get_class($model) == Hardware) { $model->attributes = $_POST['Hardware']; $model->h_type = Resources::getResourceIdByName($_POST['Hardware']['h_type'], Resources::HARDWARE_TYPES_DB); } else { if (get_class($model) == Facilities) { $model->attributes = $_POST['Facilities']; $model->f_type = Resources::getResourceIdByName($_POST['Facilities']['f_type'], Resources::FACILITY_TYPES_DB); } } } if ($model->save()) { $this->redirect(array('/resources')); } } else { $this->render('createResource', array('model' => $model)); } }