Example #1
0
 /**
  * Return count of items that will be deleted when group is deleted
  * 
  * @param      object $group Group being deleted
  * @return     string
  */
 public function onGroupDeleteCount($group)
 {
     // include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     // Load some objects
     $database = App::get('db');
     $wishlist = new \Components\Wishlist\Tables\Wishlist($database);
     $wish = new \Components\Wishlist\Tables\Wish($database);
     // Get wishlist id
     $id = $wishlist->get_wishlistID($group->get('gidNumber'), 'group');
     // no id means no list
     if (!$id) {
         return Lang::txt('PLG_GROUPS_WISHLIST_LOG', 0);
     }
     // get wishes count
     $wishes = $wish->get_count($id, array('filterby' => 'all'), 1);
     // return message
     return Lang::txt('PLG_GROUPS_WISHLIST_LOG', $wishes);
 }
Example #2
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;
 }
Example #3
0
 /**
  * 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;
 }