Beispiel #1
0
 public static function fetchAll($where = null, $order = null, $limit = null, $offset = null)
 {
     $resultSet = self::getDbTable()->fetchAll($where, $order, $limit, $offset);
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Application_Model_O_Departments();
         $entry->setId($row->id)->setName($row->name)->setImg($row->img)->setCategory_id($row->category_id)->setSort($row->sort)->setCtime($row->ctime)->setUtime($row->utime)->setStatus($row->status);
         $entry->setNew(false);
         $entries[] = $entry;
     }
     return $entries;
 }
Beispiel #2
0
 public static function fetchAllPage($page = 1, $perpage = 30)
 {
     $select = self::select();
     $select->order('sort asc');
     $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
     $paginator = new Zend_Paginator($adapter);
     $paginator->setItemCountPerPage($perpage)->setCurrentPageNumber($page);
     $data = $paginator->getCurrentItems();
     $pages = $paginator->count();
     $departments = array();
     if (count($data) > 0) {
         foreach ($data as $da) {
             $departmentModel = new Application_Model_O_Departments();
             $departmentModel->setId($da->id)->setName($da->name)->setImg($da->img)->setCategory_id($da->category_id)->setSort($da->sort)->setCtime($da->ctime)->setUtime($da->utime)->setStatus($da->status);
             array_push($departments, $departmentModel);
         }
     }
     $res = array('departments' => $departments, 'pages' => $pages);
     return $res;
 }
 public function asyncajaxAction()
 {
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $params = $this->_getAllParams();
     //echo "<pre>";var_dump($params);exit;
     $depart = new Application_Model_O_Departments();
     $validate = new Yy_Validate_Value();
     if ($validate->isValid($params['id'])) {
         $depart->setId($params['id']);
     } else {
         $depart->setCtime(date('Y-m-d H:i:s'));
     }
     if ($validate->isValid($params['name'])) {
         $depart->setName($params['name']);
     }
     if ($validate->isValid($params['category_id'])) {
         $depart->setCategory_id($params['category_id']);
     }
     if ($validate->isValid($params['sort'])) {
         $depart->setSort($params['sort']);
     }
     if ($validate->isValid($params['status'])) {
         $depart->setStatus($params['status']);
     }
     try {
         $depart->save();
         $id = $depart->getId();
         //保存行程图片
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $wrdir = Yy_Utils::getWriteDir();
         $adapter->setDestination($wrdir);
         if (!$adapter->receive()) {
             $messages = $adapter->getMessages();
             //echo implode("\n", $messages);
         }
         $filename = $adapter->getFileName();
         if (is_string($filename)) {
             $handle = fopen($filename, 'rb');
             $img = addslashes(fread($handle, filesize($filename)));
             fclose($handle);
             //Application_Model_M_DepartmentsCategory::updateImage($id, $img);
             Application_Model_M_Departments::updateImage($id, $img);
         }
         $url = '/costperf/view?id=' . $id;
         $this->redirect($url);
     } catch (Zend_Db_Exception $e) {
         $this->redirect('/error?message=' . $e->getMessage());
     }
 }