示例#1
0
 private function saveAndDeleteMedia($type)
 {
     /** @var $model Media [ ] */
     $model = new Media();
     $mockRecord = $this->getMockRecord();
     $instruction = Deal::model()->findByPk($mockRecord['med_row']);
     $this->assertNotEmpty($instruction, "instruction not exist");
     $property = Property::model()->findByPk($instruction->dea_prop);
     $this->assertNotEmpty($property, "property not exist");
     $this->assertNotNull($property->addressId, "property has no address");
     $address = Address::model()->findByPk($property->addressId);
     $this->assertNotEmpty($address, " Address not exist");
     $model->setAttributes($this->getMockRecord());
     $model->file = $this->getMockCuploadedImage('image/jpeg', 1);
     if ($type == Media::TYPE_PHOTO) {
         $model->setCropFactor($this->getCropFactor());
     } elseif ($type == Media::TYPE_EPC || $type == Media::TYPE_FLOORPLAN) {
         $model->otherMedia = $type;
     }
     $this->assertTrue($model->validate(), "record not validated");
     $this->assertTrue($model->save(), "record not saved");
     foreach ($model->getImageSizes() as $imageSize) {
         $this->assertFileExists($model->getFullPath($imageSize), $imageSize . " does not exist");
     }
     $this->deleteMedia($model->med_id);
 }
 public function loadModel($address_id, $comp_id)
 {
     $model = Address::model()->findByAttributes(array('address_id' => $address_id, 'comp_id' => $comp_id));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionAdd($id = 0)
 {
     if (!empty($id)) {
         $Insurance = Insurance::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Insurance->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->insurance != '1' || $Insurance->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $Insurance->address;
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->insurance != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Insurance = new Insurance();
         $Address = new Address();
         $Address->setscenario('insurance');
     }
     //if(isset($_POST['save'])) {
     if (!empty($_POST)) {
         if (!empty($Insurance->address)) {
             Address::model()->deleteByPk($Insurance->address->address_id);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $Insurance->setAttributes($_POST['Insurance'], false);
         $Address->setAttributes($_POST['Address'], false);
         $valid = $Address->validate();
         $valid = $Insurance->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Insurance->user_id = User::createFakeUser($ContentManager);
                 $Insurance->contact_id = $Insurance->user_id;
             }
             $Address->save();
             $Insurance->address_id = $Address->address_id;
             $Insurance->save();
             $Insurance->autosearch();
             //                $this->redirect('/insurance');
             $this->render('insuranceaddsuccess', ['Insurance' => $Insurance, 'contacts' => User::getContact()]);
             exit;
         }
     }
     $this->render('add', ['Insurance' => $Insurance, 'Address' => $Address, 'contacts' => User::getContact(), 'ContentManager' => $ContentManager]);
 }
 /**
  * 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 actionAccountUpdate()
 {
     // check if user has permissions to permissionsConfiguration
     if (Yii::app()->user->checkAccess('permissionsConfiguration')) {
         // with user.account_id load account data
         $model = Accounts::model()->findByPk(Yii::app()->user->Accountid);
         // if account hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         // if Accounts and Address form exist
         if (isset($_POST['Accounts'], $_POST['Address'])) {
             // set form elements to model attributes
             $model->attributes = $_POST['Accounts'];
             $address->attributes = $_POST['Address'];
             // validate both models
             $valid = $address->validate();
             $valid = $model->validate() && $valid;
             if ($valid) {
                 // save image path, if uploaded
                 if (isset($_FILES['Accounts']['name']['image']) && !empty($_FILES['Accounts']['name']['image'])) {
                     // create an instance of file uploaded
                     $model->image = CUploadedFile::getInstance($model, 'image');
                     if (!$model->image->getError()) {
                         $this->tmpFileName = trim(date('dmYHis-z-') . microtime());
                         $extension = $model->image->getExtensionName();
                         $extensionAllowed = array('jpg', 'jpeg', 'png');
                         // verify only allowed extensions
                         if (in_array($extension, $extensionAllowed)) {
                             // save image from tmp folder to defined folder, after set account_logo path
                             if ($model->image->saveAs(ConfigurationController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                                 $model->account_logo = ConfigurationController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             }
                         }
                     }
                 }
                 // save address
                 $address->save(false);
                 $model->address_id = $address->primaryKey;
                 // save model
                 $model->save(false);
                 // to prevent F5 keypress, redirect to account page
                 $this->redirect(Yii::app()->createUrl('configuration/account'));
             }
         }
         $this->layout = 'column2';
         $this->render('accounts/update', array('model' => $model, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
示例#5
0
 /**
  * 订单确认页面
  */
 public function actionCheckout()
 {
     $userId = $this->user_id;
     if (empty($userId)) {
         $this->redirect('/user/login');
     }
     $addList = Address::model()->getUserAddressList($userId);
     $payList = Payment::model()->getPaymentList();
     $plist = Cart::model()->getCartList($userId);
     $couponlist = Coupon::model()->getUserUsingCouponList($userId);
     if (empty($plist['list'])) {
         $this->redirect('/?from=no_deal');
     }
     $viewData = array();
     $viewData['addList'] = $addList;
     $viewData['list'] = $plist['list'];
     $viewData['total'] = $plist['total'];
     $viewData['couponlist'] = $couponlist;
     $viewData['payList'] = $payList;
     $this->render('cart/checkout', $viewData);
 }
 public function actionAddcall($id = 0)
 {
     $flZayavka = 1;
     if (!empty($id)) {
         $this->pageTitle = Yii::t('MarketModule.default', 'Редактирование спецтехники');
         $title = Yii::t('MarketModule.default', 'Редактирование заявки на спецтехнику');
     } else {
         $this->pageTitle = Yii::t('MarketModule.default', 'Добавление спецтехники');
         $title = Yii::t('MarketModule.default', 'Добавление заявки на спецтехнику');
     }
     $this->breadcrumbs = array_merge([CHtml::encode(Yii::t('MarketModule.default', 'Заявки на спецтехнику')) => ['/specialtechniquecall']], [CHtml::encode($this->pageTitle)]);
     if (!empty($id)) {
         $SpecialTechnique = SpecialTechnique::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $SpecialTechnique->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || $SpecialTechnique->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $SpecialTechnique->address;
         $CostForm = $SpecialTechnique->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $SpecialTechnique = new SpecialTechnique();
         $Address = new Address();
         $Address->setscenario('specialtechnique');
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     if (!empty($_POST)) {
         if (!empty($SpecialTechnique->address)) {
             Address::model()->deleteByPk($SpecialTechnique->address->address_id);
         }
         $SpecialTechnique->setAttributes($_POST['SpecialTechnique'], false);
         $SpecialTechnique->type_request = 'request';
         $CostForm->setAttributes($_POST['CostForm'], false);
         $Address->setAttributes($_POST['Address'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $Address->validate();
         $valid = $SpecialTechnique->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $SpecialTechnique->user_id = User::createFakeUser($ContentManager);
                 $SpecialTechnique->contact_id = $SpecialTechnique->user_id;
             }
             $Address->save();
             $SpecialTechnique->address_id = $Address->address_id;
             $SpecialTechnique->save();
             $SpecialTechnique->setRelations($_POST['SpecialTechnique']);
             $SpecialTechnique->setCost($CostForm);
             $SpecialTechnique->autosearch();
             //$this->redirect('/specialtechniquecall');
             echo CJSON::encode(array('status' => '500', 'redirect' => '/specialaddcallsuccess/' . $SpecialTechnique->special_technique_id));
             Yii::app()->end();
         }
     }
     $this->render('add', ['showPhoto' => false, 'CostForm' => $CostForm, 'SpecialTechnique' => $SpecialTechnique, 'contacts' => $contacts, 'Address' => $Address, 'title' => $title, 'ContentManager' => $ContentManager, 'flZayavka' => $flZayavka]);
 }
示例#7
0
 /**
  * 保存用户的最后地址信息为默认信息
  * @param $userId
  * @param $add_id
  * @return bool
  */
 public function saveUserLastAddressDefault($userId, $add_id)
 {
     if (empty($add_id) || empty($userId)) {
         return false;
     }
     $info = Address::model()->findByPk($add_id);
     if ($info && $info->is_default != 1) {
         $info->is_default = 1;
         $info->save();
     }
     $sql = 'update bg_address set is_default= 0 where user_id = ' . $userId . ' and id != ' . $add_id;
     Yii::app()->shop->createCommand($sql)->query();
     return true;
 }
 public function actionCheckout()
 {
     $cart = Yii::app()->user->getState('special_order');
     if (!empty($cart)) {
         $user = Yii::app()->user;
         $address = array();
         //$address = Address::model()->findAll('id=:id', array(':id'=>41));
         if (!$user->isGuest) {
             $address = Address::model()->findAll('user_id=:id AND country_id=:c_id', array(':id' => $user->id, ':c_id' => 156));
         }
         if (!empty($_GET['golp']) && is_numeric($_GET['golp'])) {
             $id = 0;
             $id = $_GET['golp'];
             $naddress = Address::model()->findAll('user_id=:user_id AND id=:id', array(':user_id' => $user->id, ':id' => $id));
             $model = CheckoutAddress::model()->findByPk($id);
             if (empty($naddress)) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'The address you selected is invalid');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('/cart/_shipping', array('model' => $model, 'address' => $address), false, true);
                     Yii::app()->end();
                 }
                 $this->render('/cart/_shipping', array('model' => $model, 'address' => $address));
                 Yii::app()->end();
             }
             //Yii::app()->user->setState('user_cart', $cart);
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 $this->renderPartial('_view', array('model' => $order), false, true);
             } else {
                 $this->render('view', array('model' => $order));
             }
             Yii::app()->end();
         } else {
             $model = new CheckoutAddress();
         }
         if (isset($_POST['Address'])) {
             $_POST['CheckoutAddress'] = $_POST['Address'];
         }
         if (isset($_POST['CheckoutAddress'])) {
             $model->attributes = $_POST['CheckoutAddress'];
             $model->user_id = 0;
             if (!empty($user->id)) {
                 $model->user_id = $user->id;
             }
             $model->country_id = 156;
             if ($model->save()) {
                 $order = new SpecialOrder();
                 $order->product_name = $cart['product_name'];
                 $order->product_quantity = $cart['product_quantity'];
                 $order->product_colour = $cart['product_colour'];
                 $order->specification = $cart['specification'];
                 $order->comment = $cart['comment'];
                 $order->email = $model->email;
                 $order->telephone = $model->telephone;
                 $order->firstname = $model->firstname;
                 $order->lastname = $model->lastname;
                 $order->address_1 = $model->address_1;
                 $order->address_2 = $model->address_2;
                 $order->city = $model->city;
                 $order->postal_code = $model->postal_code;
                 $order->country_id = 156;
                 $order->zone_id = $model->zone_id;
                 $order->ip = Yii::app()->request->userHostAddress;
                 $order->user_agent = Yii::app()->request->userAgent;
                 $order->order_status_id = 1;
                 $order->payment_code = uniqid() . rand(1, 9);
                 $order->save();
                 //Yii::app()->user->setState('user_cart', $cart);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $order), false, true);
                 } else {
                     $this->render('view', array('model' => $order));
                 }
                 Yii::app()->end();
             }
         }
         if (Yii::app()->getRequest()->getIsAjaxRequest()) {
             $this->renderPartial('/cart/_shipping', array('model' => $model, 'address' => $address), false, true);
             Yii::app()->end();
         }
         $this->render('/cart/_shipping', array('model' => $model, 'address' => $address));
         Yii::app()->end();
     }
     $this->redirect(array('specialorder'));
 }
示例#9
0
<?php

namespace Afosto\ActiveAnts;

require_once dirname(__FILE__) . '/vendor/autoload.php';
//Include our configs
require_once dirname(__FILE__) . '/../config.php';
//Make sure this directory is writable
$cacheDirectory = dirname(__FILE__) . '/../cache/';
App::start($url, $user, $password, $cacheDirectory);
$product = Product::model()->setName('testProduct')->setSku('testSku');
if (!$product->save()) {
    echo $product->getMessage();
}
$item = OrderItem::model()->setSku('testSku', false)->setGrossPrice(1.21)->setName('testProduct')->setTaxRate(21);
$address = Address::model()->setName('Afosto SaaS BV')->setAddress('Protonstraat', 9, 'a')->setCity('Groningen')->setCountry('NL')->setPostalcode('9743AL');
$order = Order::model()->setEmail('*****@*****.**')->setOrderId('#' . rand(100, 999))->setPhoneNumber('test')->addOrderItem($item)->setBillingAddress($address)->setShippingAddress();
//$order->setPickupPoint('NL-111101', '1111AA', 'Straatnaam 10a' , 'Groningen');
if (!$order->save()) {
    echo $order->getMessage();
}
$purchase = PurchaseOrder::model()->addItem('testSku', 1)->addReference('testPurchaseOrder');
if (!$purchase->save()) {
    echo $purchase->getMessage();
}
foreach (Stock::model()->findAll() as $stock) {
    echo $stock->sku . ': ' . $stock->stock . "\n";
}
示例#10
0
文件: Cart.php 项目: conghua1013/yii
 /**
  * 保存订单信息.
  * @param $cartInfo
  * @return array
  * @throws exception
  */
 protected function saveOrderInfo($userId, $request, $cartInfo)
 {
     $addid = $request['addrid'];
     $addInfo = Address::model()->findByPk($addid);
     if (empty($userId)) {
         throw new exception('请登录后再提交订单!');
     }
     if (empty($addInfo)) {
         throw new exception('地址不存在,请添加后再提交订单!');
     } elseif ($addInfo['user_id'] != $userId) {
         throw new exception('地址异常修改地址后再提交订单!');
     } elseif ($addInfo['is_default'] != 1) {
         Address::model()->saveUserLastAddressDefault($userId, $addInfo['id']);
     }
     $m = new Order();
     $m->order_sn = Order::model()->getOrderSn();
     $m->user_id = $userId;
     $m->order_status = 0;
     $m->pay_id = $request['payid'];
     $m->shipping_fee = $cartInfo['total']['shipping_fee'];
     $m->order_amount = $cartInfo['total']['final_amount'];
     $m->product_amount = $cartInfo['total']['product_amount'];
     $m->quantity = $cartInfo['total']['quantity'];
     $m->coupon_id = $cartInfo['total']['coupon_id'];
     //$m->coupon_type 	= $cartInfo['total']['coupon_type'];
     $m->coupon_amount = $cartInfo['total']['coupon_amount'];
     $m->consignee = $addInfo['consignee'];
     $m->mobile = $addInfo['mobile'];
     $m->province = $addInfo['province'];
     $m->city = $addInfo['city'];
     $m->district = $addInfo['district'];
     $m->address = $addInfo['address'];
     $m->email = '';
     $m->remark = $request['remark'];
     //备注
     $m->cps_msg = '';
     $m->source = 1;
     $m->add_time = time();
     $id = $m->save();
     if (empty($id)) {
         throw new exception('订单生成失败!');
     }
     $oInfo = array();
     $oInfo['order_id'] = $m->id;
     $oInfo['order_sn'] = $m->order_sn;
     return $oInfo;
 }
示例#11
0
echo $form->dropDownList($model, 'country_id', GxHtml::listDataEx(Country::model()->findAllAttributes(null, true)));
?>
		<?php 
echo $form->error($model, 'country_id');
?>
		</div><!-- row -->
		<div class="row">
		<?php 
echo $form->labelEx($model, 'last_update');
?>
		<?php 
echo $form->textField($model, 'last_update');
?>
		<?php 
echo $form->error($model, 'last_update');
?>
		</div><!-- row -->

		<label><?php 
echo GxHtml::encode($model->getRelationLabel('addresses'));
?>
</label>
		<?php 
echo $form->checkBoxList($model, 'addresses', GxHtml::encodeEx(GxHtml::listDataEx(Address::model()->findAllAttributes(null, true)), false, true));
?>

<?php 
echo GxHtml::submitButton('Save');
$this->endWidget();
?>
</div><!-- form -->
 public function actionEdit($id)
 {
     $model = Address::model()->with('clients', 'properties')->findByPk($id);
     if (!$model) {
         throw new CHttpException(404, 'Address [id = ' . $id . '] is not found');
     }
     if (isset($_POST['Address']) && $_POST['Address']) {
         $model->attributes = $_POST['Address'];
         if ($model->save()) {
             $this->redirect(array('edit', 'id' => $model->id));
         }
     }
     $this->render('edit', ['model' => $model]);
 }
示例#13
0
 public function testModel()
 {
     $this->assertEquals('Address', get_class(Address::model()), 'Class name should match model.');
 }
示例#14
0
 /**
  * 顾客详细信息(包括客户详细信息及健康信息)确认&修改
  */
 public function actionUpdateCust($id)
 {
     $user_model = User::model();
     $user_info = $user_model->findByPk($id);
     $cust_model = Customer::model();
     $cust_info = $cust_model->findByPk($id);
     $addr_model = Address::model();
     $query = 'select * from tbl_address where addr_cust_id=' . $id;
     $addr_info = $addr_model->findBySql($query);
     $custhi_model = Cust_Health_Info::model();
     $custhi_info = $custhi_model->findByPk($id);
     if (!isset($custhi_info)) {
         //未找到记录的话,需要新建记录
         $custhi_info = new Cust_Health_Info();
     }
     $custhr_model = Cust_Health_Reply::model();
     $query = 'select * from tbl_cust_health_reply where custhr_cust_id=' . $id;
     $custhr_info = $custhr_model->findAllBySql($query);
     if (isset($_POST['User'])) {
         if (isset($user_info)) {
             $user_info->attributes = $_POST['User'];
             $user_info->save();
         }
         if (isset($cust_info)) {
             $cust_info->attributes = $_POST['Customer'];
             //将作为用户名的手机号填入顾客信息里
             $cust_info->cust_mobile1 = $_POST['User']['usr_username'];
             //将用户喜爱的项目按位计算并保存
             $cust_prefer = 0;
             //如果啥都没选的话,下记字符串应该为空,否则为数组(内容为数字)
             if ($_POST['Customer']['cust_prefer'] != '') {
                 for ($i = 0; $i < count($_POST['Customer']['cust_prefer']); $i++) {
                     if ($_POST['Customer']['cust_prefer'][$i]) {
                         $cust_prefer |= (int) $_POST['Customer']['cust_prefer'][$i];
                     }
                 }
             } else {
                 $cust_prefer = 0;
             }
             $cust_info->cust_prefer = $cust_prefer;
             //将用户喜爱的美疗师按位计算并保存
             $cust_beautician = 0;
             //如果啥都没选的话,下记字符串应该为空,否则为字符串数组(内容为数字)
             if ($_POST['Customer']['cust_beautician'] != '') {
                 for ($i = 0; $i < count($_POST['Customer']['cust_beautician']); $i++) {
                     if ($_POST['Customer']['cust_beautician'][$i]) {
                         $cust_beautician |= (int) $_POST['Customer']['cust_beautician'][$i];
                     }
                 }
             } else {
                 $cust_beautician = 0;
             }
             $cust_info->cust_beautician = $cust_beautician;
             $cust_info->save();
         }
         if (isset($addr_info)) {
             $addr_info->attributes = $_POST['Address'];
             $addr_info->save();
         }
         if (isset($custhi_info)) {
             $custhi_info->attributes = $_POST['Cust_Health_Info'];
             $custhi_info->pk_custhi_cust_id = $id;
             $custhi_info->custhi_height = (double) $_POST['Cust_Health_Info']['custhi_height'];
             $custhi_info->custhi_weight = (double) $_POST['Cust_Health_Info']['custhi_weight'];
             $custhi_info->custhi_date = date("Y-m-d H:i:s", time());
             $custhi_info->save();
         }
         $this->redirect("./index.php?r=user/showCust");
     }
     $this->renderPartial('updateCust', array('user_info' => $user_info, 'cust_info' => $cust_info, 'addr_info' => $addr_info, 'custhi_info' => $custhi_info, 'custhr_info' => $custhr_info));
 }
示例#15
0
<?php

$this->breadcrumbs = array($model->label(2) => array('index'), 'Manage');
$this->menu = array(array('label' => 'List' . ' ' . $model->label(2), 'url' => array('index')), array('label' => 'Create' . ' ' . $model->label(), 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('staff-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1><?php 
echo 'Manage' . ' ' . GxHtml::encode($model->label(2));
?>
</h1>

<p>
You may optionally enter a comparison operator (&lt;, &lt;=, &gt;, &gt;=, &lt;&gt; or =) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php 
echo GxHtml::link('Advanced Search', '#', array('class' => 'search-button'));
?>
<div class="search-form">
<?php 
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'staff-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('staff_id', 'first_name', 'last_name', array('name' => 'address_id', 'value' => 'GxHtml::valueEx($data->address)', 'filter' => GxHtml::listDataEx(Address::model()->findAllAttributes(null, true))), 'picture', 'email', array('class' => 'CButtonColumn'))));
示例#16
0
		<?php 
echo $form->labelEx($model, 'email');
?>
		<?php 
echo $form->textField($model, 'email', array('maxlength' => 50));
?>
		<?php 
echo $form->error($model, 'email');
?>
		</div><!-- row -->
		<div class="row">
		<?php 
echo $form->labelEx($model, 'address_id');
?>
		<?php 
echo $form->dropDownList($model, 'address_id', GxHtml::listDataEx(Address::model()->findAllAttributes(null, true)));
?>
		<?php 
echo $form->error($model, 'address_id');
?>
		</div><!-- row -->
		<div class="row">
		<?php 
echo $form->labelEx($model, 'active');
?>
		<?php 
echo $form->checkBox($model, 'active');
?>
		<?php 
echo $form->error($model, 'active');
?>
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     if (Yii::app()->user->checkAccess('updateUsers')) {
         $allowEdit = false;
         $model = $this->loadModel();
         $tmppw = $model->user_password;
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         $userManager = Yii::app()->user->IsManager;
         if ($model->user_id == Yii::app()->user->id || $userManager || Yii::app()->user->IsAdministrator) {
             $allowEdit = true;
         }
         if (isset($_POST['Users']) && isset($_POST['Address'])) {
             $model->attributes = $_POST['Users'];
             $address->attributes = $_POST['Address'];
             if (isset($_POST['Users']['user_password'])) {
                 $model->user_password = md5($model->user_password);
             }
             $valid = $address->validate();
             $valid = $model->validate() && $valid;
             if ($valid) {
                 $address->save(false);
                 $model->address_id = $address->primaryKey;
                 if ($model->save(false)) {
                     // Guardar log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'UserUpdated', 'log_resourceid' => $model->user_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                     Logs::model()->saveLog($attributes);
                     $this->redirect(array('view', 'id' => $model->user_id));
                 }
             }
         }
         $this->render('update', array('model' => $model, 'allowEdit' => $allowEdit, 'userManager' => $userManager, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
示例#18
0
 public function actionCheckout()
 {
     $cart = $this->getCart();
     if (!empty($cart)) {
         $user = Yii::app()->user;
         $address = array();
         //$address = Address::model()->findAll('id=:id', array(':id'=>41));
         if (!$user->isGuest) {
             $address = Address::model()->findAll('user_id=:id AND country_id=:c_id', array(':id' => $user->id, ':c_id' => 156));
         }
         if (!empty($_GET['golp']) && is_numeric($_GET['golp'])) {
             $id = 0;
             $id = $_GET['golp'];
             $naddress = Address::model()->findAll('user_id=:user_id AND id=:id', array(':user_id' => $user->id, ':id' => $id));
             $model = CheckoutAddress::model()->findByPk($id);
             if (empty($naddress)) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'The address you selected is invalid');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_shipping', array('model' => $model, 'address' => $address), false, true);
                     Yii::app()->end();
                 }
                 $this->render('_shipping', array('model' => $model, 'address' => $address));
                 Yii::app()->end();
             }
             Yii::app()->user->setState('user_cart', $cart);
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 $this->renderPartial('_payment', array('app' => $model), false, true);
                 Yii::app()->end();
             } else {
                 $this->redirect(array('payment', 'id' => $model->id));
             }
         } else {
             $model = new CheckoutAddress();
         }
         if (isset($_POST['Address'])) {
             $_POST['CheckoutAddress'] = $_POST['Address'];
         }
         if (isset($_POST['CheckoutAddress'])) {
             $model->attributes = $_POST['CheckoutAddress'];
             $model->user_id = 0;
             if (!empty($user->id)) {
                 $model->user_id = $user->id;
             }
             $model->country_id = 156;
             if ($model->save()) {
                 /*
                 $cart['shipping']['email'] = $model->email;
                 $cart['shipping']['telephone'] = $model->telephone;
                 $cart['shipping']['firstname'] = $model->firstname;
                 $cart['shipping']['lastname'] = $model->lastname;
                 $cart['shipping']['address_1'] = $model->address_1;
                 $cart['shipping']['address_2'] = $model->address_2;
                 $cart['shipping']['city'] = $model->city;
                 $cart['shipping']['postal_code'] = $model->postal_code;
                 $cart['shipping']['country_id'] = 156;
                 $cart['shipping']['zone_id'] = $model->zone_id;
                 */
                 Yii::app()->user->setState('user_cart', $cart);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_payment', array('app' => $model), false, true);
                     Yii::app()->end();
                 } else {
                     $this->redirect(array('payment', 'id' => $model->id));
                 }
             }
         }
         if (Yii::app()->getRequest()->getIsAjaxRequest()) {
             $this->renderPartial('_shipping', array('model' => $model, 'address' => $address), false, true);
             Yii::app()->end();
         }
         $this->render('_shipping', array('model' => $model, 'address' => $address));
         Yii::app()->end();
     }
     $this->redirect(array('cart'));
 }
示例#19
0
<?php

$this->breadcrumbs[] = Yii::t('crud', 'Customers');
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\$('.search-form').toggle();\nreturn false;\n});\n\$('.search-form form').submit(function(){\n\$.fn.yiiGridView.update('customer-grid', {\ndata: \$(this).serialize()\n});\nreturn false;\n});\n");
?>

<?php 
$this->widget("TbBreadcrumbs", array("links" => $this->breadcrumbs));
?>
<h1>
    <?php 
echo Yii::t('crud', 'Customers');
?>
 <small><?php 
echo Yii::t('crud', 'Manage');
?>
</small>
</h1>

<?php 
$this->renderPartial("_toolbar", array("model" => $model));
$this->widget('TbGridView', array('id' => 'customer-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'customer_id', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/customer/editableSaver'))), array('name' => 'store_id', 'value' => 'CHtml::value($data,\'store.itemLabel\')', 'filter' => CHtml::listData(Store::model()->findAll(array('limit' => 1000)), 'store_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'first_name', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/customer/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'last_name', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/customer/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'email', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/customer/editableSaver'))), array('name' => 'address_id', 'value' => 'CHtml::value($data,\'address.itemLabel\')', 'filter' => CHtml::listData(Address::model()->findAll(array('limit' => 1000)), 'address_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'active', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/customer/editableSaver'))), array('class' => 'TbButtonColumn', 'viewButtonUrl' => "Yii::app()->controller->createUrl('view', array('customer_id' => \$data->customer_id))", 'updateButtonUrl' => "Yii::app()->controller->createUrl('update', array('customer_id' => \$data->customer_id))", 'deleteButtonUrl' => "Yii::app()->controller->createUrl('delete', array('customer_id' => \$data->customer_id))"))));
 /**
  *  обавить
  * @param int $id
  * @param null $delivery
  * @throws CException
  * @throws CHttpException
  */
 public function actionAdd($id = 0, $delivery = null)
 {
     if (!empty($id)) {
         $Cargo = Cargo::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Cargo->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->cargo != '1' || $Cargo->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $AddressesForm = $Cargo->getAddressForm();
         $CostForm = $Cargo->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->cargo != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Cargo = new Cargo();
         $AddressesForm = new AddressesForm();
         if (isset($delivery)) {
             $product = Product::model()->findByPk($delivery);
             $AddressesForm->from_1_name = $product->getEavAttribute('adres_name');
             $AddressesForm->from_1_address_lat = $product->getEavAttribute('adres_adress_lat');
             $AddressesForm->from_1_address_long = $product->getEavAttribute('adres_adress_long');
             $AddressesForm->from_1_ind = '';
         }
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     $Cargo->contact_id = Yii::app()->user->id;
     if (!empty($_POST)) {
         $Cargo->setAttributes($_POST['Cargo'], false);
         $AddressesForm->setAttributes($_POST['AddressesForm'], false);
         if ($Cargo->price_asc == '0') {
             $CostForm->setAttributes($_POST['CostForm'], false);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $AddressesForm->validate();
         $valid = $Cargo->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Cargo->user_id = User::createFakeUser($ContentManager);
                 $Cargo->contact_id = $Cargo->user_id;
             }
             $Cargo->save();
             $_POST['Cargo']['type_transport'] = '';
             if (isset($Cargo->transport_type_id)) {
                 switch ($Cargo->transport_type_id) {
                     case 20:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['sea_transport'];
                         break;
                     case 21:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['zhd_transport'];
                         break;
                     case 22:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['air_transport'];
                         break;
                     case 72:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['river_transport'];
                         break;
                     default:
                         break;
                 }
             }
             $Cargo->setRelations($_POST['Cargo']);
             $Cargo->setAddress($AddressesForm);
             $Cargo->setCost($CostForm);
             $Cargo->autosearch();
             if ($_POST['Cargo']['customs_clearance'] == 1) {
                 if ($_POST['AddressesForm']['from_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['from_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['to_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['from_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['from_1_ind'] = 'CHE';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['to_1_ind'] = 'CHE';
                 }
                 $from = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['from_1_ind']]);
                 $to = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['to_1_ind']]);
                 $Custom = new Custom();
                 $Custom->type_id = $_POST['Cargo']['name_id'];
                 $Custom->packing_id = $_POST['Cargo']['packing_id'];
                 $Custom->country_from = isset($from) ? $from->id : 0;
                 $Custom->country_to = isset($to) ? $to->id : 0;
                 $Custom->weight_netto = $_POST['Cargo']['weight'];
                 $Custom->weight_brutto = $_POST['Cargo']['weight'];
                 $Custom->volume = $_POST['Cargo']['volume'];
                 $Custom->date_from = $_POST['Cargo']['when_from'];
                 $Custom->date_to = $_POST['Cargo']['when_to'];
                 $Custom->user_id = Yii::app()->user->id;
                 $Custom->contact_id = $_POST['Cargo']['contact_id'];
                 $Custom->save();
                 $Custom->autosearch();
             }
             if ($_POST['Cargo']['cargo_insurance'] == 1) {
                 $addrId = Yii::app()->db->createCommand()->select('address_id')->from('site_cargo_address u')->where('cargo_id=:cargo_id', array(':cargo_id' => $Cargo->cargo_id))->order('cargo_id ASC')->limit(1)->queryRow();
                 $addr = Address::model()->findByPk($addrId);
                 $Insurance = new Insurance();
                 $Insurance->category_id = 147;
                 $Insurance->address_id = $addr->address_id;
                 $Insurance->description = '';
                 $Insurance->contact_id = $_POST['Cargo']['contact_id'];
                 $Insurance->create = date('Y-m-d H:i:s');
                 $Insurance->user_id = Yii::app()->user->id;
                 $Insurance->date_to = $_POST['Cargo']['when_to'] != '' ? $_POST['Cargo']['when_to'] : '0000-00-00';
                 $Insurance->save();
                 $Insurance->autosearch();
             }
             echo CJSON::encode(array('status' => '500', 'redirect' => '/cargoaddsuccess/' . $Cargo->cargo_id));
             Yii::app()->end();
         }
     }
     $DictionaryData = \DictionaryData::model()->findAll('group_id=3');
     $this->render('add', ['Cargo' => $Cargo, 'addreses' => $AddressesForm, 'CostForm' => $CostForm, 'contacts' => $contacts, 'ContentManager' => $ContentManager, 'DictionaryData' => $DictionaryData]);
 }
 public function actionSetToDefault()
 {
     $id = $_REQUEST['id'];
     $cri = new CDbCriteria(array('condition' => 'is_default = 1'));
     $address = Address::model()->find($cri);
     if ($address) {
         $address->is_default = 0;
         if ($address->save()) {
             $address_now = Address::model()->findByPk($id);
             $address_now->is_default = 1;
             //           $address_now->save();
             if ($address_now->save()) {
                 echo '设置成功';
             }
             //             $this->refresh();
         }
     } else {
         $address_now = Address::model()->findByPk($id);
         $address_now->is_default = 1;
         //           $address_now->save();
         if ($address_now->save()) {
             echo '设置成功';
         }
         //             $this->refresh();
     }
 }
示例#22
0
 /**
  * 用户的地址列表展示.
  */
 public function actionAddress()
 {
     $userId = $this->user_id;
     if (empty($userId)) {
         $this->redirect('/user/login');
     }
     $list = Address::model()->getUserAddressList($userId);
     $viewData = array();
     $viewData['list'] = $list;
     $this->render('/user/address', $viewData);
 }
 /**
  * Updates a particular model.
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateCompanies
     if (Yii::app()->user->checkAccess('updateCompanies')) {
         // get Company object from $id parameter
         $model = $this->loadModel();
         // if company hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if (Yii::app()->user->IsAdministrator) {
             // if Company form exist
             if (isset($_POST['Companies'])) {
                 // set form elements to Companies model attributes
                 $model->attributes = $_POST['Companies'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // validate both models
                 $valid = $address->validate();
                 $valid = $model->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $model->address_id = $address->primaryKey;
                     // save company
                     if ($model->save()) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CompanyUpdated', 'log_resourceid' => $model->company_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->company_id));
                     }
                 }
             }
         }
         $this->render('update', array('model' => $model, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
示例#24
0
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<link href="<?php 
echo BACK_CSS_URL;
?>
mine.css" type="text/css" rel="stylesheet">
</head>

<body>
<!--<div style="width:1300px;height:500px;overflow:scroll;">-->
<div>
	<?php 
//定义model用于取得duration和地址(区名)
$order_item_model = Order_Item::model();
$commodity_service_model = Commodity_Service::model();
$order_model = Order::model();
$address_model = Address::model();
$day = date("Y-m-d", time());
echo '<table border="2" width="100%" class="table_a">';
echo '<tr>';
echo "<td width='120'>理疗师</td>";
for ($i = 0; $i < 15; $i++) {
    if ($i % 2 == 0) {
        echo "<td bgcolor='#add8e6'>" . "<a href='./index.php?r=aptm/dayCal&day=" . $day . "' target=_blank>" . $day . '</a></td>';
    } else {
        echo "<td bgcolor='#7fffd4'>" . "<a href='./index.php?r=aptm/dayCal&day=" . $day . "' target=_blank>" . $day . '</a></td>';
    }
    $day = date("Y-m-d", strtotime("{$day} +1 day"));
}
echo '</tr>';
//计算美容师人数,为第一层for循环做准备
$beau_num = count($beau_info);
 public function loadModel($id)
 {
     $model = Address::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('crud', 'The requested page does not exist.'));
     }
     return $model;
 }
示例#26
0
 public function resourceToModel($res, $patient)
 {
     $patient->nhs_num = $res->nhs_num;
     $patient->hos_num = $res->hos_num;
     $patient->gender = $res->gender;
     $patient->dob = $res->birth_date;
     $patient->date_of_death = $res->date_of_death;
     $patient->gp_id = $res->gp_ref ? $res->gp_ref->getId() : null;
     $patient->practice_id = $res->prac_ref ? $res->prac_ref->getId() : null;
     $this->saveModel($patient);
     $contact = $patient->contact;
     $contact->title = $res->title;
     $contact->last_name = $res->family_name;
     $contact->first_name = $res->given_name;
     $contact->primary_phone = $res->primary_phone;
     $this->saveModel($contact);
     $cur_addrs = array();
     foreach ($contact->addresses as $addr) {
         $cur_addrs[$addr->id] = PatientAddress::fromModel($addr);
     }
     $add_addrs = array();
     $matched_ids = array();
     foreach ($res->addresses as $new_addr) {
         $found = false;
         foreach ($cur_addrs as $id => $cur_addr) {
             if ($cur_addr->isEqual($new_addr)) {
                 $matched_ids[] = $id;
                 $found = true;
                 unset($cur_addrs[$id]);
                 break;
             }
         }
         if (!$found) {
             $add_addrs[] = $new_addr;
         }
     }
     $crit = new \CDbCriteria();
     $crit->compare('contact_id', $contact->id)->addNotInCondition('id', $matched_ids);
     \Address::model()->deleteAll($crit);
     foreach ($add_addrs as $add_addr) {
         $addr = new \Address();
         $addr->contact_id = $contact->id;
         $add_addr->toModel($addr);
         $this->saveModel($addr);
     }
     $cur_cb_ids = array();
     foreach ($patient->commissioningbodies as $cb) {
         $cur_cb_ids[] = $cb->id;
     }
     $new_cb_ids = array();
     foreach ($res->cb_refs as $cb_ref) {
         $new_cb_ids[] = $cb_ref->getId();
     }
     $add_cb_ids = array_diff($new_cb_ids, $cur_cb_ids);
     $del_cb_ids = array_diff($cur_cb_ids, $new_cb_ids);
     foreach ($add_cb_ids as $cb_id) {
         $cba = new \CommissioningBodyPatientAssignment();
         $cba->commissioning_body_id = $cb_id;
         $cba->patient_id = $patient->id;
         $this->saveModel($cba);
     }
     if ($del_cb_ids) {
         $crit = new \CDbCriteria();
         $crit->compare('patient_id', $patient->id)->addInCondition('commissioning_body_id', $del_cb_ids);
         \CommissioningBodyPatientAssignment::model()->deleteAll($crit);
     }
 }
示例#27
0
 public function afterDelete($event)
 {
     if ($this->owner->contact_id && get_class($this->owner) != 'ContactLocation') {
         Address::model()->deleteAll('contact_id = :contact_id', array(':contact_id' => $this->owner->contact_id));
         Contact::model()->deleteByPk($this->owner->contact_id);
     }
     parent::afterDelete($event);
 }
示例#28
0
<div class="btn-group">
<?php 
$this->widget('bootstrap.widgets.TbButtonGroup', array('type' => '', 'buttons' => array()));
?>
</div>

<?php 
$relatedSearchModel = $model->getRelatedSearchModel('inventories');
$this->widget('TbGridView', array('id' => '/sakila/hybrid/inventory-grid', 'dataProvider' => $relatedSearchModel->search(), 'filter' => count($model->inventories) > 1 ? $relatedSearchModel : null, 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array('inventory_id', array('name' => 'film_id', 'value' => 'CHtml::value($data,\'film.itemLabel\')', 'filter' => CHtml::listData(Film::model()->findAll(array('limit' => 1000)), 'film_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'last_update', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'TbButtonColumn', 'viewButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/inventory/view', array('inventory_id' => \$data->inventory_id))", 'updateButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/inventory/update', array('inventory_id' => \$data->inventory_id))", 'deleteButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/inventory/delete', array('inventory_id' => \$data->inventory_id))"))));
?>


<h2>
    <?php 
echo Yii::t('crud', 'Staffs');
?>
 </h2>

<div class="btn-group">
<?php 
$this->widget('bootstrap.widgets.TbButtonGroup', array('type' => '', 'buttons' => array()));
?>
</div>

<?php 
$relatedSearchModel = $model->getRelatedSearchModel('staffs');
$this->widget('TbGridView', array('id' => '/sakila/hybrid/staff-grid', 'dataProvider' => $relatedSearchModel->search(), 'filter' => count($model->staffs) > 1 ? $relatedSearchModel : null, 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array('staff_id', array('class' => 'editable.EditableColumn', 'name' => 'first_name', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'last_name', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('name' => 'address_id', 'value' => 'CHtml::value($data,\'address.itemLabel\')', 'filter' => CHtml::listData(Address::model()->findAll(array('limit' => 1000)), 'address_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'picture', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'email', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'active', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'username', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/store/editableSaver'))), array('class' => 'TbButtonColumn', 'viewButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/staff/view', array('staff_id' => \$data->staff_id))", 'updateButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/staff/update', array('staff_id' => \$data->staff_id))", 'deleteButtonUrl' => "Yii::app()->controller->createUrl('/sakila/hybrid/staff/delete', array('staff_id' => \$data->staff_id))"))));
?>

示例#29
0
 /**
  * Returns the static model of the specified AR class.
  * Please note that you should have this exact method in all your AFActiveRecord descendants!
  * @param string $className active record class name.
  * @return FullAddress the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * Updates a particular model.
  * @param integer $_GET['id'] the ID of the model to be updated
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateClients
     if (Yii::app()->user->checkAccess('updateClients')) {
         // get Clients object from $id parameter
         $model = $this->loadModel();
         // find client user data
         $modelUsers = Users::model()->together()->findByPk($model->user_id);
         // current user password
         $tmppw = $modelUsers->user_password;
         // if client hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($modelUsers->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if ($modelUsers->user_id == Yii::app()->user->id || Yii::app()->user->IsAdministrator) {
             // if Users and Address form exist
             if (isset($_POST['Users']) && isset($_POST['Address'])) {
                 // set form elements to Users model attributes
                 $modelUsers->attributes = $_POST['Users'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // if current password is different to new password
                 if (isset($_POST['Users']['user_password'])) {
                     $modelUsers->user_password = md5($modelUsers->user_password);
                 }
                 // validate both models
                 $valid = $address->validate();
                 $valid = $modelUsers->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $modelUsers->address_id = $address->primaryKey;
                     // save user
                     if ($modelUsers->save(false)) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientUpdated', 'log_resourceid' => $model->client_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->client_id));
                     }
                 }
             }
             $this->render('update', array('model' => $modelUsers, 'address' => $address));
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }