public function searchProcess($userId, $keyword, $options = array(), $cond = array()) { if ($userId && $keyword) { $arrayWord = $this->parseKeyword($keyword); $articleTable = new VC_DbTable_Store_Article(); $sql = "SELECT SQL_CALC_FOUND_ROWS sa.title, sa.content, sa.id FROM store_article AS sa"; $where = " WHERE user_id = {$userId} AND ("; foreach ($arrayWord as $word) { $where .= " sa.`title` LIKE '%" . $word . "%' OR sa.`content` LIKE '%" . $word . "%' OR"; } $where = rtrim($where, "OR"); $where .= ")"; if (sizeof($cond) > 0) { foreach ($cond as $field => $value) { $where .= " AND sa." . $field . " = '" . $value . "'"; } } $sql .= $where; $sql .= " ORDER BY sa.id DESC"; $sql .= " LIMIT " . $options['offset'] . "," . $options['count']; $db = $articleTable->getAdapter(); $result['list'] = $db->query($sql)->fetchAll(); $result['numFound'] = $db->query("SELECT FOUND_ROWS() as numFound")->fetchColumn(); return $result; } return null; }
public function deleteAction() { $articleId = (int) $this->_getParam('id'); if ($articleId == 0) { throw new VC_Exception("Invalid article delete information"); } //Check if this article belong with this user $articleTbl = new VC_DbTable_Store_Article(); $article = $articleTbl->findByIdAndUserId($articleId, $this->userId); if ($article) { //Delete $articleTbl->delete("id = " . $articleId); $this->_redirect("article/view/?tpid=" . $this->_getParam("tpid")); } else { throw new VC_Exception("This article not belong with you"); } }
public function deleteByTopicId($topicId) { $articleTbl = new VC_DbTable_Store_Article(); $articleTbl->delete("topic_id = " . $topicId); $this->delete("id = " . $topicId); }