/**
  * 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 $id the ID of the model to be loaded
  * @return Tinkhachhang the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Tinkhachhang::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete_user($id)
 {
     //Kiểm tra khách hàng này đã đăng tin chưa nếu chưa thì mới xóa
     if (Tinkhachhang::model()->findByAttributes(array('ma_khach_hang' => $id))) {
         $this->redirect(array('admin'));
     }
     //xóa dữ liệu khách hàng và redirect trang
     $this->loadModel($id)->delete();
     $this->redirect(array('admin'));
 }
 /**
  * 
  * @param integer $maTin Mã tin
  */
 private function __suaTinGhepXe($maTin)
 {
     $form = new CForm('application.views.user.khach_hang._formGX');
     $form['tinkhachhang']->model = $tinKH = Tinkhachhang::model()->findByPk($maTin);
     $form['tinghepxe']->model = Tinghepxe::model()->find("ma_tin = {$maTin}");
     if ($form->submitted('dangtin') && $form->validate()) {
         $tinkhachhang = $form['tinkhachhang']->model;
         $tinghepxe = $form['tinghepxe']->model;
         //update tin khách hàng sau đó là tin ghép xe
         if ($tinkhachhang->save(false)) {
             Tinghepxe::updateTinGhepXe($tinghepxe->dia_chi_di, $tinghepxe->dia_chi_den, $tinghepxe->noi_den_tinh, $tinghepxe->ma_loai_xe_ghep, $tinghepxe->ngay_khoi_hanh, $tinghepxe->ma_tin);
         }
     }
     //render view
     $this->render('sua_tin', ['form' => $form]);
 }
Exemple #4
0
 /**
  * Kiểm tra xem có đúng tin có mã tin là $maTin có phải là của khách hàng này
  * @param integer $maTin
  * @return boolean
  */
 public static function checkBelongToUser($maTin)
 {
     if (Tinkhachhang::model()->findByAttributes(array('ma_tin' => $maTin), 'ma_khach_hang = ' . Yii::app()->user->userId)) {
         return true;
     }
     return false;
 }