westdc-core/Westdc/Metadata/Attachments.php

102 lines
2.6 KiB
PHP
Raw Normal View History

2015-02-08 14:12:08 +00:00
<?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){
2015-02-08 14:18:01 +00:00
$this->getWhereObject()->nest()
->OR->like("realname",'%'.$keyword.'%')
->OR->like("realname",'%'.strtolower($keyword).'%')
2015-02-08 14:12:08 +00:00
->OR->like("realname",'%'.strtoupper($keyword).'%');
}
public function setQueryType($type){
$this->getWhereObject()->AND->equalTo("filetype",$type);
}
2015-02-09 14:26:48 +00:00
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";
}
2015-02-14 13:15:52 +00:00
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;
}
2015-02-08 14:12:08 +00:00
}