/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); if (isset($this->city)) { $this->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $this->city); } if (isset($this->blood_group)) { $this->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $this->blood_group); } if (isset($this->area)) { $this->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $this->area); } $criteria->compare('request_id', $this->request_id); $criteria->compare('name', $this->name, true); $criteria->compare('city', $this->city); $criteria->compare('state', $this->state); $criteria->compare('number', $this->number, true); $criteria->compare('date', $this->date, true); $criteria->compare('blood_group', $this->blood_group); $criteria->compare('area', $this->area); $criteria->compare('status', $this->status, true); $criteria->compare('remarks', $this->remarks, true); $criteria->compare('donor', $this->donor); return new CActiveDataProvider($this, array('criteria' => $criteria)); }
/** * 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) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DonationRequest'])) { $model->attributes = $_POST['DonationRequest']; $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city); $model->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $model->blood_group); $model->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $model->area); $model->state = $model->city0->lookup_parent_id; if (!Utilities::checkDateFormat($model->date)) { $model->date = DateTime::createFromFormat('d/M/yyyy', $model->date)->format('Y-m-d'); } if ($model->save()) { if ($model->status == "Donor Assigned") { $donor = UserDetails::model()->findByPk($model->donor); $donor->last_donation_date = date("Y-m-d"); $donor->donation_status = 'Y'; $donor->save(false); } $this->redirect(array('view', 'id' => $model->request_id)); } } $model->city = $model->city0->lookup_value; $model->area = $model->area0->lookup_value; $model->blood_group = $model->bloodGroup->lookup_value; //$model->date = DateTime::createFromFormat('Y-m-d', $model->date )->format('d/M/y'); $this->render('update', array('model' => $model)); }
/** * 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) { $model = $this->loadModel($id); //$model->dob = DateTime::createFromFormat ( 'Y-m-d', $model->dob )->format ( 'd/m/Y' ); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['UserDetails'])) { $model->attributes = $_POST['UserDetails']; $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city); $model->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $model->blood_group); $model->state = $model->city0->lookup_parent_id; $model->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $model->area); if (!Utilities::checkDateFormat($model->dob)) { $model->dob = DateTime::createFromFormat('d/M/yyyy', $model->dob)->format('Y-m-d'); } if ($model->save()) { $this->redirect(array('view', 'id' => $model->user_id)); } } if (isset($model->city)) { $model->city = $model->city0->lookup_value; } if (isset($model->blood_group)) { $model->blood_group = $model->bloodGroup->lookup_value; } if (isset($model->area)) { $model->area = $model->area0->lookup_value; } $this->render('update', array('model' => $model)); }
public function actionupdateUser() { // Parse the PUT parameters. This didn't work: parse_str(file_get_contents('php://input'), $put_vars); // $json = file_get_contents ( 'php://input' ); // $GLOBALS['HTTP_RAW_POST_DATA'] is not preferred: http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data // $put_vars = CJSON::decode ( $json, true ); // true means use associative array if (!isset($_GET['id'])) { $this->_sendResponse(500, 'Error: Parameter <b>id</b> is missing'); } switch ($_GET['property']) { // Get an instance of the respective model case 'update': $model = UserDetails::model()->findByPk($_GET['id']); foreach ($_POST as $var => $value) { // Does the model have this attribute? If not raise an error $model->{$var} = $value; // else // $this->_sendResponse(500, // sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, // $_GET['model']) ); } $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city); $model->state = $model->city0->lookup_parent_id; break; case 'number': $model = Utilities::getDetailswithNo($_GET['id']); $model->number = $_POST['number']; break; case 'resetPassword': $model = Utilities::getDetailswithPasswordNo($_GET['id'], $_POST['oldpassword']); $model->password = $_POST['password']; break; default: $this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model'])); Yii::app()->end(); } // Did we find the requested model? If not, raise an error if ($model === null) { $this->_sendResponse(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id'])); } // Try to save the model if ($model->save()) { $this->_sendResponse(200, CJSON::encode($model)); } else { // Errors occurred $msg = ""; $msg .= "<ul>"; foreach ($model->errors as $attribute => $attr_errors) { foreach ($attr_errors as $attr_error) { $msg .= "<li>{$attr_error}</li>"; } } $msg .= "</ul>"; $this->_sendResponse(500, $msg); } }