public function findListWithAnswerCountList($id, $startStamp, $priorUsers = array(), $limit = null) { $answerDao = QUESTIONS_BOL_AnswerDao::getInstance(); $limitSql = empty($limit) ? '' : 'LIMIT ' . $limit[0] . ', ' . $limit[1]; if (empty($priorUsers)) { $query = 'SELECT o.*, count(DISTINCT a.id) AS answerCount FROM ' . $this->getTableName() . ' o ' . 'LEFT JOIN ' . $answerDao->getTableName() . ' a ON o.id = a.optionId ' . 'WHERE o.questionId=:q AND o.timeStamp <= :ss GROUP BY o.id ORDER BY answerCount DESC, o.timeStamp, o.id ' . $limitSql; } else { $query = 'SELECT o.*, count(DISTINCT a.id) AS answerCount FROM ' . $this->getTableName() . ' o ' . 'LEFT JOIN ' . $answerDao->getTableName() . ' a ON o.id = a.optionId ' . 'LEFT JOIN ' . $answerDao->getTableName() . ' a2 ON o.id = a2.optionId AND a2.userId IN (' . implode(', ', $priorUsers) . ') ' . 'WHERE o.questionId=:q AND o.timeStamp <= :ss GROUP BY o.id ORDER BY count(DISTINCT a2.userId) DESC, answerCount DESC, o.timeStamp, o.id ' . $limitSql; } $list = $this->dbo->queryForList($query, array('q' => $id, 'ss' => $startStamp)); $countList = array(); $optionList = array(); foreach ($list as $row) { $countList[$row['id']] = $row['answerCount']; unset($row['answerCount']); $option = new QUESTIONS_BOL_Option(); foreach ($row as $k => $v) { $option->{$k} = $v; } $optionList[$row['id']] = $option; } return array('countList' => $countList, 'optionList' => $optionList); }
private function copyData() { $tables = array(array(QUESTIONS_BOL_QuestionDao::getInstance()->getTableName(), EQUESTIONS_BOL_QuestionDao::getInstance()->getTableName(), array('id', 'userId', 'text', 'settings', 'timeStamp')), array(QUESTIONS_BOL_OptionDao::getInstance()->getTableName(), EQUESTIONS_BOL_OptionDao::getInstance()->getTableName(), array('id', 'userId', 'questionId', 'text', 'timeStamp')), array(QUESTIONS_BOL_AnswerDao::getInstance()->getTableName(), EQUESTIONS_BOL_AnswerDao::getInstance()->getTableName(), array('id', 'userId', 'optionId', 'timeStamp')), array(QUESTIONS_BOL_FollowDao::getInstance()->getTableName(), EQUESTIONS_BOL_FollowDao::getInstance()->getTableName(), array('id', 'userId', 'questionId', 'timeStamp')), array(QUESTIONS_BOL_ActivityDao::getInstance()->getTableName(), EQUESTIONS_BOL_ActivityDao::getInstance()->getTableName(), array('id', 'questionId', 'activityType', 'activityId', 'userId', 'timeStamp', 'privacy', 'data'))); foreach ($tables as $t) { OW::getDbo()->query('REPLACE INTO ' . $t[1] . ' (`' . implode('` ,`', $t[2]) . '`) SELECT `' . implode('` ,`', $t[2]) . '` FROM ' . $t[0]); } }
public function __construct() { $this->questionDao = QUESTIONS_BOL_QuestionDao::getInstance(); $this->answerDao = QUESTIONS_BOL_AnswerDao::getInstance(); $this->optionDao = QUESTIONS_BOL_OptionDao::getInstance(); $this->followDao = QUESTIONS_BOL_FollowDao::getInstance(); }