Exemple #1
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;
 }
Exemple #2
0
 /**
  * Return data on a group view (this will be some form of HTML)
  *
  * @param      object  $group      Current group
  * @param      string  $option     Name of the component
  * @param      string  $authorized User's authorization level
  * @param      integer $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      string  $action     Action to perform
  * @param      array   $access     What can be accessed
  * @param      array   $areas      Active area(s)
  * @return     array
  */
 public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null)
 {
     $return = 'html';
     $active = 'wishlist';
     // The output array we're returning
     $arr = array('html' => '');
     //get this area details
     $this_area = $this->onGroupAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas) && $limit) {
         if (!in_array($this_area['name'], $areas)) {
             $return = 'metadata';
         }
     }
     //get the group members
     $members = $group->get('members');
     //if we want to return content
     if ($return == 'html') {
         //set group members plugin access level
         $group_plugin_acl = $access[$active];
         //if set to nobody make sure cant access
         if ($group_plugin_acl == 'nobody') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
             return $arr;
         }
         //check if guest and force login if plugin access is registered or members
         if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) {
             $url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active, false, true);
             App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning');
             return;
         }
         //check to see if user is member and plugin access requires members
         if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
             return $arr;
         }
     }
     //instantiate database
     $database = App::get('db');
     // Set some variables so other functions have access
     $this->database = $database;
     $this->authorized = $authorized;
     $this->members = $members;
     $this->group = $group;
     $this->option = $option;
     $this->action = $action;
     //include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
     // Get the component parameters
     $this->config = Component::params('com_wishlist');
     Lang::load('com_wishlist') || Lang::load('com_wishlist', PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site');
     //set some more vars
     $gid = $this->group->get('gidNumber');
     $cn = $this->group->get('cn');
     $category = 'group';
     $admin = 0;
     // Configure controller
     $controller = new \Components\Wishlist\Site\Controllers\Wishlists();
     // Get filters
     $filters = $controller->getFilters(0);
     $filters['limit'] = $this->params->get('limit');
     // Load some objects
     $obj = new \Components\Wishlist\Tables\Wishlist($this->database);
     $objWish = new \Components\Wishlist\Tables\Wish($this->database);
     $objOwner = new \Components\Wishlist\Tables\Owner($this->database);
     // Get wishlist id
     $id = $obj->get_wishlistID($gid, $category);
     // Create a new list if necessary
     if (!$id) {
         // create private list for group
         if (\Hubzero\User\Group::exists($gid)) {
             $group = \Hubzero\User\Group::getInstance($gid);
             $id = $obj->createlist($category, $gid, 0, $cn . ' ' . Lang::txt('PLG_GROUPS_WISHLIST_NAME_GROUP'));
         }
     }
     // get wishlist data
     $wishlist = $obj->get_wishlist($id, $gid, $category);
     //if we dont have a wishlist display error
     if (!$wishlist) {
         $arr['html'] = '<p class="error">' . Lang::txt('PLG_GROUPS_WISHLIST_ERROR_WISHLIST_NOT_FOUND') . '</p>';
         return $arr;
     }
     // Get list owners
     $owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist);
     //if user is guest and wishlist isnt public
     //if (!$wishlist->public && User::isGuest())
     //{
     //	$arr['html'] = '<p class="warning">' . Lang::txt('The Group Wishlist is not a publicly viewable list.') . '</p>';
     //	return $arr;
     //}
     // Authorize admins & list owners
     if (User::authorise($option, 'manage')) {
         $admin = 1;
     }
     //authorized based on wishlist
     if (in_array(User::get('id'), $owners['individuals'])) {
         $admin = 2;
     } else {
         if (in_array(User::get('id'), $owners['advisory'])) {
             $admin = 3;
         }
     }
     //get item count
     $items = $objWish->get_count($id, $filters, $admin);
     $arr['metadata']['count'] = $items;
     if ($return == 'html') {
         // Get wishes
         $wishlist->items = $objWish->get_wishes($wishlist->id, $filters, $admin, User::getInstance());
         // HTML output
         // Instantiate a view
         $view = $this->view('default', 'browse');
         // Pass the view some info
         $view->option = $option;
         //$view->owners = $owners;
         $view->group = $this->group;
         $view->wishlist = $wishlist;
         $view->items = $items;
         $view->filters = $filters;
         $view->admin = $admin;
         $view->config = $this->config;
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     return $arr;
 }
Exemple #3
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param   object  $resource  Current resource
  * @param   string  $option    Name of the component
  * @param   array   $areas     Active area(s)
  * @param   string  $rtrn      Data to be returned
  * @return  array
  */
 public function onResources($model, $option, $areas, $rtrn = 'all')
 {
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (!$model->type->params->get('plg_' . $this->_name)) {
         return $arr;
     }
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) {
             $rtrn = 'metadata';
         }
     }
     $this->config = Component::params('com_wishlist');
     Lang::load('com_wishlist', PATH_APP . DS . 'bootstrap' . DS . 'site') || Lang::load('com_wishlist', Component::path('com_wishlist') . DS . 'site');
     $database = App::get('db');
     $option = 'com_wishlist';
     $cat = 'resource';
     $refid = $model->resource->id;
     $items = 0;
     $admin = 0;
     $html = '';
     // Include some classes & scripts
     require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'models' . DS . 'wishlist.php';
     require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
     // Configure controller
     $controller = new \Components\Wishlist\Site\Controllers\Wishlists();
     // Get filters
     $filters = $controller->getFilters(0);
     $filters['limit'] = $this->params->get('limit');
     // Load some objects
     $obj = new \Components\Wishlist\Tables\Wishlist($database);
     $objWish = new \Components\Wishlist\Tables\Wish($database);
     $objOwner = new \Components\Wishlist\Tables\Owner($database);
     // Get wishlist id
     $id = $obj->get_wishlistID($refid, $cat);
     // Create a new list if necessary
     if (!$id) {
         if ($model->resource->title && $model->resource->standalone == 1 && $model->resource->published == 1) {
             $rtitle = $model->istool() ? Lang::txt('COM_WISHLIST_NAME_RESOURCE_TOOL') . ' ' . $model->resource->alias : Lang::txt('COM_WISHLIST_NAME_RESOURCE_ID') . ' ' . $model->resource->id;
             $id = $obj->createlist($cat, $refid, 1, $rtitle, $model->resource->title);
         }
     }
     // get wishlist data
     $wishlist = $obj->get_wishlist($id, $refid, $cat);
     if (!$wishlist) {
         $html = '<p class="error">' . Lang::txt('ERROR_WISHLIST_NOT_FOUND') . '</p>';
     } else {
         // Get list owners
         $owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist);
         // Authorize admins & list owners
         if (!User::isGuest()) {
             if (User::authorise($option, 'manage')) {
                 $admin = 1;
             }
             if (isset($owners['individuals']) && in_array(User::get('id'), $owners['individuals'])) {
                 $admin = 2;
             } else {
                 if (isset($owners['advisory']) && in_array(User::get('id'), $owners['advisory'])) {
                     $admin = 3;
                 }
             }
         } else {
             if (!$wishlist->public && $rtrn != 'metadata') {
                 // not authorized
                 App::abort(403, Lang::txt('ALERTNOTAUTH'));
                 return;
             }
         }
         $items = $objWish->get_count($id, $filters, $admin);
         if ($rtrn != 'metadata') {
             // Get wishes
             $wishlist->items = $objWish->get_wishes($wishlist->id, $filters, $admin, User::getInstance());
             $title = $admin ? Lang::txt('COM_WISHLIST_TITLE_PRIORITIZED') : Lang::txt('COM_WISHLIST_TITLE_RECENT_WISHES');
             if (count($wishlist->items) > 0 && $items > $filters['limit']) {
                 $title .= ' (<a href="' . Route::url('index.php?option=' . $option . '&task=wishlist&category=' . $wishlist->category . '&rid=' . $wishlist->referenceid) . '">' . Lang::txt('PLG_RESOURCES_WISHLIST_VIEW_ALL') . '</a>)';
             } else {
                 $title .= ' (' . $items . ')';
             }
             // HTML output
             // Instantiate a view
             $view = $this->view('default', 'browse')->set('option', $option)->set('resource', $model->resource)->set('title', $title)->set('wishlist', $wishlist)->set('filters', $filters)->set('admin', $admin)->set('config', $this->config);
             foreach ($this->getErrors() as $error) {
                 $view->setError($error);
             }
             // Return the output
             $arr['html'] = $view->loadTemplate();
         }
     }
     // Build the HTML meant for the "about" tab's metadata overview
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         $view = $this->view('default', 'metadata')->set('resource', $model->resource)->set('items', $items)->set('wishlistid', $id);
         $arr['metadata'] = $view->loadTemplate();
     }
     return $arr;
 }
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param      object  	$publication 	Current publication
  * @param      string  	$option    		Name of the component
  * @param      array   	$areas     		Active area(s)
  * @param      string  	$rtrn      		Data to be returned
  * @param      string 	$version 		Version name
  * @param      boolean 	$extended 		Whether or not to show panel
  * @return     array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) {
             $rtrn = 'metadata';
         }
     }
     if (!$publication->_category->_params->get('plg_wishlist') || !$extended) {
         return $arr;
     }
     $database = App::get('db');
     // Load component language file
     Lang::load('com_wishlist') || Lang::load('com_wishlist', PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site');
     $option = 'com_wishlist';
     $cat = 'publication';
     $refid = $publication->id;
     $items = 0;
     $admin = 0;
     $html = '';
     // Include some classes & scripts
     require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'models' . DS . 'wishlist.php';
     require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
     // Configure controller
     $controller = new \Components\Wishlist\Site\Controllers\Wishlists();
     // Get filters
     $filters = $controller->getFilters(0);
     $filters['limit'] = $this->params->get('limit');
     // Load some objects
     $obj = new \Components\Wishlist\Tables\Wishlist($database);
     $objWish = new \Components\Wishlist\Tables\Wish($database);
     $objOwner = new \Components\Wishlist\Tables\Owner($database);
     // Get wishlist id
     $id = $obj->get_wishlistID($refid, $cat);
     // Create a new list if necessary
     if (!$id) {
         if ($publication->title && $publication->state == 1) {
             $rtitle = isset($publication->alias) && $publication->alias ? Lang::txt('COM_WISHLIST_NAME_RESOURCE') . ' ' . $publication->alias : Lang::txt('COM_WISHLIST_NAME_PUB_ID') . ' ' . $publication->id;
             $id = $obj->createlist($cat, $refid, 1, $rtitle, $publication->title);
         }
     }
     // get wishlist data
     $wishlist = $obj->get_wishlist($id, $refid, $cat);
     if (!$wishlist) {
         $html = '<p class="error">' . Lang::txt('COM_WISHLIST_ERROR_LIST_NOT_FOUND') . '</p>';
     } else {
         // Get the component parameters
         $this->config = Component::params('com_wishlist');
         // Get list owners
         $owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist);
         // Authorize admins & list owners
         if (!User::isGuest()) {
             if (User::authorize($option, 'manage')) {
                 $admin = 1;
             }
             if (in_array(User::get('id'), $owners['individuals'])) {
                 $admin = 2;
             } elseif (in_array(User::get('id'), $owners['advisory'])) {
                 $admin = 3;
             }
         } elseif (!$wishlist->public && $rtrn != 'metadata') {
             // not authorized
             throw new Exception(Lang::txt('COM_WISHLIST_ERROR_ALERTNOTAUTH'), 403);
             return;
         }
         $items = $objWish->get_count($id, $filters, $admin);
         if ($rtrn != 'metadata') {
             // Get wishes
             $wishlist->items = $objWish->get_wishes($wishlist->id, $filters, $admin, User::getRoot());
             $title = $admin ? Lang::txt('COM_WISHLIST_TITLE_PRIORITIZED') : Lang::txt('COM_WISHLIST_TITLE_RECENT_WISHES');
             if (count($wishlist->items) > 0 && $items > $filters['limit']) {
                 $title .= ' (<a href="' . Route::url('index.php?option=' . $option . '&task=wishlist&category=' . $wishlist->category . '&rid=' . $wishlist->referenceid) . '">' . Lang::txt('view all') . ' ' . $items . '</a>)';
             } else {
                 $title .= ' (' . $items . ')';
             }
             // HTML output
             // Instantiate a view
             $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'wishlist', 'name' => 'browse'));
             // Pass the view some info
             $view->option = $option;
             $view->publication = $publication;
             $view->title = $title;
             $view->wishlist = $wishlist;
             $view->filters = $filters;
             $view->admin = $admin;
             $view->config = $this->config;
             if ($this->getError()) {
                 $view->setError($this->getError());
             }
             // Return the output
             $html = $view->loadTemplate();
         }
     }
     // Build the HTML meant for the "about" tab's metadata overview
     $metadata = '';
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'wishlist', 'name' => 'metadata'));
         $view->publication = $publication;
         $view->items = $items;
         $view->wishlistid = $id;
         $metadata = $view->loadTemplate();
     }
     $arr = array('html' => $html, 'metadata' => $metadata);
     if ($publication->state == 1) {
         $arr['count'] = $items;
         $arr['name'] = 'wishlist';
     }
     return $arr;
 }