public function insertAction() { $message = array(); $insertTokenNamespace = new Zend_Session_Namespace("INSERT_TOKEN"); $topicId = $this->_getParam("tpid"); if ($this->_getParam('submit')) { if ($topicId) { //Check is topic belongs to this user $topicTbl = new VC_DbTable_Store_Topic(); $isBelongThisUser = $topicTbl->checkRecordExistMultiCond(array('id' => $topicId, 'user_id' => $this->userId)); if (!$isBelongThisUser) { throw new Zend_Exception("This topic does not belong you"); } if ($this->_getParam('title') && $this->_getParam('content')) { $insertData = array(); $insertData['title'] = $this->_getParam('title'); $insertData['content'] = $this->_getParam('content'); $insertData['root_link'] = $this->_getParam('root_link'); $insertData['topic_id'] = $topicId; $insertData['user_id'] = $this->userId; $insertData['post_date'] = date("Y-m-d"); $articleTbl = new VC_DbTable_Store_Article(); $articleId = $articleTbl->insert($insertData); //Move files from upload tmp to file $fileBus = new VC_Business_File(); $moveFile = $fileBus->moveTmpFileToFile($this->userId, $insertTokenNamespace->insertToken, $articleId); unset($insertTokenNamespace->insertToken); unset($insertTokenNamespace); $this->_redirect("article/view/?tpid=" . $topicId); } else { if (!$this->_getParam('title')) { $message[] = "You have to input title"; } if (!$this->_getParam('content')) { $message[] = "You have to input content"; } } //$this->view->topicInfo = $topicTbl->findById($topicId); } else { $message[] = "You have to choose topic"; } } else { //Create insert token $time = time(); $insertTokenNamespace->insertToken = $time; $this->view->insertToken = $time; } $menuObj = new VC_Business_MenuFactory(); $groupAndTopic = $menuObj->getGroupsAndTopicsOfUser($this->userId); //echo "<pre>"; var_dump($groupAndTopic); echo "</pre>"; die; $this->view->groupAndTopic = $groupAndTopic; $this->view->data = $this->_getAllParams(); $this->view->message = $message; $this->view->insertToken = $insertTokenNamespace->insertToken; //Get all temp file uploaded of this article $uploadTmpTbl = new VC_DbTable_Common("upload_tmp", "id"); $this->view->listUploadFiles = $uploadTmpTbl->fetchAll("user_id = " . $this->userId . " AND insert_token = '" . $insertTokenNamespace->insertToken . "'"); }
public function getGroupsAndTopicsOfUser($userId) { if ((int) $userId == 0) { throw new VC_Exception("Invalid user information"); } //TODO: Cache $topicGroupTbl = new VC_DbTable_Store_TopicGroup(); $topicTbl = new VC_DbTable_Store_Topic(); $allTopicGroupOfUser = $topicGroupTbl->findByUserId($userId); if ($allTopicGroupOfUser) { foreach ($allTopicGroupOfUser as $key => $topicGroup) { //Get all topic of group topic $allTopicGroupOfUser[$key]['topics'] = $topicTbl->findByTopicGroupId($topicGroup['id']); //if ($topicGroup['id'] == 2) var_dump($topicGroup['topics'] ); } } return $allTopicGroupOfUser; }
public function deleteAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $topicGroupId = $this->_getParam("id"); $message = ""; if ($topicGroupId) { //Check belong this user $topicGroupTbl = new VC_DbTable_Store_TopicGroup(); $getTopic = $topicGroupTbl->fetchRow("id = " . $topicGroupId . " AND user_id = " . $this->userId); if ($getTopic) { $topicGroupTbl->delete("id = " . $topicGroupId); //Delete all topic of this $topicTbl = new VC_DbTable_Store_Topic(); $topicTbl->deleteTopicByTopicGroup($topicGroupId); $this->_helper->flashMessenger->addMessage(array('manage' => "Bạn đã xóa thành công.")); } else { $this->_helper->flashMessenger->addMessage(array('manage' => "Thông tin nhóm chủ đề không hợp lệ.")); } } else { $this->_helper->flashMessenger->addMessage(array('manage' => "Thông tin nhóm chủ đề không hợp lệ.")); } $this->_redirect("topic-group/index"); }
public function editAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $topicId = $this->_getParam("id"); $topicName = $this->_getParam("name"); $message = ""; if ($topicId && $topicName) { //Check belong this user $topicTbl = new VC_DbTable_Store_Topic(); $getTopic = $topicTbl->fetchRow("id = " . $topicId . " AND user_id = " . $this->userId); if ($getTopic) { $data = array('name' => $topicName); $topicTbl->update($data, "id = " . $topicId); $this->_helper->flashMessenger->addMessage(array('manage' => "Bạn đã cập nhật thành công.")); } else { $this->_helper->flashMessenger->addMessage(array('manage' => "Thông tin chủ đề không hợp lệ.")); } } else { $this->_helper->flashMessenger->addMessage(array('manage' => "Thông tin chủ đề không hợp lệ.")); } echo $topicName; //$this->_redirect("topic/index"); }