/** * 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_news($id, $type) { $tinKhachHang = $this->loadModel($id); if ($tinKhachHang->ma_loai_tin == Tinraovat::CODE_RV) { Tinraovat::model()->deleteAll('ma_tin =' . $tinKhachHang->ma_tin); } else { Tinghepxe::model()->deleteAll('ma_tin =' . $tinKhachHang->ma_tin); } $tinKhachHang->delete(); $this->redirect(array('admin')); }
<?php return array('enctype' => 'multipart/form-data', 'elements' => array('tinkhachhang' => array('type' => 'form', 'title' => 'Sửa tin rao vặt', 'elements' => array('<div class="col-xs-12 col-sm-6 col-md-6">', 'nguoi_lien_lac' => array('type' => 'text', 'class' => 'form-control'), '</div>' . '<div class="col-xs-12 col-sm-5 col-md-5 pull-right">', 'so_dien_thoai' => array('type' => 'text', 'class' => 'form-control'), '</div>' . '<div class="clearfix"></div>' . '<div class="col-xs-12 col-sm-6 col-md-6">', 'tieu_de_tin' => array('type' => 'text', 'class' => 'form-control'), '</div>' . '<div class="col-xs-12 col-sm-5 col-md-5 pull-right">', 'tinh_thanh' => array('type' => 'dropdownlist', 'items' => Province::listProvinces(), 'class' => 'form-control'), '</div>' . '<div class="clearfix"></div>' . '<div class="col-xs-12 col-sm-6 col-md-6">', 'trang_thai' => array('type' => 'dropdownlist', 'items' => Tinraovat::getStatusTinDang(), 'class' => 'form-control'), '</div>' . '<div class="col-md-12">', 'noi_dung_tin' => array('type' => 'textarea', 'rows' => '10', 'class' => 'form-control', 'id' => 'noi-dung-tin'), '</div>')), 'tinraovat' => array('type' => 'form', 'elements' => array('<div class="col-xs-12 col-sm-6 col-md-6">', 'ma_loai_tin_rv' => array('type' => 'dropdownlist', 'items' => Loaitinraovat::optionLoaiTinRV(), 'class' => 'form-control'), '</div>' . '<div class="col-xs-12 col-sm-5 col-md-5 pull-right">', 'gia_rao_vat' => array('type' => 'text', 'class' => 'form-control'), '</div>' . '<div class="col-xs-12 col-md-5">', 'anh' => array('type' => 'file'), '</div>'))), 'buttons' => array('<div class="col-md-12 text-center">', 'dangtin' => array('type' => 'submit', 'label' => 'Đăng tin', 'class' => 'btn-success'), '</div>'));
public static function updateTinRV($maLoaiTinRV, $giaRaoVat, $anh = 'null', $maTin) { $sql = "UPDATE " . Tinraovat::model()->tableName() . " SET ma_loai_tin_rv = {$maLoaiTinRV},gia_rao_vat= '{$giaRaoVat}', anh = '{$anh}'" . " WHERE ma_tin ={$maTin}"; Yii::app()->db->createCommand($sql)->execute(); }
/** * Sửa tin rao vặt * @param integer $maTin */ private function __suaTinRaoVat($maTin) { $form = new CForm('application.views.user.khach_hang._formRV'); $form['tinkhachhang']->model = $tinKH = Tinkhachhang::model()->findByPk($maTin); $form['tinraovat']->model = $tinRV = Tinraovat::model()->find("ma_tin = {$maTin}"); $anh = $tinRV['anh']; if ($form->submitted('dangtin') && $form->validate()) { $tinkhachhang = $form['tinkhachhang']->model; $tinraovat = $form['tinraovat']->model; if ($tinkhachhang->save(false)) { $image = CUploadedFile::getInstance($tinraovat, 'anh'); if ($image) { //Nếu tồn tại ảnh trong CSDL thì sẽ xóa ảnh cũ trong thư mục ảnh if ($anh) { unlink(Yii::app()->basePath . "/../" . Tinraovat::IMAGE_DIR_RV . $anh); } $newName = md5(microtime(true) . 'xechieuve') . $image->name; $tinraovat->anh = $newName; $image->saveAs(Tinraovat::IMAGE_DIR_RV . $newName); } Tinraovat::updateTinRV($tinraovat->ma_loai_tin_rv, $tinraovat->gia_rao_vat, $tinraovat->anh != null ? $tinraovat->anh : $anh, $tinraovat->ma_tin); } } //render view $this->render('sua_tin', ['form' => $form]); }
echo $form->labelEx($tinKhachHang, 'noi_dung_tin'); ?> <?php echo $form->textArea($tinKhachHang, 'noi_dung_tin', array('rows' => 6, 'cols' => 50, 'id' => 'noi-dung-tin')); ?> <?php echo $form->error($tinKhachHang, 'noi_dung_tin'); ?> </div> <div class="col-md-6"> <?php echo $form->labelEx($tinKhachHang, 'trang_thai'); ?> <?php echo $form->dropDownList($tinKhachHang, 'trang_thai', Tinraovat::getStatusTinDang(), array('class' => 'form-control')); ?> </div> <div class="col-md-5 pull-right"> <?php echo $form->labelEx($tinRaoVat, 'gia_rao_vat'); ?> <?php echo $form->textField($tinRaoVat, 'gia_rao_vat', array('class' => 'form-control')); ?> <?php echo $form->error($tinRaoVat, 'gia_rao_vat'); ?> </div> <div class="clearfix"></div>
public function actionXem_chi_tiet() { $matin = Yii::app()->request->getParam('id'); //Nếu không tồn tại mã loại xe thì sẽ redirect về trang chủ if ($matin == '') { $this->redirect(Yii::app()->homeUrl); } $modeltrv = new Tinraovat(); if (!($tinraovat = $modeltrv->getTinraovat($matin))) { $this->redirect(['site/index']); } $this->render('xem_chi_tiet', ['tinraovat' => $tinraovat]); }
/** * Delete tin đăng của khách hàng * @param type $maTin */ public function deleteTin($maTin, $maLoaiTin) { if ($maLoaiTin == Tinraovat::CODE_RV) { //Kiểm tra nếu có tồn tại ảnh thì xóa luôn cùng $tinRV = Tinraovat::model()->find("ma_tin = {$maTin}"); if ($anh = $tinRV['anh']) { unlink(Yii::app()->basePath . "/../" . Tinraovat::IMAGE_DIR_RV . $anh); } $sql = "DELETE FROM tinraovat "; Yii::app()->db->createCommand($sql)->where('ma_tin = :id', array(':id' => $maTin))->andWhere('ma_khach_hang = :mkh', array(':mkh' => Yii::app()->user->userId)); } else { $sql = "DELETE FROM tinghepxe "; Yii::app()->db->createCommand($sql)->where('ma_tin = :id', array(':id' => $maTin))->andWhere('ma_khach_hang = :mkh', array(':mkh' => Yii::app()->user->userId)); } //xóa tin ở bảng cha(bảng tin khách hàng) $this->deleteByPk($maTin); }