serviceManager = $serviceManager; return $this; } public function getTableGateway() { $this->tableGateway = new TableGateway('attachments',Db::getInstance()); return $this->tableGateway; } private function getWhereObject(){ if(empty($this->where)) $this->where = new Where; return $this->where; } public function getWhere() { return $this->getWhereObject(); } public function setQueryKeyword($keyword){ $this->getWhereObject()->nest() ->OR->like("realname",'%'.$keyword.'%') ->OR->like("realname",'%'.strtolower($keyword).'%') ->OR->like("realname",'%'.strtoupper($keyword).'%'); } public function setQueryType($type){ $this->getWhereObject()->AND->equalTo("filetype",$type); } public function setQueryUser($user){ if($user == "mine") { $authService = $this->serviceManager->get('Auth'); $user = $authService->getIdentity('id'); } $this->getWhereObject()->AND->equalTo("userid",$user); } public function setOrder($order = "",$sort = ""){ if(empty($order) || empty($sort)) return "ts_created DESC"; $sql = $order; if("asc" == strtolower($sort)) return $sql." ASC"; else return $sql." DESC"; } public function upload($file) { $configService = $this->serviceManager->get('ConfigService'); $appConfig = $configService->get('application.ini'); $fileUploadService = $this->serviceManager->get('File/Upload'); $fileUploadService->attachDefaultListener(); $fileUploadService->setParams(['file_type' => 'file']); $file_info = $fileUploadService($file,$appConfig['attachment_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y); if(isset($file_info['error']) && !empty($file_info['error'])) { return array("error" => $file_info['error']); } return $file_info; } }