<?php
require_once 'basic.php';
require_once 'member.php';
require_once 'TaThreadDao.php';
Wind::import('SRV:forum.srv.PwPost');
Wind::import('SRV:forum.dao.PwForumStatisticsDao');
Wind::import('SRV:forum.dao.PwThreadsCateIndexDao');
Wind::import('SRV:forum.dao.PwThreadsIndexDao');
Wind::import('SRV:forum.dao.PwThreadsContentDao');
Wind::import('SRV:forum.dao.PwThreadsHitsDao');
Wind::import('SRV:forum.dao.PwThreadsDao');
Wind::import('SRV:forum.dao.PwPostsDao');
Wind::import('SRV:user.dao.PwUserDataDao');
Wind::import('SRV:forum.srv.PwForumMiscService');
class targetany_question extends targetany_basic {
public $memberModel;
public $postData;
public $config = array();
public $threadDao = null;
public static function getPostFormat() {
$container = array(
'thread' => array(
'tid' => '',
'fid' => '',
'authorid' => '',
'author' => '',
'subject' => '',
'views' => '', //Hits
'replies' => '',
'digest' => '',
'lastposter' => '',
'price' => 0,
),
'postTableId' => array(), //pid
'threadpartake' => array(), //tid, uid, datetime
'post' => array(
'pid' => '',
'fid' => '',
'tid' => '',
'first' => 0,
'author' => '',
'authorid' => '',
'subject' => '',
'message' => ''
)
);
}
public static function getQuestionKeys() {
return array(
'question_title' => '',
'question_author' => '匿名用户',
'question_detail' => '',
'question_topics' => '',
'question_view_count' => 0,
'question_answer' => '',
'question_publish_time' => time(),
'question_author_avatar' => '',
'question_categories' => ''
);
}
public static function getAnswerKeys() {
return array(
'question_answer_content' => '',
'question_answer_author' => '匿名用户',
'question_answer_agree_count' => 0,
'question_answer_publish_time' => 0,
'question_answer_author_avatar' => '',
'question_answer_comment' => ''
);
}
public static function getCommentKeys() {
return array(
'question_answer_comment_author',
'question_answer_comment_author_avatar',
'question_answer_comment_content',
'question_answer_comment_publish_time'
);
}
public function __construct($postData) {
parent::__construct();
$this->postData = $postData;
$this->getConfigInfo($postData);
return $this;
}
public function getDefaultValue($key, $stdInputs) {
if (isset($stdInputs[$key])) {
return $stdInputs[$key];
}
return '';
}
public function getConfigInfo($postData) {
if (count($postData)) {
foreach ($postData as $key => $item) {
if (in_array($key, self::getConfigKeys())) {
$this->config[$key] = $item;
}
}
}
if (!isset($this->config['min_time'])|| !$this->config['min_time']) {
$this->config['min_time'] = time() - 10000000;
}
if (!isset($this->config['default_forum']) || !$this->config['default_forum']) {
$forums = $this->getFroums();
foreach ($forums as $k => $v) {
$this->config['default_forum'] = $v['value'];
break;
}
}
}
public function getAnswersToPost($answerJson) {
$answers = json_decode($answerJson, true);
$posters = array();
if (!($answers && count($answers))) {
return array();
}
$keys = $this->getAnswerKeys();
foreach ($answers as $answer) {
$post = array();
foreach ($answer as $akey => $value) {
if (isset($keys[$akey])) {
if ($akey == 'question_answer_author') {
if (!$value) {
ta_fail(TA_ERROR_MISSING_FIELD, "Missing question_answer_author", "缺少回复人名称字段");
}
$uid = $this->memberModel->getMember($value);
$post['author'] = $this->_value($value, $keys[$akey]);
$post['authorid'] = $uid;
} else if ($akey == 'question_answer_content') {
if (!$value) {
ta_fail(TA_ERROR_MISSING_FIELD, "Missing question_answer_content", "缺少回复内容字段");
}
$post['message'] = $this->processMessage($value);
} else if ($akey == 'question_answer_publish_time') {
$post['dateline'] = $this->_value($value, $keys[$akey]);
} else if ($akey == 'question_answer_author_avatar') {
$post['avatar'] = $this->_value($value, $keys[$akey]);
} else if ($akey == 'question_answer_comment') {
//$post['avatar'] = $this->_value($value, $keys[$qkey]);
} else if ($akey == 'question_answer_agree_count') {
$post['agree_count'] = $this->_value($value, $keys[$qkey]);
}
}
}
if (isset($post['avatar']) && $post['avatar']) {
$this->memberModel->insertMemberAvatar($post['authorid'], $post['avatar']);
}
$post['first'] = 0;
unset($post['avatar']);
if (!empty($post)) {
$posters[] = $post;
}
}
return $posters;
}
public function processMessage($content) {
$content = $this->parse_html($content);
return $content;
}
public function loadPostData() {
$post = array();
$otherPosts = array();
$keys = $this->getQuestionKeys();
foreach ($this->postData as $qkey => $value) {
if (isset($keys[$qkey])) {
if ($qkey == 'question_answer') {
$otherPosts = $this->getAnswersToPost($value);
} else if ($qkey == 'question_topics' || $qkey == 'question_categories') {
$post['topics'] = json_decode($value, true);
} else if ($qkey == 'question_title') {
if (!$value) {
ta_fail(TA_ERROR_MISSING_FIELD, "Missing question_title", "缺少帖子标题");
}
$post['subject'] = $this->_value($value, $keys[$qkey]);
} else if ($qkey == 'question_author') {
if (!$value) {
ta_fail(TA_ERROR_MISSING_FIELD, "Missing question_author", "缺少发帖人名称字段");
}
$uid = $this->memberModel->getMember($value);
$post['author'] = $this->_value($value, $keys[$qkey]);
$post['authorid'] = $uid;
} else if ($qkey == 'question_detail') {
if (!$value) {
ta_fail(TA_ERROR_MISSING_FIELD, "Missing question_detail", "缺少帖子内容字段");
}
$post['message'] = $this->processMessage($value);
} else if ($qkey == 'question_view_count') {
$post['views'] = $this->_value($value, $keys[$qkey]);
} else if ($qkey == 'question_publish_time') {
$post['dateline'] = $this->_value($value, $keys[$qkey]);
} else if ($qkey == 'question_author_avatar') {