コード例 #1
0
ファイル: helper.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * 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
 /**
  * List all questions
  *
  * @return  void
  */
 public function displayTask()
 {
     // Filters
     $filters = array('tag' => Request::getstate($this->_option . '.' . $this->_controller . '.tag', 'tag', ''), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'state' => Request::getstate($this->_option . '.' . $this->_controller . '.state', 'state', -1, 'int'), 'sort' => Request::getstate($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getstate($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'));
     $records = Question::all()->including(['responses', function ($response) {
         $response->select('id')->select('question_id');
     }]);
     if ($filters['search']) {
         $filters['search'] = strtolower((string) $filters['search']);
         $records->whereLike('subject', $filters['search'], 1)->orWhereLike('question', $filters['search'], 1)->resetDepth();
     }
     if ($filters['state'] >= 0) {
         $records->whereEquals('state', $filters['state']);
     }
     $rows = $records->ordered('filter_order', 'filter_order_Dir')->paginated();
     // Output the HTML
     $this->view->set('rows', $rows)->set('filters', $filters)->display();
 }
コード例 #3
0
ファイル: helper.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * 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();
     }
 }
コード例 #4
0
ファイル: helper.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * 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;
 }
コード例 #5
0
ファイル: helper.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * 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;
 }
コード例 #6
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()
 {
     $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => Request::getInt('state', -1), 'sort' => Request::getWord('sort', 'created'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')));
     $records = Question::all();
     if ($filters['search']) {
         $filters['search'] = strtolower((string) $filters['search']);
         $records->whereLike('subject', $filters['search'], 1)->orWhereLike('question', $filters['search'], 1)->resetDepth();
     }
     if ($filters['state'] >= 0) {
         $records->whereEquals('state', $filters['state']);
     }
     $rows = $records->limit($filters['limit'])->ordered('sort', 'sortDir')->paginated();
     $response = new stdClass();
     $response->questions = array();
     $response->total = $records->rows()->count();
     if ($response->total) {
         $base = rtrim(Request::base(), '/');
         foreach ($records->rows() as $question) {
             $obj = new stdClass();
             $obj->id = $question->get('id');
             $obj->subject = $question->get('subject');
             $obj->quesion = $question->get('question');
             $obj->state = $question->get('state');
             $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($question->link()), '/'));
             $obj->responses = $question->responses()->count();
             $response->questions[] = $obj;
         }
     }
     $response->success = true;
     $this->send($response);
 }
コード例 #7
0
ファイル: questions.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * 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);
     }
 }
コード例 #8
0
ファイル: questions.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Parse a list of filters to return data for
  *
  * @return  object
  */
 private function _find()
 {
     $records = \Components\Answers\Models\Question::all()->including(['responses', function ($response) {
         $response->select('id')->select('question_id')->where('state', '!=', 2);
     }]);
     if ($this->filters['tag']) {
         $cloud = new \Components\Answers\Models\Tags();
         $tags = $cloud->parse($this->filters['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);
     }
     if ($this->filters['search']) {
         $this->filters['search'] = strtolower((string) $this->filters['search']);
         $records->whereLike('subject', $this->filters['search'], 1)->orWhereLike('question', $this->filters['search'], 1)->resetDepth();
     }
     if ($this->filters['filterby'] == 'open') {
         $records->whereEquals('state', 0);
     }
     if ($this->filters['filterby'] == 'closed') {
         $records->whereEquals('state', 1);
     }
     if (!$this->filters['filterby'] || $this->filters['filterby'] == 'both') {
         $records->where('state', '<', 2);
     }
     return $records;
 }