public static function fetchByType($type = 1, $page = 1, $perpage = 30) { if ($type != 0 && $type != 1 && $type != 2) { return array(); } $select = self::select(); if ($type != 0) { $select->where('type = ?', $type); } $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(); $destinations = array(); if (count($data) > 0) { foreach ($data as $da) { $destinationModel = new Application_Model_O_Destination(); $destinationModel->setId($da->id)->setCity($da->city)->setType($da->type)->setLongitude($da->longitude)->setLatitude($da->latitude)->setImg($da->img)->setSort($da->sort)->setCtime($da->ctime)->setUtime($da->utime)->setStatus($da->status); array_push($destinations, $destinationModel); } } $res = array('destinations' => $destinations, '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; // unset($params['controller']); // unset($params['action']); // unset($params['module']); $dest = new Application_Model_O_Destination(); $validate = new Yy_Validate_Value(); if ($validate->isValid($params['id'])) { $dest->setId($params['id']); } else { $dest->setCtime(date('Y-m-d H:i:s')); } if ($validate->isValid($params['city'])) { $dest->setCity($params['city']); } if ($validate->isValid($params['type'])) { $dest->setType($params['type']); } if ($validate->isValid($params['longitude'])) { $dest->setLongitude($params['longitude']); } if ($validate->isValid($params['latitude'])) { $dest->setLatitude($params['latitude']); } if ($validate->isValid($params['sort'])) { $dest->setSort($params['sort']); } if ($validate->isValid($params['status'])) { $dest->setStatus($params['status']); } try { $dest->save(); $id = $dest->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_Destination::updateImage($id, $img); } $url = '/destination/view?id=' . $id . '&from=add'; $this->redirect($url); } catch (Zend_Db_Exception $e) { $this->redirect('/error?message=' . $e->getMessage()); } }
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_Destination(); $entry->setId($row->id)->setCity($row->city)->setType($row->type)->setLongitude($row->longitude)->setLatitude($row->latitude)->setImg($row->img)->setSort($row->sort)->setCtime($row->ctime)->setUtime($row->utime)->setStatus($row->status); $entry->setNew(false); $entries[] = $entry; } return $entries; }