From f81e82374bb476986cb1544c3b2469b0ee04dea5 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Thu, 24 Dec 2009 08:18:27 +0000 Subject: [PATCH] * adjust the company module. use dao. --- trunk/module/company/control.php | 2 + trunk/module/company/model.php | 48 ++++++++++++----------- trunk/module/company/view/create.html.php | 4 +- trunk/module/company/view/edit.html.php | 2 +- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/trunk/module/company/control.php b/trunk/module/company/control.php index 0829356e4e..63202ba13d 100644 --- a/trunk/module/company/control.php +++ b/trunk/module/company/control.php @@ -65,6 +65,7 @@ class company extends control if(!empty($_POST)) { $this->company->create(); + if(dao::isError()) die(js::error(dao::getError())); die(js::locate($this->createLink('admin', 'browsecompany'), 'parent')); } @@ -86,6 +87,7 @@ class company extends control if(!empty($_POST)) { $this->company->update($companyID); + if(dao::isError()) die(js::error(dao::getError())); die(js::locate($this->createLink('admin', 'browsecompany'), 'parent')); } diff --git a/trunk/module/company/model.php b/trunk/module/company/model.php index 216a3478b2..7399d3b01d 100644 --- a/trunk/module/company/model.php +++ b/trunk/module/company/model.php @@ -25,18 +25,16 @@ lang->company->menu, 'addUser', array($this->app->company->id, $dept)); } /* 获得公司列表。*/ - function getList() + public function getList() { - $sql = "SELECT * FROM " . TABLE_COMPANY; - $stmt = $this->dbh->query($sql); - return $stmt->fetchAll(); + return $this->dao->select('*')->from(TABLE_COMPANY)->fetchAll(); } /** @@ -48,40 +46,44 @@ class companyModel extends model */ public function getByDomain($domain = '') { - if(empty($domain)) $domain = filter_input(INPUT_SERVER, 'HTTP_HOST'); - $sql = 'SELECT * FROM ' . TABLE_COMPANY . " WHERE `pms` = '$domain' LIMIT 1"; - return $this->dbh->query($sql)->fetch(); + if(empty($domain)) $domain = $_SERVER['HTTP_HOST']; + return $this->dao->findByPMS($domain)->from(TABLE_COMPANY)->fetch(); } /* 通过id获取公司信息。*/ public function getByID($companyID = '') { - $sql = 'SELECT * FROM ' . TABLE_COMPANY . " WHERE `id` = '$companyID' LIMIT 1"; - return $this->dbh->query($sql)->fetch(); + return $this->dao->findById((int)$companyID)->from(TABLE_COMPANY)->fetch(); } /* 新增一个公司。*/ - function create() + public function create() { - extract($_POST); - $sql = "INSERT INTO " . TABLE_COMPANY . " (name, phone, fax, address, zipcode, website, backyard, pms, guest) - VALUES('$name', '$phone', '$fax', '$address', '$zipcode', '$website', '$backyard', '$pms', '$guest')"; - return $this->dbh->exec($sql); + $company = fixer::input('post')->get(); + $this->dao->insert(TABLE_COMPANY) + ->data($company) + ->autoCheck() + ->batchCheck('name, pms', 'notempty') + ->batchCheck('name,pms', 'unique') + ->exec(); } /* 更新一个公司信息。*/ - function update($companyID) + public function update($companyID) { - extract($_POST); - $sql = "UPDATE " . TABLE_COMPANY . " SET name = '$name', phone = '$phone', fax = '$fax', address = '$address', - zipcode = '$zipcode', website = '$website', backyard = '$backyard', pms = '$pms', guest = '$guest' - WHERE id = '$companyID' LIMIT 1"; - return $this->dbh->exec($sql); + $company = fixer::input('post')->get(); + $this->dao->update(TABLE_COMPANY) + ->data($company) + ->autoCheck() + ->batchCheck('name, pms', 'notempty') + ->batchCheck('name,pms', 'unique', "id != '$companyID'") + ->where('id')->eq($companyID) + ->exec(); } /* 删除一个公司。*/ - function delete($companyID) + public function delete($companyID) { - return $this->dbh->query("DELETE FROM " . TABLE_COMPANY . " WHERE id = '$companyID' LIMIT 1"); + return $this->dao->delete()->from(TABLE_COMPANY)->where('id')->eq((int)$companyID)->limit(1)->exec(); } } diff --git a/trunk/module/company/view/create.html.php b/trunk/module/company/view/create.html.php index c472c3726b..8f085e80fc 100644 --- a/trunk/module/company/view/create.html.php +++ b/trunk/module/company/view/create.html.php @@ -24,7 +24,7 @@ ?>
-
+ @@ -61,7 +61,7 @@ - +
company->create;?>
company->guest;?>company->guestList);?>company->guestList);?>
diff --git a/trunk/module/company/view/edit.html.php b/trunk/module/company/view/edit.html.php index 7e65231799..f35178b6ce 100644 --- a/trunk/module/company/view/edit.html.php +++ b/trunk/module/company/view/edit.html.php @@ -61,7 +61,7 @@ company->guest;?> - company->guestList, $company->guest);?> + company->guestList, $company->guest);?>