102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: liujin834
|
|
* Date: 15/2/8
|
|
* Time: 下午7:45
|
|
*/
|
|
|
|
namespace Westdc\Metadata;
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
|
use Westdc\EventModel\AbstractEventManager;
|
|
use Zend\Db\TableGateway\TableGateway;
|
|
use Westdc\Db\Db;
|
|
use Zend\Db\Sql\Where;
|
|
|
|
class Attachments extends AbstractEventManager implements ServiceManagerAwareInterface{
|
|
|
|
protected $serviceManager;
|
|
|
|
private $tableGateway;
|
|
private $where = NULL;
|
|
|
|
public function setServiceManager(ServiceManager $serviceManager)
|
|
{
|
|
$this->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;
|
|
}
|
|
|
|
} |