PageRenderTime 58ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/library/Dao/Td/Tudu/Tudu.php

https://github.com/polokk/tudu-web-1
PHP | 2328 lines | 1572 code | 332 blank | 424 comment | 323 complexity | 82f155822ecd9b08f290aa459db9b898 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Tudu Dao
  4. *
  5. * LICENSE
  6. *
  7. *
  8. * @category Dao
  9. * @package Dao_Td
  10. * @subpackage Tudu
  11. * @copyright Copyright (c) 2009-2010 Shanghai Best Oray Information S&T CO., Ltd.
  12. * @link http://www.oray.com/
  13. * @version $Id: Tudu.php 2809 2013-04-07 09:57:05Z cutecube $
  14. */
  15. /**
  16. * @category Dao
  17. * @package Dao_Td
  18. * @subpackage Tudu
  19. * @copyright Copyright (c) 2009-2010 Shanghai Best Oray Information S&T CO., Ltd.
  20. */
  21. class Dao_Td_Tudu_Tudu extends Oray_Dao_Abstract
  22. {
  23. const STATUS_UNSTART = 0; // 未开始
  24. const STATUS_DOING = 1; // 进行中
  25. const STATUS_DONE = 2; // 已完成
  26. const STATUS_REJECT = 3; // 已拒绝
  27. const STATUS_CANCEL = 4; // 已取消
  28. const SPECIAL_CYCLE = 1;
  29. const SPECIAL_VOTE = 2; // 投票
  30. const TYPE_TASK = 'task';
  31. const TYPE_NOTICE = 'notice';
  32. const TYPE_DISCUSS = 'discuss';
  33. const TYPE_MEETING = 'meeting';
  34. /**
  35. * 用户角色
  36. * @var string
  37. */
  38. const ROLE_ACCEPTER = 'to'; // 接收人
  39. const ROLE_SENDER = 'from'; // 发送人
  40. const ROLE_CC = 'cc'; // 被抄送
  41. /**
  42. * Initialize object
  43. *
  44. * Called from {@link __construct()} as final step of object instantiation.
  45. *
  46. * @return void
  47. */
  48. public function init()
  49. {}
  50. /**
  51. * Get record
  52. *
  53. * SELECT t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid,
  54. * t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy,
  55. * p.post_id AS postid, p.content, p.poster_info AS posterinfo, p.attach_num AS attachnum,
  56. * t.last_post_time AS lastposttime, t.last_poster AS lastposter,
  57. * t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum,
  58. * t.percent, t.score, t.status, t.special,
  59. * t.start_time AS starttime, t.end_time AS endtime,
  60. * t.total_time AS totaltime, t.elapsed_time AS elapsedtime,
  61. * t.accept_time AS accepttime, t.create_time AS create_time,
  62. * tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels,
  63. * tu.is_read AS isread, tu.is_forward AS isforward,
  64. * t.is_draft AS isdraft, t.is_done AS isdone
  65. * FROM td_tudu t
  66. * LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1
  67. * LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = ?
  68. * WHERE t.tudu_id = ?
  69. *
  70. * @param array $condition
  71. * @param array $filter
  72. * @return Dao_Td_Tudu_Record_Tudu
  73. */
  74. public function getTudu(array $condition, $filter = null)
  75. {
  76. if (empty($condition['tuduid'])
  77. || empty($condition['uniqueid'])) {
  78. return null;
  79. }
  80. $table = "td_tudu t "
  81. . "LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1 "
  82. . "LEFT JOIN td_tudu_group g ON g.tudu_id = p.tudu_id "
  83. . "LEFT JOIN td_class c ON t.class_id = c.class_id AND t.org_id = c.org_id AND t.board_id = c.board_id "
  84. . "LEFT JOIN td_flow f ON t.flow_id = f.flow_id AND t.org_id = f.org_id AND t.board_id = f.board_id "
  85. . "LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = "
  86. . $this->_db->quote($condition['uniqueid']) . " "
  87. . "LEFT JOIN td_tudu_flow fl ON fl.tudu_id = t.tudu_id";
  88. $columns = "t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid, t.prev_tudu_id AS prevtuduid, "
  89. . "t.type, t.subject, t.from, t.to, t.cc, t.bcc, t.priority, t.privacy, t.password, t.is_auth AS isauth, fl.current_step_id AS stepid, "
  90. . "p.post_id AS postid, p.content, p.header, p.poster_info AS posterinfo, p.attach_num AS attachnum, t.app_id AS appid, "
  91. . "t.last_post_time AS lastposttime, t.last_poster AS lastposter, t.last_forward AS lastforward, "
  92. . "t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, t.cycle_num AS cyclenum, "
  93. . "fl.step_num as stepnum, t.percent, t.score, t.status, t.special, t.notify_all AS notifyall, t.accep_mode AS accepmode,"
  94. . "t.start_time AS starttime, t.end_time AS endtime, t.need_confirm AS needconfirm, "
  95. . "t.total_time AS totaltime, t.elapsed_time AS elapsedtime, "
  96. . "t.accept_time AS accepttime, t.create_time AS createtime, "
  97. . "tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels, "
  98. . "tu.is_read AS isread, tu.is_forward AS isforward, tu.mark, "
  99. . "tu.role, tu.percent AS selfpercent, tu.forward_info AS forwardinfo, "
  100. . "tu.tudu_status AS selftudustatus, tu.accept_time AS selfaccepttime, tu.auth_code AS authcode, "
  101. . "t.is_draft AS isdraft, t.is_done AS isdone, t.is_top AS istop, p.is_send AS issend, "
  102. . "t.class_id AS classid, t.flow_id AS flowid, c.class_name AS classname, "
  103. . "g.type AS nodetype, g.parent_tudu_id AS parentid, g.root_tudu_id AS rootid";
  104. $where = array();
  105. $where[] = 't.tudu_id = ' . $this->_db->quote($condition['tuduid']);
  106. if (isset($filter['orgid'])) {
  107. $where[] = 't.org_id = ' . $this->_db->quote($filter['orgid']);
  108. }
  109. // WHERE
  110. $where = implode(' AND ', $where);
  111. $sql = "SELECT {$columns} FROM {$table} WHERE {$where} LIMIT 0, 1";
  112. $record = $this->_db->fetchRow($sql);
  113. if (!$record) {
  114. return null;
  115. }
  116. return Oray_Dao::record('Dao_Td_Tudu_Record_Tudu', $record);
  117. }
  118. /**
  119. * Get records
  120. *
  121. * SQL here..
  122. *
  123. * @param array $condition
  124. * @param array $filter
  125. * @param array $sort
  126. * @param int $maxCount
  127. * @return Oray_Dao_Recordset
  128. */
  129. public function getTudus(array $condition, $filter = null, $sort = null, $maxCount = null)
  130. {
  131. $table = "td_tudu t LEFT JOIN td_tudu_group g ON t.tudu_id = g.tudu_id";
  132. $columns = 't.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, `from`, `to`, is_draft AS isdraft, subject, '
  133. . 'g.type AS nodetype, g.parent_tudu_id AS parentid';
  134. $where = array();
  135. $order = array();
  136. $limit = '';
  137. if (!empty($condition['tuduids']) && is_array($condition['tuduids'])) {
  138. $where[] = 't.tudu_id IN(' . implode(',', array_map(array($this->_db, 'quote'), $condition['tuduids'])) . ')';
  139. }
  140. if (!empty($condition['parentid'])) {
  141. $where[] = 'g.parent_tudu_id = ' . $this->_db->quote($condition['parentid']);
  142. if (!empty($condition['uniqueid'])) {
  143. $where[] = 'g.unique_id = ' . $this->_db->quote($condition['uniqueid']);
  144. }
  145. }
  146. if (empty($where)) {
  147. return new Oray_Dao_Recordset();
  148. }
  149. // WHERE
  150. $where = implode(' AND ', $where);
  151. if ($where) {
  152. $where = 'WHERE ' . $where;
  153. }
  154. $sort = $this->_formatSort($sort);
  155. foreach ($sort as $key => $val) {
  156. switch ($key) {
  157. default:
  158. continue 2;
  159. }
  160. $order[] = $key . ' ' . $val;
  161. }
  162. // ORDER
  163. $order = implode(', ', $order);
  164. if ($order) {
  165. $order = 'ORDER BY ' . $order;
  166. }
  167. // LIMIT
  168. if (is_int($maxCount) && $maxCount > 0) {
  169. $limit = 'LIMIT ' . $maxCount;
  170. }
  171. $sql = "SELECT $columns FROM $table $where $order $limit";
  172. $records = $this->_db->fetchAll($sql);
  173. return new Oray_Dao_Recordset($records, 'Dao_Td_Tudu_Record_Tudus');
  174. }
  175. /**
  176. *
  177. * @param $condition
  178. * @param $filter
  179. */
  180. public function getUserTudus(array $condition, $filter = null, $offset = null, $count = null)
  181. {
  182. $table = "td_tudu t "
  183. . "LEFT JOIN td_tudu_group g ON g.tudu_id = t.tudu_id "
  184. . "LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = "
  185. . $this->_db->quote($condition['uniqueid'])
  186. . "LEFT JOIN td_post AS p ON p.tudu_id = t.tudu_id AND p.is_first = 1";
  187. $columns = "t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.is_done AS isdone, t.percent, t.cycle_id AS cycleid, t.percent, t.reply_num AS replynum, t.accept_time AS lastaccepttime, "
  188. . "t.last_post_time AS lastposttime, t.is_done, t.priority, t.privacy, t.password, t.start_time AS starttime, t.end_time AS endtime, p.attach_num AS attachnum, tu.accept_time as accepttime, "
  189. . "t.type, t.subject, t.from, t.to, t.cc, t.bcc, t.status, t.is_draft AS isdraft, t.need_confirm AS needconfirm, tu.unique_id AS uniqueid, "
  190. . "TRIM(LEADING ',' FROM tu.labels) labels, tu.role, tu.accepter_info AS accepterinfo, tu.tudu_status AS selfstatus, tu.is_read as isread, g.type as nodetype ";
  191. $where = array();
  192. $limit = '';
  193. if (empty($condition)) {
  194. return null;
  195. }
  196. if (!empty($condition['uniqueid'])) {
  197. $where[] = 'tu.unique_id = ' . $this->_db->quote($condition['uniqueid']);
  198. }
  199. if (!empty($condition['labelid'])) {
  200. $table .= ' LEFT JOIN td_tudu_label AS tl ON tl.unique_id = tu.unique_id AND tl.tudu_id = tu.tudu_id';
  201. $where[] = 'tl.label_id = ' . $this->_db->quote($condition['labelid']);
  202. }
  203. if (!empty($condition['type'])) {
  204. $where[] = 't.type = ' . $this->_db->quote($condition['type']);
  205. }
  206. // 关键字
  207. if (!empty($condition['keyword'])) {
  208. $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
  209. $where[] = 't.subject LIKE ' . $keyword;
  210. }
  211. if (!$filter || !isset($filter['role']) || $filter['role'] == true) {
  212. $where[] = 'tu.role IS NOT NULL';
  213. }
  214. if (!$filter || !isset($filter['isdone']) || $filter['isdone'] == true) {
  215. $where[] = 't.status <= 2';
  216. $where[] = 't.is_done = 0';
  217. }
  218. $where = implode(' AND ', $where);
  219. if ($where) {
  220. $where = 'WHERE ' . $where;
  221. }
  222. if (null !== $count) {
  223. $limit = 'LIMIT';
  224. if (null !== $offset) {
  225. $limit .= ' ' . (int) $offset . ',';
  226. }
  227. $limit .= ' ' . (int) $count;
  228. }
  229. $sql = "SELECT $columns FROM $table $where ORDER BY last_post_time DESC $limit";
  230. $records = $this->_db->fetchAll($sql);
  231. if (!$records) {
  232. return array();
  233. }
  234. return $records;
  235. }
  236. /**
  237. * 读取图度组
  238. *
  239. * @param array $condition
  240. * @param array $filter
  241. */
  242. public function getTuduGroups(array $condition, $filter = null)
  243. {
  244. $table = "td_tudu t "
  245. . "LEFT JOIN td_tudu_group g ON g.tudu_id = t.tudu_id "
  246. . "INNER JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id";
  247. $columns = "t.org_id AS orgid, t.board_id AS boardid, tu.unique_id AS uniqueid, t.tudu_id AS tuduid, "
  248. . "t.subject, t.type, t.from, t.to, g.type AS nodetype";
  249. $where = array();
  250. $bind = array();
  251. if (isset($condition['uniqueid'])) {
  252. $where[] = "tu.unique_id = :uniqueid";
  253. $bind['uniqueid'] = $condition['uniqueid'];
  254. }
  255. if (isset($condition['orgid'])) {
  256. $where[] = "t.org_id = :orgid";
  257. $bind['orgid'] = $condition['orgid'];
  258. }
  259. if ($filter && array_key_exists('isdraft', $filter)) {
  260. if (null !== $filter['isdraft']) {
  261. $where[] = "t.is_draft = " . ($filter['isdraft'] ? 1 : 0);
  262. }
  263. } else {
  264. $where[] = "t.is_draft = 0";
  265. }
  266. if ($filter && array_key_exists('isdone', $filter)) {
  267. if (null !== $filter['isdone']) {
  268. $where[] = "t.is_done = " . ($filter['isdone'] ? 1 : 0);
  269. }
  270. } else {
  271. $where[] = "t.is_done = 0";
  272. }
  273. $where[] = "(g.type = 'node' OR g.type = 'root')";
  274. // WHERE
  275. $where = implode(' AND ', $where);
  276. if ($where) {
  277. $where = 'WHERE ' . $where;
  278. }
  279. $sql = "SELECT $columns FROM $table $where ORDER BY t.last_post_time DESC";
  280. $records = $this->_db->fetchAll($sql, $bind);
  281. if (!$records) {
  282. return new Oray_Dao_Recordset();
  283. }
  284. return new Oray_Dao_Recordset($records, 'Dao_Td_Tudu_Record_TuduGroups');
  285. }
  286. /**
  287. *
  288. *
  289. * @param $condition
  290. * @param $filter
  291. * @param $sort
  292. * @param $maxCount
  293. */
  294. public function getGroupTudus(array $condition, $filter = null, $sort = null, $maxCount = null)
  295. {
  296. $table = "td_tudu t "
  297. . "LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1 "
  298. . "LEFT JOIN td_tudu_group g ON g.tudu_id = p.tudu_id "
  299. . "LEFT JOIN td_class c ON t.class_id = c.class_id AND t.org_id = c.org_id AND t.board_id = c.board_id "
  300. . "LEFT JOIN td_tudu_flow fl ON fl.tudu_id = t.tudu_id "
  301. . "LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = "
  302. . $this->_db->quote($condition['uniqueid']);
  303. $columns = "t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid, t.prev_tudu_id AS prevtuduid, "
  304. . "t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy, t.password, fl.current_step_id AS stepid, "
  305. . "p.post_id AS postid, '' AS content, '' AS posterinfo, p.attach_num AS attachnum, "
  306. . "t.last_post_time AS lastposttime, t.last_poster AS lastposter, t.last_forward AS lastforward, "
  307. . "t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, "
  308. . "t.percent, t.score, t.status, t.special, t.notify_all AS notifyall, t.accep_mode AS accepmode, "
  309. . "t.start_time AS starttime, t.end_time AS endtime, t.complete_time AS completetime, t.need_confirm AS needconfirm, "
  310. . "t.total_time AS totaltime, t.elapsed_time AS elapsedtime, "
  311. . "t.accept_time AS accepttime, t.create_time AS createtime, "
  312. . "tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels, "
  313. . "tu.is_read AS isread, tu.is_forward AS isforward, tu.mark, "
  314. . "tu.role, tu.percent AS selfpercent, tu.forward_info AS forwardinfo, "
  315. . "tu.tudu_status AS selftudustatus, tu.accept_time AS selfaccepttime, "
  316. . "t.is_draft AS isdraft, t.is_done AS isdone, t.is_top AS istop, p.is_send AS issend, "
  317. . "t.class_id AS classid, t.flow_id AS flowid, c.class_name AS classname, "
  318. . "g.type AS nodetype, g.parent_tudu_id AS parentid";
  319. $where = array();
  320. $order = array();
  321. $limit = '';
  322. if (!empty($condition['tuduids']) && is_array($condition['tuduids'])) {
  323. $where[] = 't.tudu_id IN(' . implode(',', array_map(array($this->_db, 'quote'), $condition['tuduids'])) . ')';
  324. }
  325. if (!empty($condition['parentid'])) {
  326. $where[] = 'g.parent_tudu_id = ' . $this->_db->quote($condition['parentid']);
  327. }
  328. if (!empty($condition['senderid'])) {
  329. $where[] = 'g.unique_id = ' . $this->_db->quote($condition['senderid']);
  330. }
  331. if (!empty($condition['role'])) {
  332. $where[] = 'tu.role = ' . $this->_db->quote($condition['role']);
  333. }
  334. if (!empty($condition['starttime']) && !empty($condition['endtime'])) {
  335. $startTime = (int) $condition['starttime'];
  336. $endTime = (int) $condition['endtime'];
  337. $where[] = "(((t.start_time >= {$startTime} AND t.start_time <= {$endTime}) "
  338. . "OR (t.end_time >= {$startTime} AND t.end_time <= {$endTime}) "
  339. . "OR ((t.start_time <= {$startTime} OR t.start_time IS NULL) "
  340. . "AND (t.end_time >= {$endTime} OR t.end_time IS NULL)))"
  341. . "AND (((t.complete_time <= {$endTime} AND t.complete_time >= {$startTime}) "
  342. . "OR (t.complete_time >= {$endTime} AND t.complete_time >= {$startTime})) "
  343. . "OR t.complete_time IS NULL) OR (t.status <= 1 AND DATEDIFF(FROM_UNIXTIME(UNIX_TIMESTAMP(), '%Y-%m-%d'), FROM_UNIXTIME(t.end_time, '%Y-%m-%d')) > 0 AND t.end_time <= {$endTime}))";
  344. // 不显示“已取消”,和“已拒绝并确认“的图度
  345. $where[] = '(t.status <= 2 OR (t.status = 3 AND t.is_done = 0)) ';
  346. }
  347. if ($filter && array_key_exists('isdraft', $filter)) {
  348. if (null !== $filter['isdraft']) {
  349. $where[] = 't.is_draft = ' . ($filter['isdraft'] ? 1 : 0);
  350. }
  351. } else {
  352. $where[] = 't.is_draft = 0';
  353. }
  354. if (empty($where)) {
  355. return new Oray_Dao_Recordset();
  356. }
  357. // WHERE
  358. $where = implode(' AND ', $where);
  359. if ($where) {
  360. $where = 'WHERE ' . $where;
  361. }
  362. $sort = $this->_formatSort($sort);
  363. foreach ($sort as $key => $val) {
  364. switch ($key) {
  365. case 'lastposttime':
  366. $key = 'last_post_time';
  367. break;
  368. case 'subject':
  369. $key = 'subject';
  370. break;
  371. case 'endtime':
  372. $key = 'end_time';
  373. break;
  374. case 'from':
  375. $key = '`from`';
  376. break;
  377. case 'to':
  378. $key = '`to`';
  379. break;
  380. case 'istop':
  381. $key = 'is_top';
  382. break;
  383. default:
  384. continue 2;
  385. break;
  386. }
  387. $order[] = $key . ' ' . $val;
  388. }
  389. // ORDER
  390. $order = implode(', ', $order);
  391. if ($order) {
  392. $order = 'ORDER BY ' . $order;
  393. }
  394. // LIMIT
  395. if (is_int($maxCount) && $maxCount > 0) {
  396. $limit = 'LIMIT ' . $maxCount;
  397. }
  398. $sql = "SELECT $columns FROM $table $where $order $limit";
  399. $records = $this->_db->fetchAll($sql);
  400. return new Oray_Dao_Recordset($records, 'Dao_Td_Tudu_Record_Tudu');
  401. }
  402. /**
  403. * 获取用户图度箱的图度列表
  404. *
  405. * SELECT t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid,
  406. * t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy,
  407. * t.last_post_time AS lastposttime, t.last_poster AS lastposter,
  408. * t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, t.percent, t.score, t.status,
  409. * t.start_time AS starttime, t.end_time AS endtime,
  410. * t.total_time AS totaltime, t.elapsed_time AS elapsedtime,
  411. * t.create_time AS create_time, p.post_id AS postid, p.content, '' AS posterinfo, p.attach_num AS attachnum,
  412. * tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels,
  413. * tu.is_read AS isread, tu.is_forward AS isforward, is_draft AS isdraft, is_done AS isdone
  414. * FROM td_tudu t
  415. * LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1
  416. * INNER JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id
  417. * LEFT JOIN td_tudu_label tl ON tl.tudu_id = t.tudu_id AND tl.unique_id = tu.unique_id
  418. * WHERE tu.unique_id = ? AND tl.label_id = ?
  419. *
  420. * @param array $condition
  421. * @param mixed $sort
  422. * @param int $page
  423. * @param int $pageSize
  424. * @return Oray_Dao_Recordset
  425. */
  426. public function getTuduPage(array $condition = null, $sort = null, $page = null, $pageSize = null)
  427. {
  428. $table = 'td_tudu t '
  429. . 'LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1 '
  430. . 'LEFT JOIN td_tudu_group g ON g.tudu_id = p.tudu_id '
  431. . 'INNER JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id '
  432. . "LEFT JOIN td_class c ON t.class_id = c.class_id AND t.org_id = c.org_id AND t.board_id = c.board_id "
  433. . 'LEFT JOIN td_tudu_label tl ON tl.tudu_id = t.tudu_id AND tl.unique_id = tu.unique_id '
  434. . 'LEFT JOIN td_tudu_cycle tc ON tc.cycle_id = t.cycle_id '
  435. . 'LEFT JOIN td_tudu_flow fl ON fl.tudu_id = t.tudu_id ';
  436. $columns = "t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid, t.prev_tudu_id AS prevtuduid, "
  437. . "t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy, t.password, fl.current_step_id AS stepid, t.app_id AS appid, "
  438. . "t.last_post_time AS lastposttime, t.last_poster AS lastposter, t.last_forward AS lastforward, t.flow_id AS flowid, "
  439. . "t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, t.percent, t.score, t.status, "
  440. . "t.special, t.start_time AS starttime, t.end_time AS endtime, t.complete_time AS completetime, t.notify_all AS notifyall, "
  441. . "t.total_time AS totaltime, t.elapsed_time AS elapsedtime, t.need_confirm AS needconfirm, "
  442. . "t.create_time AS createtime, t.accept_time AS accepttime, t.accep_mode AS accepmode, "
  443. . "p.post_id AS postid, '' AS content, '' AS posterinfo, p.attach_num AS attachnum, "
  444. . "tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels, tu.mark, "
  445. . "tu.is_read AS isread, tu.is_forward AS isforward, is_draft AS isdraft, t.is_done AS isdone, t.is_top AS istop, "
  446. . "tu.role, tu.percent AS selfpercent, tu.forward_info AS forwardinfo, "
  447. . "tu.tudu_status AS selftudustatus, tu.accept_time AS selfaccepttime, "
  448. . "t.class_id AS classid, c.class_name AS classname, tc.display_date AS displaydate, "
  449. . "g.type AS nodetype, g.parent_tudu_id AS parentid";
  450. $primary = "t.tudu_id";
  451. $recordClass = "Dao_Td_Tudu_Record_Tudu";
  452. $where = array();
  453. $order = array();
  454. // $condition...
  455. if (isset($condition['tuduindexnum'])) {
  456. if (is_array($condition['tuduindexnum'])) {
  457. $arr = array_map('intval', $condition['tuduindexnum']);
  458. $where[] = 't.tudu_index_num IN (' . implode(',', $arr) . ')';
  459. } else {
  460. $where[] = 't.tudu_index_num = ' . $condition['tuduindexnum'];
  461. }
  462. }
  463. if (isset($condition['uniqueid'])) {
  464. $where[] = 'tu.unique_id = ' . $this->_db->quote($condition['uniqueid']);
  465. }
  466. if (isset($condition['label'])) {
  467. $where[] = 'tl.label_id = ' . $this->_db->quote($condition['label']);
  468. }
  469. // 板块
  470. if (isset($condition['boardid'])) {
  471. $where[] = 't.board_id = ' . $this->_db->quote($condition['boardid']);
  472. }
  473. // 主题分类
  474. if (isset($condition['classid'])) {
  475. $where[] = 't.class_id = ' . $this->_db->quote($condition['classid']);
  476. }
  477. // 查找已读状态
  478. if (isset($condition['isread'])) {
  479. $where[] = 'tu.is_read = ' . ($condition['isread'] ? 1 : 0);
  480. }
  481. // 关键字
  482. if (!empty($condition['keyword'])) {
  483. $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
  484. $where[] = 't.subject LIKE ' . $keyword;
  485. }
  486. // 发送人
  487. if (!empty($condition['from'])) {
  488. $from = $this->_db->quote('%' . $condition['from'] . '%');
  489. $where[] = 't.from LIKE ' . $from;
  490. }
  491. // 接收人
  492. if (!empty($condition['to'])) {
  493. $to = $this->_db->quote('%' . $condition['to'] . '%');
  494. $where[] = 't.to LIKE ' . $to;
  495. }
  496. // 状态
  497. if (isset($condition['status'])) {
  498. if (is_array($condition['status'])) {
  499. foreach ($condition['status'] as $item) {
  500. $status[] = $this->_db->quote($item);
  501. }
  502. $where[] = 't.status IN (' . implode(',', $status) . ')';
  503. } else if (is_int($condition['status'])) {
  504. $where[] = 't.status = ' . $condition['status'];
  505. }
  506. }
  507. // 类型
  508. if (!empty($condition['type'])) {
  509. $where[] = 't.type = ' . $this->_db->quote($condition['type']);
  510. }
  511. // 已完成
  512. if (isset($condition['isdone'])) {
  513. $where[] = 't.is_done = ' . ($condition['isdone'] ? 1 : 0);
  514. }
  515. // 甘特图
  516. if(!empty($condition['startdate']) && !empty($condition['enddate'])) {
  517. $startDate = (int) $condition['startdate'];
  518. $endDate = (int) $condition['enddate'];
  519. $where[] = "(((t.start_time >= {$startDate} AND t.start_time <= {$endDate}) "
  520. . "OR (t.end_time >= {$startDate} AND t.end_time <= {$endDate}) "
  521. . "OR ((t.start_time <= {$startDate} OR t.start_time IS NULL) "
  522. . "AND (t.end_time >= {$endDate} OR t.end_time IS NULL)))"
  523. . "AND (((t.complete_time <= {$endDate} AND t.complete_time >= {$startDate}) "
  524. . "OR (t.complete_time >= {$endDate} AND t.complete_time >= {$startDate})) "
  525. . "OR t.complete_time IS NULL) OR (t.status <= 1 AND DATEDIFF(FROM_UNIXTIME(UNIX_TIMESTAMP(), '%Y-%m-%d'), FROM_UNIXTIME(t.end_time, '%Y-%m-%d')) > 0 AND t.end_time <= {$endDate}))";
  526. }
  527. $array = array(
  528. 'createtime' => 't.create_time',
  529. 'endtime' => 't.end_time',
  530. 'starttime' => 't.start_time'
  531. );
  532. // createtime, endtime, starttime
  533. foreach ($array as $key => $col) {
  534. if (!isset($condition[$key])) {
  535. continue ;
  536. }
  537. if (is_array($condition[$key])) {
  538. $arr = array();
  539. if (isset($condition[$key]['start'])) {
  540. $arr[] = $col . ' >= ' . (int) $condition[$key]['start'];
  541. }
  542. if (isset($condition[$key]['end'])) {
  543. $arr[] = $col . ' <= ' . (int) $condition[$key]['end'];
  544. }
  545. if ($arr) {
  546. $where[] = '(' . $col . ' IS NOT NULL AND ' . implode(' AND ', $arr) . ')';
  547. }
  548. } elseif (is_int($condition[$key])) {
  549. $where[] = '(' . $col . ' IS NOT NULL AND ' . $col . ' >= ' . $condition[$key] . ')';
  550. }
  551. }
  552. // 过期
  553. if (isset($condition['expiredate']) && is_int($condition['expiredate'])) {
  554. $where[] = '(tu.is_read = 0 OR t.start_time IS NULL OR t.start_time <= ' . $condition['expiredate'] . ')';
  555. }
  556. // WHERE
  557. $where = implode(' AND ', $where);
  558. if ($where) {
  559. $where = 'WHERE ' . $where;
  560. }
  561. // 格式化排序参数
  562. $sort = $this->_formatSort($sort);
  563. foreach ($sort as $key => $val) {
  564. switch ($key) {
  565. case 'lastposttime':
  566. $key = 'last_post_time';
  567. break;
  568. case 'subject':
  569. $key = 'subject';
  570. break;
  571. case 'endtime':
  572. $key = 'end_time';
  573. break;
  574. case 'starttime':
  575. $key = 'start_time';
  576. break;
  577. case 'from':
  578. $key = '`from`';
  579. break;
  580. case 'to':
  581. $key = '`to`';
  582. break;
  583. case 'istop':
  584. $key = 'is_top';
  585. break;
  586. case 'percent':
  587. $key = 'percent';
  588. break;
  589. default:
  590. continue 2;
  591. break;
  592. }
  593. $order[] = $key . ' ' . $val;
  594. }
  595. // ORDER
  596. $order = implode(', ', $order);
  597. if ($order) {
  598. $order = 'ORDER BY ' . $order;
  599. }
  600. if (null === $pageSize && null === $page) {
  601. $sql = "SELECT $columns FROM $table $where $order";
  602. } else {
  603. // 使用默认的分页大小
  604. if (null === $pageSize) {
  605. $pageSize = self::$_defaultPageSize;
  606. }
  607. if ($page < 1) $page = 1;
  608. $sql = "SELECT $columns FROM $table $where $order LIMIT " . $pageSize * ($page - 1) . ", " . $pageSize;
  609. }
  610. $records = $this->_db->fetchAll($sql);
  611. return new Oray_Dao_Recordset($records, $recordClass);
  612. }
  613. /**
  614. * 获取版块的图度列表
  615. *
  616. * SELECT
  617. * t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid,
  618. * t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy,
  619. * t.last_post_time AS lastposttime, t.last_poster AS lastposter,
  620. * t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, t.percent, t.score, t.status,
  621. * t.special, t.start_time AS starttime, t.end_time AS endtime,
  622. * t.total_time AS totaltime, t.elapsed_time AS elapsedtime,
  623. * t.create_time AS createtime, t.accept_time AS accepttime,
  624. * p.post_id AS postid, '' AS content, '' AS posterinfo, p.attach_num AS attachnum,
  625. * tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels,
  626. * tu.is_read AS isread, tu.is_forward AS isforward, is_draft AS isdraft, is_done AS isdone,
  627. * g.type AS nodetype, g.parent_tudu_id AS parentid
  628. *
  629. * FROM td_tudu t
  630. * LEFT JOIN td_tudu_group g ON g.tudu_id = p.tudu_id
  631. * LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1
  632. * LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = ?
  633. *
  634. * WHERE t.is_draft = 0
  635. * AND t.org_id = ?
  636. * AND t.board_id = ?
  637. *
  638. * @param array $condition
  639. * @param mixed $sort
  640. * @param int $page
  641. * @param int $pageSize
  642. * @return Oray_Dao_Recordset
  643. */
  644. public function getBoardTuduPage(array $condition = null, $sort = null, $page = null, $pageSize = null)
  645. {
  646. $uniqueId = isset($condition['uniqueid'])
  647. ? $this->_db->quote($condition['uniqueid'])
  648. : "''";
  649. $table = "td_tudu t "
  650. . "LEFT JOIN td_post p ON p.tudu_id = t.tudu_id AND p.is_first = 1 "
  651. . "LEFT JOIN td_tudu_group g ON g.tudu_id = p.tudu_id "
  652. . "LEFT JOIN td_class c ON t.class_id = c.class_id AND t.org_id = c.org_id AND t.board_id = c.board_id "
  653. . 'LEFT JOIN td_tudu_cycle tc ON tc.cycle_id = t.cycle_id '
  654. . "LEFT JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id AND tu.unique_id = " . $uniqueId;
  655. $columns = "t.org_id AS orgid, t.board_id AS boardid, t.tudu_id AS tuduid, t.cycle_id AS cycleid, "
  656. . "t.type, t.subject, t.from, t.to, t.cc, t.priority, t.privacy, t.password, "
  657. . "t.last_post_time AS lastposttime, t.last_poster AS lastposter, t.flow_id AS flowid, "
  658. . "t.view_num AS viewnum, t.reply_num AS replynum, t.log_num AS lognum, t.percent, t.score, t.status, "
  659. . "t.special, t.start_time AS starttime, t.end_time AS endtime, t.need_confirm AS needconfirm, "
  660. . "t.total_time AS totaltime, t.elapsed_time AS elapsedtime, t.accep_mode AS accepmode, "
  661. . "t.create_time AS createtime, t.accept_time AS accepttime, "
  662. . "p.post_id AS postid, '' AS content, '' AS posterinfo, p.attach_num AS attachnum, "
  663. . "tu.unique_id AS uniqueid, TRIM(LEADING ',' FROM tu.labels) labels, tu.mark, "
  664. . "tu.is_read AS isread, tu.is_forward AS isforward, is_draft AS isdraft, is_done AS isdone, t.is_top AS istop, "
  665. . "t.class_id AS classid, c.class_name AS classname, tc.display_date AS displaydate, "
  666. . "g.type AS nodetype, g.parent_tudu_id AS parentid";
  667. $primary = "t.tudu_id";
  668. $recordClass = "Dao_Td_Tudu_Record_Tudu";
  669. $where = array();
  670. $order = array();
  671. if (isset($condition['orgid'])) {
  672. $where[] = 't.org_id = ' . $this->_db->quote($condition['orgid']);
  673. }
  674. if (isset($condition['boardid'])) {
  675. if (is_array($condition['boardid'])) {
  676. $where[] = 't.board_id IN(' . implode(',', array_map(array($this->_db, 'quote'), $condition['boardid'])) . ')';
  677. } else {
  678. $where[] = 't.board_id = ' . $this->_db->quote($condition['boardid']);
  679. }
  680. }
  681. // 关键字
  682. if (!empty($condition['keyword'])) {
  683. $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
  684. $where[] = 't.subject LIKE ' . $keyword;
  685. }
  686. // 发送人
  687. if (!empty($condition['from'])) {
  688. $from = $this->_db->quote('%' . $condition['from'] . '%');
  689. $where[] = 't.from LIKE ' . $from;
  690. }
  691. // 接收人
  692. if (!empty($condition['to'])) {
  693. $to = $this->_db->quote('%' . $condition['to'] . '%');
  694. $where[] = 't.to LIKE ' . $to;
  695. }
  696. // 主题分类
  697. if (isset($condition['classid'])) {
  698. $where[] = 'c.class_id = ' . $this->_db->quote($condition['classid']);
  699. }
  700. // 类型
  701. if (!empty($condition['type'])) {
  702. if (is_array($condition['type'])) {
  703. $where[] = 't.type IN ( ' . implode(',', array_map(array($this->_db, 'quote'), $condition['type'])) . ')';
  704. } else {
  705. $where[] = 't.type = ' . $this->_db->quote($condition['type']);
  706. }
  707. }
  708. if (isset($condition['priority']) && is_int($condition['priority'])) {
  709. $where[] = 't.priority = ' . $condition['priority'];
  710. }
  711. if (isset($condition['status']) && is_int($condition['status'])) {
  712. $where[] = 't.status = ' . $condition['status'];
  713. }
  714. // 创建时间
  715. if (isset($condition['createtime'])) {
  716. if (is_array($condition['createtime'])) {
  717. $array = array();
  718. if (isset($condition['createtime']['start']) && is_int($condition['createtime']['start'])) {
  719. $array[] = 't.create_time >= ' . $condition['createtime']['start'];
  720. }
  721. if (isset($condition['createtime']['end']) && is_int($condition['createtime']['end'])) {
  722. $array[] = 't.create_time <= ' . $condition['createtime']['end'];
  723. }
  724. if ($array) {
  725. $where[] = '(' . implode(' AND ', $array) . ')';
  726. }
  727. } elseif (is_int($condition['createtime'])) {
  728. $where[] = 't.create_time >= ' . $condition['createtime'];
  729. }
  730. }
  731. // 创建时间
  732. if (isset($condition['endtime'])) {
  733. if (is_array($condition['endtime'])) {
  734. $array = array();
  735. if (isset($condition['endtime']['start']) && is_int($condition['endtime']['start'])) {
  736. $array[] = 't.end_time >= ' . $condition['endtime'];
  737. }
  738. if (isset($condition['endtime']['end']) && is_int($condition['endtime']['end'])) {
  739. $array[] = 't.end_time <= ' . $condition['endtime'];
  740. }
  741. if ($array) {
  742. $where[] = '(' . implode(' AND ', $array) . ')';
  743. }
  744. } elseif (is_int($condition['endtime'])) {
  745. $where[] = 't.end_time >= ' . $condition['endtime'];
  746. }
  747. }
  748. // 过期
  749. if (isset($condition['expiredate']) && is_int($condition['expiredate'])) {
  750. $where[] = '(t.is_done <> 1 OR t.create_time >= ' . $condition['expiredate'] . ')';
  751. }
  752. // 过滤草稿
  753. $where[] = 't.is_draft = 0';
  754. if (isset($condition['privacy'])) {
  755. $where[] = '(t.privacy = 0 OR tu.unique_id = ' . $uniqueId . ')';
  756. }
  757. if (isset($condition['self'])) {
  758. $where[] = 'tu.unique_id = ' . $uniqueId;
  759. }
  760. // WHERE
  761. $where = implode(' AND ', $where);
  762. // 格式化排序参数
  763. $sort = $this->_formatSort($sort);
  764. foreach ($sort as $key => $val) {
  765. switch ($key) {
  766. case 'lastposttime':
  767. $key = 'last_post_time';
  768. break;
  769. case 'subject':
  770. $key = 'subject';
  771. break;
  772. case 'endtime':
  773. $key = 'end_time';
  774. break;
  775. case 'istop':
  776. $key = 'is_top';
  777. break;
  778. default:
  779. continue 2;
  780. break;
  781. }
  782. $order[] = $key . ' ' . $val;
  783. }
  784. // ORDER
  785. $order = implode(', ', $order);
  786. // 使用默认的分页大小
  787. if (null === $pageSize) {
  788. $pageSize = self::$_defaultPageSize;
  789. }
  790. /**
  791. * @see Oray_Db_Paginator
  792. */
  793. require_once 'Oray/Db/Paginator.php';
  794. // 初始化分页器
  795. $paginator = new Oray_Db_Paginator(array(
  796. Oray_Db_Paginator::ADAPTER => $this->_db,
  797. Oray_Db_Paginator::RECORD_CLASS => $recordClass,
  798. Oray_Db_Paginator::PAGE_SIZE => $pageSize,
  799. Oray_Db_Paginator::TABLE => $table,
  800. Oray_Db_Paginator::PRIMARY => $primary,
  801. Oray_Db_Paginator::COLUMNS => $columns,
  802. Oray_Db_Paginator::WHERE => $where,
  803. Oray_Db_Paginator::ORDER => $order
  804. ));
  805. // 返回查询结果
  806. return $paginator->query($page);
  807. }
  808. /**
  809. * 获取符合条件的图度数量
  810. *
  811. * @param $condition
  812. */
  813. public function getTuduCount(array $condition)
  814. {
  815. $table = 'td_tudu t ';
  816. if (isset($condition['orgid'])) {
  817. $where[] = 't.org_id = ' . $this->_db->quote($condition['orgid']);
  818. }
  819. if (isset($condition['type'])) {
  820. $where[] = 't.type = ' . $this->_db->quote($condition['type']);
  821. }
  822. if (isset($condition['boardid'])) {
  823. $where[] = 't.board_id = ' . $this->_db->quote($condition['boardid']);
  824. }
  825. if (isset($condition['uniqueid'])) {
  826. $table .= 'INNER JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id ';
  827. $where[] = 'tu.unique_id = ' . $this->_db->quote($condition['uniqueid']);
  828. if (isset($condition['labelid'])) {
  829. $table .= 'LEFT JOIN td_tudu_label tl ON tl.tudu_id = t.tudu_id AND tl.unique_id = tu.unique_id ';
  830. $where[] = 'tl.label_id = ' . $this->_db->quote($condition['labelid']);
  831. }
  832. }
  833. // 草稿
  834. if (isset($condition['isdraft'])) {
  835. $where[] = 't.is_draft = ' . ($condition['isdraft'] ? 1 : 0);
  836. }
  837. // 查找已读状态
  838. if (isset($condition['isread'])) {
  839. $where[] = 'tu.is_read = ' . ($condition['isread'] ? 1 : 0);
  840. }
  841. // 关键字
  842. if (!empty($condition['keyword'])) {
  843. $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
  844. $where[] = 't.subject LIKE ' . $keyword;
  845. }
  846. // 发送人
  847. if (!empty($condition['from'])) {
  848. $from = $this->_db->quote('%' . $condition['from'] . '%');
  849. $where[] = 't.from LIKE ' . $from;
  850. }
  851. // 接收人
  852. if (!empty($condition['to'])) {
  853. $to = $this->_db->quote('%' . $condition['to'] . '%');
  854. $where[] = 't.to LIKE ' . $to;
  855. }
  856. // 状态
  857. if (isset($condition['status'])) {
  858. if (is_array($condition['status'])) {
  859. foreach ($condition['status'] as $item) {
  860. $status[] = $this->_db->quote($item);
  861. }
  862. $where[] = 't.status IN (' . implode(',', $status) . ')';
  863. } else if (is_int($condition['status'])) {
  864. $where[] = 't.status = ' . $condition['status'];
  865. }
  866. }
  867. // 版块
  868. if (!empty($condition['boardid'])) {
  869. $where[] = 't.board_id = ' . $this->_db->quote($condition['boardid']);
  870. }
  871. // 主题分类
  872. if (isset($condition['classid'])) {
  873. $where[] = 't.class_id = ' . $this->_db->quote($condition['classid']);
  874. }
  875. // 已完成
  876. if (isset($condition['isdone'])) {
  877. $where[] = 't.is_done = ' . ($condition['isdone'] ? 1 : 0);
  878. }
  879. $array = array(
  880. 'createtime' => 't.create_time',
  881. 'endtime' => 't.end_time',
  882. 'starttime' => 't.start_time'
  883. );
  884. // createtime, endtime, starttime
  885. foreach ($array as $key => $col) {
  886. if (!isset($condition[$key])) {
  887. continue ;
  888. }
  889. if (is_array($condition[$key])) {
  890. $arr = array();
  891. if (isset($condition[$key]['start'])) {
  892. $arr[] = $col . ' >= ' . (int) $condition[$key]['start'];
  893. }
  894. if (isset($condition[$key]['end'])) {
  895. $arr[] = $col . ' <= ' . (int) $condition[$key]['end'];
  896. }
  897. if ($arr) {
  898. $where[] = '(' . implode(' AND ', $arr) . ')';
  899. }
  900. } elseif (is_int($condition[$key])) {
  901. $where[] = $col . ' >= ' . $condition[$key];
  902. }
  903. }
  904. // 过期
  905. if (isset($condition['expiredate']) && is_int($condition['expiredate'])) {
  906. $where[] = '(tu.is_read = 0 OR t.start_time IS NULL OR t.start_time <= ' . $condition['expiredate'] . ')';
  907. }
  908. // WHERE
  909. $where = implode(' AND ', $where);
  910. if ($where) {
  911. $where = 'WHERE ' . $where;
  912. }
  913. $sql = "SELECT COUNT(0) FROM {$table} {$where}";
  914. $count = (int) $this->_db->fetchOne($sql);
  915. return $count;
  916. }
  917. /**
  918. * 统计符合条件的图度数量 -- 此方法将丢弃,请使用 getTuduCount 代替
  919. *
  920. * @param array $condition
  921. * @depared
  922. */
  923. public function countTudu(array $condition)
  924. {
  925. $table = 'td_tudu t '
  926. . 'INNER JOIN td_tudu_user tu ON tu.tudu_id = t.tudu_id '
  927. . 'LEFT JOIN td_tudu_label tl ON tl.tudu_id = t.tudu_id AND tl.unique_id = tu.unique_id';
  928. // $condition...
  929. if (isset($condition['uniqueid'])) {
  930. $where[] = 'tu.unique_id = ' . $this->_db->quote($condition['uniqueid']);
  931. }
  932. if (isset($condition['label'])) {
  933. $where[] = 'tl.label_id = ' . $this->_db->quote($condition['label']);
  934. }
  935. // 状态
  936. if (isset($condition['isdraft']) && is_int($condition['isdraft'])) {
  937. $where[] = 't.is_draft = ' . (int) $condition['isdraft'];
  938. }
  939. // 查找已读状态
  940. if (isset($condition['isread'])) {
  941. $where[] = 'tu.is_read = ' . ($condition['isread'] ? 1 : 0);
  942. }
  943. // 关键字
  944. if (!empty($condition['keyword'])) {
  945. $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
  946. $where[] = 't.subject LIKE ' . $keyword;
  947. }
  948. // 发送人
  949. if (!empty($condition['from'])) {
  950. $from = $this->_db->quote('%' . $condition['from'] . '%');
  951. $where[] = 't.from LIKE ' . $from;
  952. }
  953. // 接收人
  954. if (!empty($condition['to'])) {
  955. $to = $this->_db->quote('%' . $condition['to'] . '%');
  956. $where[] = 't.to LIKE ' . $to;
  957. }
  958. // 状态
  959. if (isset($condition['status']) && is_int($condition['status'])) {
  960. $where[] = 't.status = ' . $condition['status'];
  961. }
  962. // 版块
  963. if (!empty($condition['boardid'])) {
  964. $where[] = 't.board_id = ' . $this->_db->quote($condition['boardid']);
  965. }
  966. // 主题分类
  967. if (isset($condition['classid'])) {
  968. $where[] = 't.class_id = ' . $this->_db->quote($condition['classid']);
  969. }
  970. // 类型
  971. if (!empty($condition['type'])) {
  972. $where[] = 't.type = ' . $this->_db->quote($condition['type']);
  973. }
  974. // 已完成
  975. if (isset($condition['isdone'])) {
  976. $where[] = 't.is_done = ' . ($condition['isdone'] ? 1 : 0);
  977. }
  978. $array = array(
  979. 'createtime' => 't.create_time',
  980. 'endtime' => 't.end_time',
  981. 'starttime' => 't.start_time'
  982. );
  983. // createtime, endtime, starttime
  984. foreach ($array as $key => $col) {
  985. if (!isset($condition[$key])) {
  986. continue ;
  987. }
  988. if (is_array($condition[$key])) {
  989. $arr = array();
  990. if (isset($condition[$key]['start'])) {
  991. $arr[] = $col . ' >= ' . (int) $condition[$key]['start'];
  992. }
  993. if (isset($condition[$key]['end'])) {
  994. $arr[] = $col . ' <= ' . (int) $condition[$key]['end'];
  995. }
  996. if ($arr) {
  997. $where[] = '(' . implode(' AND ', $arr) . ')';
  998. }
  999. } elseif (is_int($condition[$key])) {
  1000. $where[] = $col . ' >= ' . $condition[$key];
  1001. }
  1002. }
  1003. // 过期
  1004. if (isset($condition['expiredate']) && is_int($condition['expiredate'])) {
  1005. $where[] = '(tu.is_read = 0 OR t.start_time IS NULL OR t.start_time <= ' . $condition['expiredate'] . ')';
  1006. }
  1007. // WHERE
  1008. $where = implode(' AND ', $where);
  1009. if ($where) {
  1010. $where = 'WHERE ' . $where;
  1011. }
  1012. $sql = "SELECT COUNT(0) FROM {$table} {$where}";
  1013. $count = (int) $this->_db->fetchOne($sql);
  1014. return $count;
  1015. }
  1016. /**
  1017. * Create tudu
  1018. *
  1019. * @param $params
  1020. * @return string|false
  1021. */
  1022. public function createTudu(array $params)
  1023. {
  1024. if (empty($params['orgid'])
  1025. || empty($params['boardid'])
  1026. || empty($params['tuduid'])
  1027. || empty($params['type'])
  1028. || empty($params['from'])
  1029. || !array_key_exists('subject', $params)) {
  1030. return false;
  1031. }
  1032. $address = self::formatAddress($params['from'], true);
  1033. $createTime = empty($params['createtime']) ? time() : (int) $params['createtime'];
  1034. $table = "td_tudu";
  1035. $bind = array(
  1036. 'org_id' => $params['orgid'],
  1037. 'board_id' => $params['boardid'],
  1038. 'tudu_id' => $params['tuduid'],
  1039. 'type' => $params['type'],
  1040. 'subject' => $params['subject'],
  1041. 'from' => $params['from'],
  1042. 'priority' => empty($params['priority']) ? 0 : (int) $params['priority'],
  1043. 'privacy' => empty($params['privacy']) ? 0 : (int) $params['privacy'],
  1044. 'is_draft' => 1,
  1045. 'last_poster' => $address ? $address[0] : '',
  1046. 'last_post_time' => $createTime,
  1047. 'create_time' => $createTime
  1048. );
  1049. if (isset($params['to'])) {
  1050. $bind['to'] = $params['to'];
  1051. }
  1052. if (isset($params['cc'])) {
  1053. $bind['cc'] = $params['cc'];
  1054. }
  1055. if (isset($params['bcc'])) {
  1056. $bind['bcc'] = $params['bcc'];
  1057. }
  1058. if (isset($params['starttime'])) {
  1059. $bind['start_time'] = $params['starttime'];
  1060. }
  1061. if (isset($params['endtime'])) {
  1062. $bind['end_time'] = $params['endtime'];
  1063. }
  1064. if (isset($params['totaltime'])) {
  1065. $bind['total_time'] = (int) $params['totaltime'];
  1066. }
  1067. if (isset($params['elapsedtime'])) {
  1068. $bind['elapsed_time'] = (int) $params['elapsedtime'];
  1069. }
  1070. if (isset($params['accepttime'])) {
  1071. $bind['accept_time'] = (int) $params['accepttime'];
  1072. }
  1073. if (isset($params['percent'])) {
  1074. $bind['percent'] = (int) $params['percent'];
  1075. }
  1076. if (isset($params['status'])) {
  1077. $bind['status'] = (int) $params['status'];
  1078. }
  1079. if (isset($params['viewnum'])) {
  1080. $bind['view_num'] = (int) $params['viewnum'];
  1081. }
  1082. if (isset($params['isdone'])) {
  1083. $bind['is_done'] = $params['isdone'] ? 1 : 0;
  1084. }
  1085. if (isset($params['istop'])) {
  1086. $bind['is_top'] = $params['istop'] ? 1 : 0;
  1087. }
  1088. if (isset($params['notifyall'])) {
  1089. $bind['notify_all'] = $params['notifyall'] ? 1 : 0;
  1090. }
  1091. if (!empty($params['prevtuduid'])) {
  1092. $bind['prev_tudu_id'] = $params['prevtuduid'];
  1093. }
  1094. if (!empty($params['stepid'])) {
  1095. $bind['step_id'] = $params['stepid'];
  1096. }
  1097. if (!empty($params['appid'])) {
  1098. $bind['app_id'] = $params['appid'];
  1099. }
  1100. if (isset($params['special']) && is_int($params['special'])) {
  1101. $bind['special'] = $params['special'];
  1102. }
  1103. if (isset($params['cycleid'])) {
  1104. $bind['cycle_id'] = $params['cycleid'];
  1105. }
  1106. if (isset($params['flowid'])) {
  1107. $bind['flow_id'] = $params['flowid'];

Large files files are truncated, but you can click here to view the full file