public function indexAction() { $objQuestion = new Questionanswer_Model_Question(array()); //get user id $viewer = Engine_Api::_()->user()->getViewer(); $this->view->user_id = $viewer->getIdentity(); $limit = $this->_getParam('max'); if (!is_numeric($limit) || $limit <= 0) { $limit = 5; } $topUsers = $objQuestion->getTopUsers($limit, 1); $topUser_array = array(); if (is_array($topUsers) && count($topUsers) > 0) { foreach ($topUsers as $topUser) { $qsuser = null; $table = Engine_Api::_()->getDbtable('users', 'user'); $select = $table->select()->where('user_id = ?', $topUser['user_id']); $qsuser = $table->fetchRow($select); $topUser['user_photo'] = $this->view->htmlLink($qsuser, $this->view->itemPhoto($qsuser, 'thumb.icon', $qsuser->getTitle(), array('style' => 'float:left')), array('class' => 'topusers_thumb')); $topUser['user_link'] = $this->view->htmlLink($qsuser->getHref(), $qsuser->getTitle()); $topUser_array[] = $topUser; } } $this->view->topUsers = $topUser_array; }
public function addAnswer($user_id, $question_id, $content, $date_created) { $table = Engine_Api::_()->getDbTable('answers', 'Questionanswer'); $data = array('user_id' => $user_id, 'question_id' => $question_id, 'content' => $content, 'date_created' => $date_created); $table->insert($data); //update number answer of question $objQuestion = new Questionanswer_Model_Question(array()); $objQuestion->updateNumberAnswer($question_id); return $this; }
public function postanswerAction() { $objAnswer = new Questionanswer_Model_Answer(array()); $_user_id = $this->_helper->api()->user()->getViewer()->getIdentity(); $question_id = $_POST['question_id']; $content = $_POST['mess']; $date_created = date('Y-m-d H:i:s'); //$answer = $objAnswer->addAnswer($_user_id, $question_id, $content, $date_created); $params['user_id'] = $_user_id; $params['question_id'] = $question_id; $params['content'] = trim($content); $params['date_created'] = $date_created; $answer = Engine_Api::_()->getDbtable('answers', 'Questionanswer')->createRow(); $answer->setFromArray($params); $answer->save(); //get question detail $objQuestion = new Questionanswer_Model_Question(array()); $question_detail = $objQuestion->getQuestionById($question_id); $objQuestion->updateNumberAnswer($question_id); //add notification for owner of question if ($answer instanceof Core_Model_Item_Abstract) { if (!Engine_Api::_()->core()->hasSubject()) { Engine_Api::_()->core()->setSubject($answer); } } $subject = Engine_Api::_()->core()->getSubject(); $subjectOwner = Engine_Api::_()->getItem('user', $question_detail['user_id']); $viewer = Engine_Api::_()->user()->getViewer(); if ($subjectOwner->getIdentity() != $viewer->getIdentity()) { $notifyApi = Engine_Api::_()->getDbtable('notifications', 'activity'); $notifyApi->addNotification($subjectOwner, $viewer, $answer, 'answer_posted', array('label' => "question")); } $linkQuestion = $this->view->htmlLink("qa?qid=" . $question_detail['question_id'], substr($question_detail['content'], 0, 150)); $activity = Engine_Api::_()->getDbtable('actions', 'activity'); $action = $activity->addActivity(Engine_Api::_()->user()->getViewer(), Engine_Api::_()->user()->getViewer(), 'answer_new', null, array('body' => substr(trim($content), 0, 200), 'question' => $linkQuestion)); if (null !== $action) { $activity->attachActivity($action, $answer); } echo '{"result":"success", "message":"Post message successfully!"}'; die; }
public function editquestionAction() { $objQuestion = new Questionanswer_Model_Question(array()); $id = $this->_getParam('id', null); $this->view->form = $form = new Questionanswer_Form_Admin_Manage_EditQuestion(); $question = $objQuestion->getQuestionById($id); // Posting form if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $data_array = $form->getValues(); $date_updated = date('Y-m-d H:i:s'); $objQuestion->updateQuestion($id, $data_array['content'], $date_updated); } $this->_forward('success', 'utility', 'core', array('smoothboxClose' => true, 'parentRefresh' => true, 'format' => 'smoothbox', 'messages' => array('Question Edited.'))); } else { foreach ($form->getElements() as $name => $element) { if (isset($question[$name])) { $element->setValue($question[$name]); } } } }