Пример #1
0
 /**
  * Generate module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     $database = \App::get('db');
     $row = null;
     // randomly choose one
     $filters = array('limit' => 1, 'start' => 0, 'sortby' => 'random', 'tag' => '', 'filterby' => 'open', 'created_before' => gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), gmdate('d') + 7, gmdate('Y'))) . ' 00:00:00');
     $mp = new Question($database);
     $rows = $mp->getResults($filters);
     if (count($rows) > 0) {
         $row = $rows[0];
     }
     // Did we have a result to display?
     if ($row) {
         $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();
     }
 }
Пример #2
0
 /**
  * List all questions
  *
  * @return  void
  */
 public function displayTask()
 {
     // Filters
     $this->view->filters = array('tag' => Request::getstate($this->_option . '.' . $this->_controller . '.tag', 'tag', ''), 'q' => Request::getstate($this->_option . '.' . $this->_controller . '.q', 'q', ''), 'filterby' => Request::getstate($this->_option . '.' . $this->_controller . '.filterby', 'filterby', 'all'), 'limit' => Request::getstate($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getstate($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'sortby' => '', 'sort' => Request::getstate($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getstate($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'));
     $aq = new Tables\Question($this->database);
     // Get a record count
     $this->view->total = $aq->getCount($this->view->filters);
     // Get records
     $this->view->results = $aq->getResults($this->view->filters);
     // Did we get any results?
     if ($this->view->results) {
         foreach ($this->view->results as $key => $result) {
             $this->view->results[$key] = new Question($result);
         }
     }
     // Output the HTML
     $this->view->display();
 }
Пример #3
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 = new Config($this->_db);
     $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
     $ar = new Tables\Response($this->_db);
     $result = $ar->getActions($id);
     if ($type != 'royalty') {
         $calc += $p_Q;
         // ! this is different from version before code migration !
         $calc += count($result) * $p_A;
     }
     // Calculate as if there is at leat one answer
     if ($type == 'maxaward' && count($result) == 0) {
         $calc += $p_A;
     }
     for ($i = 0, $n = count($result); $i < $n; $i++) {
         $calc += $result[$i]->helpful * $p_R;
         $calc += $result[$i]->nothelpful * $p_R;
         if ($result[$i]->state == 1 && $type != 'royalty') {
             $accepted = 1;
         }
     }
     if (isset($accepted) or $type == 'maxaward') {
         $calc += $p_A_accepted;
     }
     // Add question votes
     $aq = new Tables\Question($this->_db);
     $aq->load($id);
     if ($aq->state != 2) {
         $calc += $aq->helpful * $p_RQ;
     }
     $calc = $calc ? $calc : '0';
     return $calc;
 }
Пример #4
0
 /**
  * Search entries
  *
  * @return     void
  */
 public function searchTask()
 {
     $this->view->config = $this->config;
     $this->view->task = $this->_task;
     // Incoming
     $this->view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'tag' => Request::getVar('tags', ''), 'q' => Request::getVar('q', ''), 'filterby' => Request::getWord('filterby', ''), 'sortby' => Request::getWord('sortby', 'date'), 'sort_Dir' => Request::getWord('sortdir', 'DESC'), 'area' => Request::getVar('area', ''));
     // Validate inputs
     $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : Request::getVar('tag', '');
     if ($this->view->filters['filterby'] && !in_array($this->view->filters['filterby'], array('open', 'closed'))) {
         $this->view->filters['filterby'] = '';
     }
     if (!in_array($this->view->filters['sortby'], array('date', 'votes', 'rewards'))) {
         $this->view->filters['sortby'] = 'date';
     }
     if ($this->view->filters['area'] && !in_array($this->view->filters['area'], array('mine', 'assigned', 'interest'))) {
         $this->view->filters['area'] = '';
     }
     // Get questions of interest
     if ($this->view->filters['area'] == 'interest') {
         require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php';
         // Get tags of interest
         $mt = new \Components\Members\Models\Tags(User::get('id'));
         $mytags = $mt->render('string');
         $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : $mytags;
         $this->view->filters['mine'] = 0;
     }
     // Get assigned questions
     if ($this->view->filters['area'] == 'assigned') {
         require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
         // What tools did this user contribute?
         $TA = new \Components\Tools\Tables\Author($this->database);
         $tools = $TA->getToolContributions(User::get('id'));
         $mytooltags = array();
         if ($tools) {
             foreach ($tools as $tool) {
                 $mytooltags[] = 'tool' . $tool->toolname;
             }
         }
         $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : implode(',', $mytooltags);
         $this->view->filters['mine'] = 0;
     }
     if ($this->view->filters['area'] == 'mine') {
         $this->view->filters['mine'] = 1;
     }
     // Instantiate a Questions object
     $aq = new Tables\Question($this->database);
     if (($this->view->filters['area'] == 'interest' || $this->view->filters['area'] == 'assigned') && !$this->view->filters['tag']) {
         // Get a record count
         $this->view->total = 0;
         // Get records
         $this->view->results = array();
     } else {
         // Get a record count
         $this->view->total = $aq->getCount($this->view->filters);
         // Get records
         $this->view->results = $aq->getResults($this->view->filters);
     }
     // Did we get any results?
     if (count($this->view->results) > 0) {
         // Do some processing on the results
         foreach ($this->view->results as $i => $result) {
             $this->view->results[$i] = new Question($result);
         }
     }
     // Set the page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setLayout('search')->display();
 }