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 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; }
public function importAction() { $adapter = new Zend_File_Transfer_Adapter_Http(); $wrdir = Yy_Utils::getWriteDir(); $adapter->setDestination($wrdir); if (!$adapter->receive()) { $messages = $adapter->getMessages(); //echo implode("\n", $messages); } //echo APPLICATION_PATH;exit; $filename = $adapter->getFileName(); if (is_string($filename)) { //上传文件后的处理 require_once APPLICATION_PATH . '/../library/Yy/Excel/PHPExcel/IOFactory.php'; if (PHP_OS == 'WINNT') { $filename = iconv('UTF-8', 'gb2312', $filename); } $inputFileType = PHPExcel_IOFactory::identify($filename); if (stristr($inputFileType, 'excel') || stristr($inputFileType, 'csv')) { $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($filename); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); array_shift($sheetData); if (count($sheetData) > 0) { $destinations = array(); foreach ($sheetData as $record) { $destination = new Application_Model_O_Destination(); $destination->setCity($record['A']); if ($record['B'] == '国内') { $type = 1; } elseif ($record['B'] == '国外') { $type = 2; } else { continue; } $destination->setType($type); $destination->setLongitude($record['C'])->setLatitude($record['D'])->setSort($record['E']); if ($record['F'] == '正常') { $status = 1; } elseif ($record['F'] == '禁用') { $status = 0; } else { continue; } $destination->setStatus($status); try { $destination->setCtime(date('Y-m-d H:i:s')); $destination->save(); array_push($destinations, $destination); $this->view->destinations = $destinations; } catch (Zend_Db_Exception $e) { } } } } else { echo "<script type='text/javascript'>alert('请上传正确的文件类型')</script>"; } } }