示例#1
0
 /**
  * Get module contents
  * 
  * @return  void
  */
 public function run()
 {
     $this->cssId = $this->params->get('cssId');
     $this->cssClass = $this->params->get('cssClass');
     $this->tag = Request::getVar('tag', '', 'get');
     $this->style = Request::getVar('style', '', 'get');
     require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     $records = Question::all();
     switch ($this->params->get('state', 'open')) {
         case 'open':
             $records->whereEquals('state', 0);
             break;
         case 'closed':
             $records->whereEquals('state', 1);
             break;
         case 'both':
         default:
             $records->where('state', '<', 2);
             break;
     }
     if ($this->tag) {
         $cloud = new Tags();
         $tags = $cloud->parse($this->tag);
         $records->select('#__answers_questions.*')->join('#__tags_object', '#__tags_object.objectid', '#__answers_questions.id')->join('#__tags', '#__tags.id', '#__tags_object.tagid')->whereEquals('#__tags_object.tbl', 'answers')->whereIn('#__tags.tag', $tags);
     }
     $this->rows = $records->limit(intval($this->params->get('limit', 5)))->ordered()->rows();
     require $this->getLayoutPath();
 }
示例#2
0
 /**
  * Generate module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     // randomly choose one
     $rows = Question::all()->select('id')->whereEquals('state', 0)->ordered()->rows()->toArray();
     $key = array_rand($rows);
     $row = Question::oneOrNew($rows[$key]['id']);
     // Did we have a result to display?
     if ($row->get('id')) {
         $this->cls = trim($this->params->get('moduleclass_sfx'));
         $this->txt_length = trim($this->params->get('txt_length'));
         $this->row = $row;
         $config = Component::params('com_answers');
         $this->thumb = DS . trim($this->params->get('defaultpic', '/core/modules/mod_featuredquestion/assets/img/question_thumb.gif'), DS);
         if ($this->thumb == '/modules/mod_featuredquestion/question_thumb.gif') {
             $this->thumb = '/core/modules/mod_featuredquestion/assets/img/question_thumb.gif';
         }
         require $this->getLayoutPath();
     }
 }
示例#3
0
 /**
  * Store changes to this offering
  *
  * @param   boolean $check Perform data validation check?
  * @return  boolean False if error, True on success
  */
 public function store($check = true)
 {
     $res = parent::store($check);
     // If marked as chosen answer
     if ($res && $this->get('state') == 1) {
         require_once __DIR__ . DS . 'question.php';
         $aq = new Question($this->get('question_id'));
         if ($aq->exists() && $aq->get('state') != 1) {
             $aq->set('state', 1);
             //$aq->set('reward', 0);
             // This was giving out points twice for one closed question
             /*
             if ($aq->config('banking'))
             {
             	// Calculate and distribute earned points
             	$AE = new Economy($this->_db);
             	$AE->distribute_points($this->get('question_id'), $aq->get('created_by'), $this->get('created_by'), 'closure');
             
             	// Call the plugin
             	if (
             		!Event::trigger('xmessage.onTakeAction', array(
             			'answers_reply_submitted',
             			array($aq->creator('id')),
             			'com_answers',
             			$this->get('question_id')
             		))
             	)
             	{
             		$this->setError(Lang::txt('Failed to remove alert.'));
             	}
             }
             */
             if (!$aq->store()) {
                 $this->setError($aq->getError());
                 return false;
             }
         }
     }
     return $res;
 }
示例#4
0
 /**
  * Get a list of tools
  *
  * @param   integer  $show_questions  Show question count for tool
  * @param   integer  $show_wishes     Show wish count for tool
  * @param   integer  $show_tickets    Show ticket count for tool
  * @param   string   $limit_tools     Number of records to pull
  * @return  mixed    False if error, otherwise array
  */
 private function _getToollist($show_questions, $show_wishes, $show_tickets, $limit_tools = '40')
 {
     $database = \App::get('db');
     // Query filters defaults
     $filters = array();
     $filters['sortby'] = 'f.published DESC';
     $filters['filterby'] = 'all';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'tool.php';
     require_once Component::path('com_tools') . DS . 'models' . DS . 'tool.php';
     // Create a Tool object
     $rows = \Components\Tools\Models\Tool::getTools($filters, false);
     $limit = 100000;
     if ($rows) {
         for ($i = 0; $i < count($rows); $i++) {
             // What is resource id?
             $rid = \Components\Tools\Models\Tool::getResourceId($rows[$i]->id);
             $rows[$i]->rid = $rid;
             // Get questions, wishes and tickets on published tools
             if ($rows[$i]->published == 1 && $i <= $limit_tools) {
                 if ($show_questions) {
                     // Get open questions
                     require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
                     $results = \Components\Answers\Models\Question::all()->including(['responses', function ($response) {
                         $response->select('id')->select('question_id')->where('state', '!=', 2);
                     }])->whereEquals('state', 0)->select('#__answers_questions.*')->join('#__tags_object', '#__tags_object.objectid', '#__answers_questions.id')->join('#__tags', '#__tags.id', '#__tags_object.tagid')->whereEquals('#__tags_object.tbl', 'answers')->whereIn('#__tags.tag', ['tool' . $rows[$i]->toolname])->limit($limit)->ordered()->rows();
                     $unanswered = 0;
                     if ($results) {
                         foreach ($results as $r) {
                             if ($r->responses->count() == 0) {
                                 $unanswered++;
                             }
                         }
                     }
                     $rows[$i]->q = $results->count();
                     $rows[$i]->q_new = $unanswered;
                 }
                 if ($show_wishes) {
                     // Get open wishes
                     require_once Component::path('com_wishlist') . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
                     require_once Component::path('com_wishlist') . DS . 'tables' . DS . 'wish.php';
                     require_once Component::path('com_wishlist') . DS . 'tables' . DS . 'wishlist.php';
                     $objWishlist = new \Components\Wishlist\Tables\Wishlist($database);
                     $objWish = new \Components\Wishlist\Tables\Wish($database);
                     $listid = $objWishlist->get_wishlistID($rid, 'resource');
                     $rows[$i]->w = 0;
                     $rows[$i]->w_new = 0;
                     if ($listid) {
                         $controller = new \Components\Wishlist\Site\Controllers\Wishlists();
                         $filters = $controller->getFilters(1);
                         $wishes = $objWish->get_wishes($listid, $filters, 1, User::getInstance());
                         $unranked = 0;
                         if ($wishes) {
                             foreach ($wishes as $w) {
                                 if ($w->ranked == 0) {
                                     $unranked++;
                                 }
                             }
                         }
                         $rows[$i]->w = count($wishes);
                         $rows[$i]->w_new = $unranked;
                     }
                 }
                 if ($show_tickets) {
                     // Get open tickets
                     $group = $rows[$i]->devgroup;
                     // Find support tickets on the user's contributions
                     $database->setQuery("SELECT id, summary, category, status, severity, owner, created, login, name,\n\t\t\t\t\t\t\t (SELECT COUNT(*) FROM `#__support_comments` as sc WHERE sc.ticket=st.id AND sc.access=0) as comments\n\t\t\t\t\t\t\t FROM `#__support_tickets` as st WHERE (st.status=0 OR st.status=1) AND type=0 AND st.group='{$group}'\n\t\t\t\t\t\t\t ORDER BY created DESC\n\t\t\t\t\t\t\t LIMIT {$limit}");
                     $tickets = $database->loadObjectList();
                     if ($database->getErrorNum()) {
                         echo $database->stderr();
                         return false;
                     }
                     $unassigned = 0;
                     if ($tickets) {
                         foreach ($tickets as $t) {
                             if ($t->comments == 0 && $t->status == 0 && !$t->owner) {
                                 $unassigned++;
                             }
                         }
                     }
                     $rows[$i]->s = count($tickets);
                     $rows[$i]->s_new = $unassigned;
                 }
             }
         }
     }
     return $rows;
 }
示例#5
0
 /**
  * Set the state of one or more questions
  *
  * @return  void
  */
 public function stateTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $publish = $this->_task == 'close' ? 1 : 0;
     // Check for an ID
     if (count($ids) < 1) {
         $action = $publish == 1 ? Lang::txt('COM_ANSWERS_SET_STATE_CLOSE') : Lang::txt('COM_ANSWERS_SET_STATE_OPEN');
         Notify::warning(Lang::txt('COM_ANSWERS_ERROR_SELECT_QUESTION_TO', $action));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Update record(s)
         $aq = Question::oneOrFail(intval($id));
         $aq->set('state', $publish);
         if (!$aq->save()) {
             Notify::error($aq->getError());
             continue;
         }
         $i++;
     }
     // Set message
     if ($i) {
         if ($publish == 1) {
             $message = Lang::txt('COM_ANSWERS_QUESTIONS_CLOSED', $i);
         } else {
             if ($publish == 0) {
                 $message = Lang::txt('COM_ANSWERS_QUESTIONS_OPENED', $i);
             }
         }
         Notify::success($message);
     }
     $this->cancelTask();
 }
示例#6
0
 /**
  * Set the state of one or more questions
  *
  * @return  void
  */
 public function stateTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $publish = $this->_task == 'close' ? 1 : 0;
     // Check for an ID
     if (count($ids) < 1) {
         $action = $publish == 1 ? Lang::txt('COM_ANSWERS_SET_STATE_CLOSE') : Lang::txt('COM_ANSWERS_SET_STATE_OPEN');
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_ANSWERS_ERROR_SELECT_QUESTION_TO', $action), 'error');
         return;
     }
     foreach ($ids as $id) {
         // Update record(s)
         $aq = Question::oneOrFail(intval($id));
         $aq->set('state', $publish);
         /*if ($publish == 1)
         		{
         			$aq->adjustCredits();
         		}*/
         if (!$aq->save()) {
             Notify::error($aq->getError());
         }
     }
     // Set message
     if ($publish == 1) {
         $message = Lang::txt('COM_ANSWERS_QUESTIONS_CLOSED', count($ids));
     } else {
         if ($publish == 0) {
             $message = Lang::txt('COM_ANSWERS_QUESTIONS_OPENED', count($ids));
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message);
 }
 /**
  * Delete a question
  *
  * @apiMethod DELETE
  * @apiUri    /answers/questions/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Question identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_ANSWERS_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = Question::oneOrNew(intval($id));
         if (!$row->get('id')) {
             throw new Exception(Lang::txt('COM_ANSWERS_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->destroy()) {
             throw new Exception($row->getError(), 500);
         }
     }
     $this->send(null, 204);
 }
示例#8
0
 /**
  * Displays a question response for editing
  *
  * @param   object  $row
  * @return  void
  */
 public function editTask($row = null)
 {
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     Request::setVar('hidemainmenu', 1);
     if (!is_object($row)) {
         $id = Request::getVar('id', array(0));
         $id = is_array($id) && !empty($id) ? $id[0] : $id;
         $row = Response::oneOrNew($id);
     }
     $qid = Request::getInt('qid', 0);
     $qid = $qid ?: $row->get('question_id');
     $question = Question::oneOrFail($qid);
     // Output the HTML
     $this->view->set('question', $question)->set('row', $row)->setLayout('edit')->display();
 }
示例#9
0
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return  void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     Lang::load('com_answers');
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = \Components\Answers\Models\Question::oneOrNew($fields['id'])->set($fields);
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Store new content
     if (!$row->save()) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller(User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the resource
     $tag = $this->model->isTool() ? 'tool:' . $this->model->resource->alias : 'resource:' . $this->model->resource->id;
     $row->addTag($tag, User::get('id'), $this->model->isTool() ? 0 : 1);
     // Get users who need to be notified on every question
     $config = Component::params('com_answers');
     $apu = $config->get('notify_users', '');
     $apu = explode(',', $apu);
     $apu = array_map('trim', $apu);
     $receivers = array();
     // Get tool contributors if question is about a tool
     if ($tags) {
         $tags = explode(',', $tags);
         if (count($tags) > 0) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php';
             $TA = new \Components\Tools\Tables\Author($this->database);
             $objV = new \Components\Tools\Tables\Version($this->database);
             if ($this->model->isTool()) {
                 $toolname = $this->model->resource->alias;
                 $rev = $objV->getCurrentVersionProperty($toolname, 'revision');
                 $authors = $TA->getToolAuthors('', 0, $toolname, $rev);
                 if (count($authors) > 0) {
                     foreach ($authors as $author) {
                         $receivers[] = $author->uidNumber;
                     }
                 }
             }
         }
     }
     if (!empty($apu)) {
         foreach ($apu as $u) {
             $user = User::getInstance($u);
             if ($user) {
                 $receivers[] = $user->get('id');
             }
         }
     }
     $receivers = array_unique($receivers);
     // Send the message
     if (!empty($receivers)) {
         // Send a message about the new question to authorized users (specified admins or related content authors)
         $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
         // Build the message subject
         $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage');
         // Build the message
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'site', 'name' => 'emails', 'layout' => 'question_plaintext'));
         $eview->option = 'com_answers';
         $eview->sitename = Config::get('sitename');
         $eview->question = $row;
         $eview->id = $row->get('id', 0);
         $eview->boundary = $from['multipart'];
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML message
         $eview->setLayout('question_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, 'com_answers'))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name));
 }
示例#10
0
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return     void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = \Components\Answers\Models\Question::oneOrNew($fields['id'])->set($fields);
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Store new content
     if (!$row->save()) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the publication
     $identifier = $this->publication->get('alias') ? $this->publication->get('alias') : $this->publication->get('id');
     $tag = $this->publication->isTool() ? 'tool' . $identifier : 'publication' . $identifier;
     $row->addTag($tag, User::get('id'), $this->publication->isTool() ? 0 : 1);
     // Redirect to the question
     App::redirect(Route::url($this->publication->link() . '&active=questions'));
 }
示例#11
0
 /**
  * Release a reported item
  *
  * @param      string $refid    ID of the database table row
  * @param      string $parent   If the element has a parent element
  * @param      string $category Element type (determines table to look in)
  * @return     array
  */
 public function releaseReportedItem($refid, $parent, $category)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'models' . DS . 'question.php';
     $database = App::get('db');
     $state = 1;
     switch ($category) {
         case 'answer':
             $comment = \Components\Answers\Models\Response::oneOrFail($refid);
             $state = 0;
             break;
         case 'question':
             $comment = \Components\Answers\Models\Question::oneOrFail($refid);
             break;
         case 'answercomment':
             $comment = \Components\Answers\Models\Comment::oneOrFail($refid);
             break;
     }
     $comment->set('state', $state);
     $comment->save();
     return '';
 }
示例#12
0
 /**
  * Display a list of questions
  *
  * @apiMethod GET
  * @apiUri    /answers/questions/list
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "sort",
  * 		"description":   "Field to sort results by.",
  * 		"required":      false,
  *      "default":       "created",
  * 		"allowedValues": "created, title, alias, id, publish_up, publish_down, state"
  * }
  * @apiParameter {
  * 		"name":          "sort_Dir",
  * 		"description":   "Direction to sort results by.",
  * 		"required":      false,
  * 		"default":       "desc",
  * 		"allowedValues": "asc, desc"
  * }
  * @return    void
  */
 public function listTask()
 {
     $database = \App::get('db');
     $model = new \Components\Answers\Tables\Question($database);
     $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'filterby' => Request::getword('filterby', ''), 'sortby' => Request::getWord('sort', 'date'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')));
     $response = new stdClass();
     $response->questions = array();
     $response->total = $model->getCount($filters);
     if ($response->total) {
         $base = rtrim(Request::base(), '/');
         foreach ($model->getResults($filters) as $i => $q) {
             $question = new \Components\Answers\Models\Question($q);
             $obj = new stdClass();
             $obj->id = $question->get('id');
             $obj->subject = $question->subject();
             $obj->quesion = $question->content();
             $obj->state = $question->get('state');
             $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($question->link()), '/'));
             $obj->responses = $question->comments('count');
             $response->questions[] = $obj;
         }
     }
     $response->success = true;
     $this->send($response);
 }
示例#13
0
 /**
  * Displays a question response for editing
  *
  * @param   object  $row
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!is_object($row)) {
         $id = Request::getVar('id', array(0));
         $id = is_array($id) && !empty($id) ? $id[0] : $id;
         $row = Response::oneOrNew($id);
     }
     $qid = Request::getInt('qid', 0);
     $qid = $qid ?: $row->get('question_id');
     $question = Question::oneOrFail($qid);
     // Output the HTML
     $this->view->set('question', $question)->set('row', $row)->setLayout('edit')->display();
 }
示例#14
0
 /**
  * Retrieves a user's questions
  *
  * @param   string  $kind       The kind of results to retrieve
  * @param   array   $interests  Array of tags
  * @return  array   Database results
  */
 private function _getQuestions($kind = 'open', $interests = array())
 {
     // Get some classes we need
     require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     require_once Component::path('com_answers') . DS . 'helpers' . DS . 'economy.php';
     $limit = intval($this->params->get('limit', 10));
     $tags = null;
     $records = \Components\Answers\Models\Question::all()->including(['responses', function ($response) {
         $response->select('id')->select('question_id');
     }])->whereEquals('state', 0);
     if ($kind == 'mine') {
         $records->whereEquals('created_by', User::get('id'));
     }
     if ($kind == 'interest') {
         $tags = count($interests) <= 0 ? $this->_getInterests() : $interests;
     }
     if ($kind == 'assigned') {
         require_once Component::path('com_tools') . DS . 'tables' . DS . 'author.php';
         $database = \App::get('db');
         $TA = new \Components\Tools\Tables\Author($database);
         $tools = $TA->getToolContributions(User::get('id'));
         if ($tools) {
             foreach ($tools as $tool) {
                 $tags .= 'tool' . $tool->toolname . ',';
             }
             $tags = rtrim($tags, ',');
         }
     }
     if ($tags) {
         $cloud = new \Components\Answers\Models\Tags();
         $tags = $cloud->parse($tags);
         $records->select('#__answers_questions.*')->join('#__tags_object', '#__tags_object.objectid', '#__answers_questions.id')->join('#__tags', '#__tags.id', '#__tags_object.tagid')->whereEquals('#__tags_object.tbl', 'answers')->whereIn('#__tags.tag', $tags);
     }
     $data = $records->limit($limit)->ordered()->rows();
     $results = array();
     foreach ($data as $datum) {
         $datum->set('rcount', $datum->responses->count());
         $results[] = $datum;
     }
     if ($this->banking && $results) {
         $database = \App::get('db');
         $AE = new \Components\Answers\Helpers\Economy($database);
         $awards = array();
         foreach ($results as $result) {
             // Calculate max award
             $result->set('marketvalue', round($AE->calculate_marketvalue($result->get('id'), 'maxaward')));
             $result->set('maxaward', round(2 * ($result->get('marketvalue', 0) / 3)));
             if ($kind != 'mine') {
                 $result->set('maxaward', $result->get('maxaward') + $result->get('reward'));
             }
             $awards[] = $result->get('maxaward', 0);
         }
         // re-sort by max reponses
         array_multisort($awards, SORT_DESC, $results);
     }
     return $results;
 }
示例#15
0
 /**
  * Latest Questions Feed
  *
  * @return  void
  */
 public function latestTask()
 {
     //get the id of module so we get the right params
     $mid = Request::getInt('m', 0);
     //get module params
     $params = \Module::params($mid);
     //number of questions to get
     $limit = intval($params->get('limit', 5));
     //open, closed, or both
     $state = $params->get('state', 'both');
     $records = Question::all();
     if ($state == 'open') {
         $records->whereEquals('state', 0);
     }
     if ($state == 'closed') {
         $records->whereEquals('state', 1);
     }
     if (!$state || $state == 'both') {
         $records->where('state', '<', Question::STATE_DELETED);
     }
     $questions = $records->ordered()->limit($limit)->start(0)->paginated()->rows();
     //force mime type of document to be rss
     Document::setType('feed');
     // Start a new feed object
     $doc = Document::instance();
     //set rss feed attribs
     $doc->link = Route::url('index.php?option=com_answers');
     $doc->title = Lang::txt('COM_ANSWERS_LATEST_QUESTIONS_RSS_TITLE', Config::get('sitename'));
     $doc->description = Lang::txt('COM_ANSWERS_LATEST_QUESTIONS_RSS_DESCRIPTION', Config::get('sitename'));
     $doc->copyright = Lang::txt('COM_ANSWERS_LATEST_QUESTIONS_RSS_COPYRIGHT', gmdate("Y"), Config::get('sitename'));
     $doc->category = Lang::txt('COM_ANSWERS_LATEST_QUESTIONS_RSS_CATEGORY');
     //add each question to the feed
     foreach ($questions as $question) {
         //set feed item attibs and add item to feed
         $item = new \Hubzero\Document\Type\Feed\Item();
         $item->title = html_entity_decode(Sanitize::stripAll(stripslashes($question->subject)));
         $item->link = Route::url($question->link());
         $item->description = html_entity_decode(Sanitize::stripAll(stripslashes($question->question)));
         $item->date = date("r", strtotime($question->get('created')));
         $item->category = Lang::txt('COM_ANSWERS_LATEST_QUESTIONS_RSS_CATEGORY_ITEM');
         $item->author = $question->creator()->get('name', Lang::txt('COM_ANSWERS_ANONYMOUS'));
         $doc->addItem($item);
     }
 }
示例#16
0
 /**
  * Calculate the market value
  *
  * @param   integer  $id    Question ID
  * @param   string   $type  Transaction type
  * @return  mixed
  */
 public function calculate_marketvalue($id, $type = 'regular')
 {
     if ($id === NULL) {
         $id = $this->qid;
     }
     if ($id === NULL) {
         return false;
     }
     require_once dirname(__DIR__) . DS . 'models' . DS . 'question.php';
     // Get point values for actions
     $BC = Config::values();
     $p_Q = $BC->get('ask');
     $p_A = $BC->get('answer');
     $p_R = $BC->get('answervote');
     $p_RQ = $BC->get('questionvote');
     $p_A_accepted = $BC->get('accepted');
     $calc = 0;
     // Get actons and sum up
     $results = Response::all()->whereEquals('question_id', $id)->where('state', '!=', 2)->rows();
     if ($type != 'royalty') {
         $calc += $p_Q;
         // ! this is different from version before code migration !
         $calc += $results->count() * $p_A;
     }
     // Calculate as if there is at leat one answer
     if ($type == 'maxaward' && $results->count() == 0) {
         $calc += $p_A;
     }
     foreach ($results as $result) {
         $calc += $result->get('helpful') * $p_R;
         $calc += $result->get('nothelpful') * $p_R;
         if ($result->get('state') == 1 && $type != 'royalty') {
             $accepted = 1;
         }
     }
     if (isset($accepted) or $type == 'maxaward') {
         $calc += $p_A_accepted;
     }
     // Add question votes
     $aq = Question::oneOrNew($id);
     if ($aq->get('state') != 2) {
         $calc += $aq->get('helpful') * $p_RQ;
     }
     $calc = $calc ? $calc : '0';
     return $calc;
 }
示例#17
0
 /**
  * Vote for an item
  *
  * @return  void
  */
 public function voteTask()
 {
     $no_html = Request::getInt('no_html', 0);
     $id = Request::getInt('id', 0);
     $vote = Request::getInt('vote', 0);
     // Login required
     if (User::isGuest()) {
         if (!$no_html) {
             $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN_TO_VOTE'));
             $this->loginTask();
         }
         return;
     }
     // Load the question
     $row = new Question($id);
     // Record the vote
     if (!$row->vote($vote)) {
         if ($no_html) {
             $response = new \stdClass();
             $response->success = false;
             $response->message = $row->getError();
             echo json_encode($response);
             return;
         } else {
             App::redirect(Route::url($row->link()), $row->getError(), 'warning');
             return;
         }
     }
     // Update display
     if ($no_html) {
         $this->qid = $id;
         $this->view->question = $row;
         $this->view->voted = $vote;
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
     } else {
         App::redirect(Route::url($row->link()));
     }
 }