?> <b><?php echo CHtml::encode($data->getAttributeLabel('effective_water_demand')); ?> :</b> <?php echo CHtml::encode(Math::wd_round($data->effective_water_demand) . ' ' . Yii::app()->params['water_demand_unit']); ?> <br /> <?php } ?> <?php if ($data->phase == 1 and ($data->status == WaterRequests::SW_NODE(WaterRequests::SUBMITTED_STATUS) and Yii::app()->user->isPlanner)) { echo CHtml::link(Yii::t('waterrequest', 'Move on Executive Phase'), array('waterRequests/create', 'phase' => 2, 'parent' => $data->id)); } ?> <div class="water_request_operation"> <?php if (Yii::app()->user->checkAccess('pdfWaterRequest', array('waterRequest' => $data))) { $img = CHtml::image('images/document_pdf.png'); echo CHtml::link($img, array('pdf', 'id' => $data->id), array('id' => 'pdf-link', 'title' => Yii::t('waterrequest', 'Generate PDF'))); } if (Yii::app()->user->checkAccess('epanetWaterRequest', array('waterRequest' => $data))) { $img = CHtml::image('images/document_epanet.png'); echo CHtml::link($img, array('epanet', 'id' => $data->id), array('id' => 'epanet-link', 'title' => Yii::t('waterrequest', 'Generate Epanet file'))); } ?>
/** * 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 function loadModel($id) { $model = WaterRequests::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getParentWDUsage($include_current = true) { if ($this->phase == 2 || $this->phase == 3) { $brothers = WaterRequests::model()->findAllByAttributes(array('username' => $this->user->username, 'phase' => $this->phase, 'parent_phase' => $this->parent_wr->id)); $usage = 0; foreach ($brothers as $brother) { if (!$include_current && $brother->id == $this->id) { continue; } $usage += $brother->total_water_demand; } return $usage; } return 0; }
<h1><?php echo Yii::t('waterrequest', 'Water Requests'); ?> </h1> <?php if (Yii::app()->user->isPlanner) { echo CHtml::openTag('p'); echo CHtml::link(Yii::t('waterrequest', 'Create New Water Request'), CController::createUrl('waterRequests/create')); echo CHtml::closeTag('p'); } echo CHtml::openTag('div', array('id' => 'wr_list')); // Status Filter line echo CHtml::openTag('div'); echo Yii::t('waterrequest', 'View status: '); echo CHtml::link(Yii::t('waterrequest', 'All'), 'javascript:void(0);', array('id' => 'all_wr', 'class' => $status == 'all' ? 'wr_filter_selected' : '', 'onclick' => '$.fn.yiiListView.update(\'waterRequestsList\', {data:{\'status\':\'all\', \'gridview\':view_wr_list_as_grid}});')); foreach (WaterRequests::allStatuses() as $value) { if (Yii::app()->user->canSee($value)) { echo ' | '; echo CHtml::link(ucfirst(Yii::t('waterrequest', $value)), 'javascript:void(0);', array('id' => $value . '_wr', 'class' => $status == $value ? 'wr_filter_selected' : '', 'onclick' => 'javascript: $.fn.yiiListView.update(\'waterRequestsList\', {data:{\'status\':\'' . $value . '\', \'gridview\':view_wr_list_as_grid }});')); } } ?> <span id="search_links"></span> <?php echo CHtml::closeTag('div'); echo CHtml::openTag('div', array('style' => 'float:right')); // Choose visualization type List or Grid echo CHtml::link(' ', 'javascript:void(0);', array('id' => 'wr_view_list', 'title' => Yii::t('waterrequest', 'List View'), 'class' => $gridview ? 'wr_view' : 'wr_view active', 'onclick' => '$(\'.wr_view\').removeClass(\'active\'); $(\'.water_request\').removeClass(\'square\'); $(this).addClass(\'active\'); setgridview(false);')); echo ' ';
/** * Updates a particular 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) { $geom_zone_model = $this->loadModel($id); // TODO: controllare se è un modello orfano $wr_model = WaterRequests::model()->findByPk($geom_zone_model->geometry->wr_id); if (!Yii::app()->user->checkAccess('updateWaterRequest', array('waterRequest' => $wr_model))) { throw new CHttpException(403, Yii::t('http_status', '403')); } // TODO: Gestire con ajax.error? // Yii::log("Updating $geom_zone_model->id ", CLogger::LEVEL_INFO, "Update WRG_Zones" ); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['WaterRequestGeometryZones']) && isset($_POST['WaterRequestGeometryZoneProperties'])) { //Yii::log("Into IF", CLogger::LEVEL_INFO, "Update WRG_Zones" ); // Actually assign only 'zone' $geom_zone_model->attributes = $_POST['WaterRequestGeometryZones']; if (isset($_POST['WaterRequestGeometryZoneProperties']['ae_choice'])) { $ae = $_POST['WaterRequestGeometryZoneProperties']['ae_choice']; } else { $ae = false; } $found_props_ids = array(); foreach ($_POST['WaterRequestGeometryZoneProperties'] as $param => $value) { //Yii::log("Param $param -> Value $value", CLogger::LEVEL_INFO, "Update WRG_Zones" ); if ($param != 'ae_choice' && !empty($value)) { $load_prop = WaterRequestGeometryZoneProperties::model()->find('parameter=:param AND geometry_zone=:geom_zone', array(':param' => $param, ':geom_zone' => $geom_zone_model->id)); if ($load_prop == null) { $load_prop = new WaterRequestGeometryZoneProperties(); } else { $found_props_ids[] = $load_prop->id; } //Yii::log("Caricato ".print_r($load_prop->attributes,true), CLogger::LEVEL_INFO, "Update WRG_Zones" ); $load_prop->parameter = $param; $load_prop->value = $value; // the prop is selected if ($ae == $param) { $load_prop->use4ae = true; } else { $load_prop->use4ae = false; } // append to array $sent_props[] = $load_prop; } } if (!isset($sent_props)) { echo CJSON::encode(array('status' => 'error no props sent')); return; } // check if one is selected, otherwise select the first one. $choosedProp = -1; for ($i = 0; $i < count($sent_props) && $choosedProp < 0; $i++) { if ($sent_props[$i]->use4ae) { $choosedProp = $i; } } // non ho settato nulla, cerco 'cp' if ($choosedProp < 0) { foreach ($sent_props as $geom_zone_property_model) { if ($geom_zone_property_model->parameter == 'cp') { $geom_zone_property_model->use4ae = true; } $choosedProp = 0; // NOW IT'S ONLY A FLAG (0 = found, -1 = not found) } } // 'cp' not found, set the first prop. if ($choosedProp < 0) { $sent_props[0]->use4ae = true; $choosedProp = 0; } /* // Check if use4ae is needed to be set to a specific prop if($geom_zone_model->zone_name) foreach($sent_props as $geom_zone_property_model){ $geom_zone_property_model->geometry_zone=$geom_zone_model->id; if ($geom_zone_property_model->()) { //Yii::log("Zone_name $geom_zone_model->zone_name", CLogger::LEVEL_INFO, "LOOP"); //$geom_zone_property_model->save(); //echo $geom_zone_property_model->parameter; // DEBUG }else $_propserror = true; } */ // Select all old properties to delete $all_props = WaterRequestGeometryZoneProperties::model()->findAll('geometry_zone=:geom_zone', array(':geom_zone' => $geom_zone_model->id)); foreach ($all_props as $found) { if (!in_array($found->id, $found_props_ids)) { $to_purge[] = $found->id; } } //Yii::log("Inseriti da utente ".print_r($found_props_ids,true), CLogger::LEVEL_INFO, "Update WRG_Zones" ); //if(isset($to_purge)) //Yii::log("Da eliminare ".print_r($to_purge,true), CLogger::LEVEL_INFO, "Update WRG_Zones" ); //starting new transaction $transaction = Yii::app()->db->beginTransaction(); try { $_error = true; // purge old properties if (isset($to_purge)) { foreach ($to_purge as $del_id) { WaterRequestGeometryZoneProperties::model()->findByPk($del_id)->delete(); } } //calculate pe and water demand //$geom_zone_model->pe = $geom_zone_model->calculatePE($sent_props[$choosedProp]->parameter, $sent_props[$choosedProp]->value); //$geom_zone_model->water_demand = $geom_zone_model->calculateWaterDemand(); //$geom_zone_model->updateWD(); if ($geom_zone_model->validate()) { $geom_zone_model->save(); $_propserror = false; $error_status = 'ok'; foreach ($sent_props as $geom_zone_property_model) { $geom_zone_property_model->geometry_zone = $geom_zone_model->id; if ($geom_zone_property_model->validate()) { //Yii::log("Zone_name $geom_zone_model->zone_name", CLogger::LEVEL_INFO, "LOOP"); $geom_zone_property_model->save(); //echo $geom_zone_property_model->parameter; // DEBUG } else { //Yii::log('PROPERTY MODEL NON VALIDA' , CLogger::LEVEL_INFO, 'actionUpdate'); // DEBUG //Yii::log($geom_zone_property_model->attributes , CLogger::LEVEL_INFO, 'actionUpdate'); // DEBUG //Yii::log($geom_zone_property_model->getErrors(), CLogger::LEVEL_INFO, 'actionUpdate'); // DEBUG $error_status = 'Error: '; foreach ($geom_zone_property_model->getErrors() as $attr => $err_msg) { $error_status = $error_status . $attr . ': ' . implode(',', $err_msg) . ' '; } $_propserror = true; } } if ($_propserror) { echo CJSON::encode(array('status' => $error_status)); } $_error = $_propserror; //echo 'after foreach: '.$_propserror.' '; // DEBUG } else { echo CJSON::encode(array('status' => ' error geom_zone_model non valida ')); } // DEBUG if ($_error) { $transaction->rollBack(); //echo CJSON::encode(array('status'=>'error una delle prop non valida')); } else { $transaction->commit(); echo CJSON::encode(array('status' => 'ok')); Yii::app()->end(); } } catch (Exception $e) { $transaction->rollBack(); echo CJSON::encode(array('status' => 'not inserted ' . $e)); } } //if isset... Yii::log('Something went wrong Zone=' . isset($_POST['WaterRequestGeometryZones']) . ' Property=' . isset($_POST['WaterRequestGeometryZoneProperties']), CLogger::LEVEL_INFO); Yii::app()->end(); }
/** * Check if the Geometry has an existing WaterRequest parent. * If the parent is not found, the geometry is deletted. * @param WaterRequestGeomtries the model to check * @return true if the geometry was orphan and deletted, false otherwise */ public function deleteIfOrphan($model) { $wr_model = WaterRequests::model()->findByPk($model->wr_id); if ($wr_model === null) { //orphan geometry if ($model->zones()) { foreach ($model->zones() as $zone) { if ($zone->properties()) { foreach ($zone->properties() as $property) { Yii::log("Cancello Orphan Property {$property->id}", CLogger::LEVEL_INFO, 'DELETE Geom'); $property->delete(); } } Yii::log("Cancello Orphan Zone {$zone->id}", CLogger::LEVEL_INFO, 'DELETE Geom'); $zone->delete(); } } Yii::log("Cancello Orphan Geometry {$geom_model->id}", CLogger::LEVEL_INFO, 'DELETE Geom'); $model->delete(); return true; } return false; }
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'water-requests-form', 'enableAjaxValidation' => false, 'action' => CController::createUrl('waterRequests/updateStatus', array('id' => $model->id)))); ?> <div class="row status_buttons"> <?php foreach (SWHelper::nextStatuslistData($model, false) as $k => $v) { if ($model->status === WaterRequests::SW_NODE(WaterRequests::CANCELLED_STATUS)) { echo CHtml::submitButton(Yii::t('waterrequest', 'Restore'), array('id' => 'save-button', 'name' => 'save-button', 'class' => 'restore-button')); } else { echo CHtml::submitButton(Yii::t('waterrequest', ucwords(str_replace('_', ' ', $v))), array('id' => $v . '-button', 'name' => $v . '-button')); } } ?> </div> <?php $this->endWidget();
/** * Displays statistics about waterrequests. */ public function actionWr() { if (!Yii::app()->user->checkAccess('viewStatistics')) { throw new CHttpException(403, Yii::t('http_status', '403')); } if (isset($_POST['city'])) { $selection = $_POST['city']; } else { $selection = null; } $wrs = WaterRequests::model()->findAll('status!=:temp AND status!=:saved AND username!=:username ORDER BY timestamp', array(':temp' => WaterRequests::SW_NODE(WaterRequests::TEMP_STATUS), ':saved' => WaterRequests::SW_NODE(WaterRequests::SAVED_STATUS), ':username' => 'planner')); //$wrs = WaterRequests::model()->findAll('status!=:temp AND status!=:saved ORDER BY timestamp',array(':temp'=>WaterRequests::SW_NODE(WaterRequests::TEMP_STATUS),':saved'=>WaterRequests::SW_NODE(WaterRequests::SAVED_STATUS))); if ($wrs != null) { $total_wrs = 0; $stat = array(); $city = array(); foreach ($wrs as $wr) { $city_states = $wr->cityStates; if ($city_states) { if (!isset($city[$city_states[0]])) { $city[$city_states[0]] = ucfirst(strtolower($city_states[0])); } if ($selection) { if ($selection !== $city_states[0]) { continue; } } } else { if ($selection) { continue; } } $y = $wr->year; $m = $wr->month; $total_wrs++; $pe = 0; foreach ($wr->geometries() as $geom) { foreach ($geom->zones() as $zone) { $pe += $zone->pe; } } if (isset($stat[$y])) { $stat[$y]['total']++; $stat[$y]['pe'] += $pe; } else { $stat[$y]['total'] = 1; $stat[$y]['pe'] = $pe; } if (isset($stat[$y][$m])) { $stat[$y][$m]['total']++; $stat[$y][$m]['pe'] += $pe; } else { $stat[$y][$m]['total'] = 1; $stat[$y][$m]['pe'] = $pe; } } $this->render('wr', array('total_wrs' => $total_wrs, 'stat' => $stat, 'city' => array_unique($city), 'selection' => $selection)); Yii::app()->end(); } $this->render('wr', array('total_wrs' => null)); }
<div class="row"> <?php echo $form->labelEx($model, 'id'); ?> <?php echo CHtml::encode($model->id); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'status'); ?> <?php if ($model->status == WaterRequests::SW_NODE(WaterRequests::TEMP_STATUS)) { echo CHtml::encode($model->statusHR); } else { echo $model->statusIcon; } ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'phase'); ?> <?php echo CHtml::encode($model->phaseHR); ?> </div>