westdc-zf1/vendor/Sookon/Article/Handle/ArticleHandle.php

103 lines
2.0 KiB
PHP

<?php
namespace Sookon\Article\Handle;
use Sookon\Helpers\PDO as Pdo;
use Sookon\Helpers\Config;
use Sookon\Helpers\View as view;
use Sookon\Mail\Mail;
use Sookon\Search\Search;
use Zend\EventManager\EventInterface;
use Sookon\Article\Event\ArticleEvent as Event;
class ArticleHandle implements Event
{
private $db;
private $config;
function __construct($db = NULL)
{
$this->db = new Pdo();
$this->config = Config::get();
}
//检查字段
public function checkParam(EventInterface $e){
$data = $e->getParam('data');
if(!is_array($data))
{
return "参数错误";
}
if(empty($data["title"]))
{
return "请输入标题";
}
if(empty($data["body"]))
{
return "请输入内容";
}
return true;
}//checkParam
//处理字段
public function processData(EventInterface $e)
{
$data = $e->getParam('data');
if(empty($data['uuid']))
{
unset($data['uuid']);
}
if(empty($data['ts_published']))
{
$data['ts_published'] = date("Y-m-d H:i:s");
}
unset($data['tags']);
unset($data['category']);
return $data;
}
//发布
public function recordPosted(EventInterface $e)
{
$params = $e->getParam('params')['data'];
$data = $e->getParam('data');
$id = $e->getParam('id');
$catelog = new \Sookon\Article\Catelog;
$catelog->AddToCatalog($id,$params['category']);
$tags = new \Sookon\Article\Tags;
$tags->MakeTags($id,$params['tags']);
//view::Dump(array($data,$id,$params));
//return $data;
}
//更改
public function recordChanged(EventInterface $e)
{
$params = $e->getParam('params')['data'];
$data = $e->getParam('data');
$id = $e->getParam('id');
$catelog = new \Sookon\Article\Catelog;
$catelog->ChangeCatalog($id,$params['category']);
$tags = new \Sookon\Article\Tags;
$tags->DeleteTags($id);
$tags->MakeTags($id,$params['tags']);
//return $data;
}
}