/**
  * Up
  **/
 public function up()
 {
     // include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     // Load some objects
     $wishlist = new \Components\Wishlist\Tables\Wishlist($this->db);
     $wish = new \Components\Wishlist\Tables\Wish($this->db);
     // Get records
     $lists = $wishlist->getRecords(array('category' => 'group'));
     // vars to hold counts
     $deletedLists = 0;
     $deletedWishes = 0;
     // check to make sure each group wishlist has a valid group
     foreach ($lists as $list) {
         // load group
         $group = \Hubzero\User\Group::getInstance($list->referenceid);
         // if group doesnt exist we need to remove the list and wishes
         if (!$group || !is_object($group)) {
             // Get wishes
             $wishes = $wish->get_wishes($list->id, array('filterby' => 'all', 'sortby' => ''), 1);
             // delete each wish
             foreach ($wishes as $item) {
                 $wish->load($item->id);
                 $wish->delete();
                 $deletedWishes++;
             }
             // delete wishlist
             $wishlist->load($list->id);
             $wishlist->delete();
             $deletedLists++;
         }
     }
 }
Example #2
0
 /**
  * Retrieves a row from the database
  *
  * @param      string $refid    ID of the database table row
  * @param      string $category Element type (determines table to look in)
  * @param      string $parent   If the element has a parent element
  * @return     array
  */
 public function transferItem($from_type, $from_id, $to_type, $rid = 0, $deactivate = 1)
 {
     $upconfig = Component::params('com_members');
     $this->banking = $upconfig->get('bankAccounts');
     $database = App::get('db');
     if ($from_type == NULL or $from_id == NULL or $to_type == NULL) {
         $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_MISSING_INFO'));
         return false;
     }
     if ($from_type == $to_type) {
         $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_CATEGORIES_MUST_BE_DIFFERENT'));
         return false;
     }
     // collectors
     $author = '';
     $subject = '';
     $body = '';
     $tags = '';
     $owner = '';
     // name of group owning the item
     $anonymous = 0;
     // get needed scripts
     include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'models' . DS . 'question.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     $wconfig = Component::params('com_wishlist');
     $admingroup = $wconfig->get('group') ? $wconfig->get('group') : 'hubadmin';
     // Get needed scripts & initial data
     switch ($from_type) {
         // Transfer from a Support Ticket
         case 'ticket':
             $row = new \Components\Support\Models\Ticket($from_id);
             if ($row->exists()) {
                 $author = $row->get('login');
                 $subject = $row->content('raw', 200);
                 // max 200 characters
                 $body = $row->get('summary');
                 $owner = $row->get('group');
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->set('status', 2);
                     $row->set('resolved', 'transfered');
                 }
                 $tags = $row->tags('string');
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
             // Transfer from a Question
         // Transfer from a Question
         case 'question':
             $row = new \Components\Answers\Models\Question($from_id);
             if ($row->exists()) {
                 $author = $row->get('created_by');
                 $subject = $row->subject('raw', 200);
                 // max 200 characters
                 $body = $row->get('question');
                 $anonymous = $row->get('anonymous');
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->set('state', 2);
                     $row->set('reward', 0);
                 }
                 $tags = $row->tags('string');
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
             // Transfer from a Wish
         // Transfer from a Wish
         case 'wish':
             $row = new \Components\Wishlist\Tables\Wish($database);
             $row->load($from_id);
             if ($row->id) {
                 $author = $row->proposed_by;
                 $subject = \Hubzero\Utility\String::truncate($row->subject, 200);
                 // max 200 characters
                 $body = $row->about;
                 $anonymous = $row->anonymous;
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->status = 2;
                     $row->ranking = 0;
                     // also delete all previous votes for this wish
                     $objR = new \Components\Wishlist\Tables\Rank($database);
                     $objR->remove_vote($from_id);
                 }
                 // get owner
                 $objG = new \Components\Wishlist\Tables\OwnerGroup($database);
                 $nativegroups = $objG->get_owner_groups($row->wishlist, $admingroup, '', 1);
                 $owner = count($nativegroups) > 0 && $nativegroups[0] != $admingroup ? $nativegroups[0] : '';
                 // tool group
                 $objWishlist = new \Components\Wishlist\Tables\Wishlist($database);
                 $wishlist = $objWishlist->get_wishlist($row->wishlist);
                 if (isset($wishlist->resource) && isset($wishlist->resource->alias)) {
                     $tags = $wishlist->resource->type == 7 ? 'tool:' : 'resource:';
                     $tags .= $wishlist->resource->alias ? $wishlist->resource->alias : $wishlist->referenceid;
                 }
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
     }
     // if no author can be found, use current administrator
     $author = User::getInstance($author);
     if (!is_object($author)) {
         $author = User::getInstance(User::get('id'));
     }
     $today = Date::toSql();
     // Where do we transfer?
     switch ($to_type) {
         // Transfer to a Support Ticket
         case 'ticket':
             $newrow = new \Components\Support\Models\Ticket();
             $newrow->set('open', 1);
             $newrow->set('status', 0);
             $newrow->set('created', $today);
             $newrow->set('login', $author->get('username'));
             $newrow->set('severity', 'normal');
             $newrow->set('summary', $subject);
             $newrow->set('report', $body ? $body : $subject);
             $newrow->set('section', 1);
             $newrow->set('type', 0);
             $newrow->set('instances', 1);
             $newrow->set('email', $author->get('email'));
             $newrow->set('name', $author->get('name'));
             // do we have an owner group?
             $newrow->set('group', $owner ? $owner : '');
             break;
         case 'question':
             $newrow = new \Components\Answers\Models\Question();
             $newrow->set('subject', $subject);
             $newrow->set('question', $body);
             $newrow->set('created', $today);
             $newrow->set('created_by', $author->get('id'));
             $newrow->set('state', 0);
             $newrow->set('anonymous', $anonymous);
             break;
         case 'wish':
             $newrow = new \Components\Wishlist\Models\Wish();
             $newrow->set('subject', $subject);
             $newrow->set('about', $body);
             $newrow->set('proposed', $today);
             $newrow->set('proposed_by', $author->get('id'));
             $newrow->set('status', 0);
             $newrow->set('anonymous', $anonymous);
             // which wishlist?
             $objWishlist = new \Components\Wishlist\Tables\Wishlist($database);
             $mainlist = $objWishlist->get_wishlistID(1, 'general');
             $listid = 0;
             if (!$rid && $owner) {
                 $rid = $this->getResourceIdFromGroup($owner);
             }
             if ($rid) {
                 $listid = $objWishlist->get_wishlistID($rid);
             }
             $newrow->set('wishlist', $listid ? $listid : $mainlist);
             break;
     }
     // Save new information
     if (!$newrow->store()) {
         $this->setError($newrow->getError());
         return;
     } else {
         // Checkin ticket
         //$newrow->checkin();
         // Extras
         if ($newrow->exists()) {
             switch ($to_type) {
                 case 'ticket':
                     // Tag new ticket
                     if ($tags) {
                         $newrow->tag($tags, User::get('id'), 0);
                     }
                     break;
                 case 'question':
                     // Tag new question
                     if ($tags) {
                         $newrow->tag($tags, User::get('id'), 0);
                     }
                     break;
             }
         }
     }
     // If we are de-activating original item
     if ($deactivate) {
         // overwrite old entry
         if (!$row->store()) {
             $this->setError($row->getError());
             exit;
         }
         // Clean up rewards if banking
         if ($this->banking) {
             switch ($from_type) {
                 case 'ticket':
                     // no banking yet
                     break;
                 case 'question':
                     $reward = \Hubzero\Bank\Transaction::getAmount('answers', 'hold', $from_id, $author->get('id'));
                     // Remove hold
                     if ($reward) {
                         \Hubzero\Bank\Transaction::deleteRecords('answers', 'hold', $from_id);
                         // Make credit adjustment
                         $BTL_Q = new \Hubzero\Bank\Teller($author->get('id'));
                         $credit = $BTL_Q->credit_summary();
                         $adjusted = $credit - $reward;
                         $BTL_Q->credit_adjustment($adjusted);
                     }
                     break;
                 case 'wish':
                     include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'helpers' . DS . 'economy.php';
                     $WE = new \Components\Wishlist\Helpers\Economy($database);
                     $WE->cleanupBonus($from_id);
                     break;
             }
         }
     }
     return $newrow->get('id');
 }
Example #3
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;
 }
Example #4
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 #5
0
 /**
  * Removes an item reported as abusive
  *
  * @param      integer $referenceid ID of the database table row
  * @param      integer $parentid    If the element has a parent element
  * @param      string  $category    Element type (determines table to look in)
  * @param      string  $message     Message to user to append to
  * @return     string
  */
 public function deleteReportedItem($referenceid, $parentid, $category, $message)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $this->loadLanguage();
     $database = App::get('db');
     switch ($category) {
         case 'wish':
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wishlist.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'plan.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'owner.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'ownergroup.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'rank.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'attachment.php';
             // Delete the wish
             $wish = new \Components\Wishlist\Tables\Wish($database);
             $wish->delete_wish($referenceid);
             // also delete all votes for this wish
             $objR = new \Components\Wishlist\Tables\Rank($database);
             $objR->remove_vote($referenceid);
             $message .= Lang::txt('PLG_SUPPORT_WISHLIST_NOTIFICATION_OF_WISH_REMOVAL', $parentid);
             break;
         case 'wishcomment':
             $comment = new \Hubzero\Item\Comment($database);
             $comment->load($referenceid);
             $comment->state = 2;
             if (!$comment->store()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_WISHLIST_NOTIFICATION_OF_COMMENT_REMOVAL', $parentid);
             break;
     }
     return $message;
 }
Example #6
0
 /**
  * Delete any associated wishes & lists when group is deleted
  * 
  * @param      object $group Group being deleted
  * @return     string Log of items removed
  */
 public function onGroupDelete($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 '';
     }
     // Get wishes
     $wishes = $wish->get_wishes($id, array('filterby' => 'all', 'sortby' => ''), 1);
     // delete each wish
     foreach ($wishes as $item) {
         $wish->load($item->id);
         $wish->delete();
     }
     // delete wishlist
     $wishlist->load($id);
     $wishlist->delete();
     // return message
     return Lang::txt('PLG_GROUPS_WISHLIST_LOG', count($wishes));
 }
Example #7
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;
 }
Example #8
0
 /**
  * Display the status of the current app
  *
  * @return     void
  */
 public function statusTask()
 {
     $this->view->setLayout('status');
     if (!$this->_toolid) {
         $this->_toolid = Request::getInt('toolid', 0);
     }
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     // do we have an alias?
     if ($this->_toolid == 0) {
         if ($alias = Request::getVar('app', '')) {
             $this->_toolid = $obj->getToolId($alias);
         }
     }
     // Couldn't get ID, exit
     if (!$this->_toolid) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller));
         return;
     }
     if (!$this->_error) {
         $this->_error = '';
     }
     if (!$this->_msg) {
         $this->_msg = Request::getVar('msg', '', 'post');
     }
     // check access rights
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // get tool status
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     if (!$status) {
         App::abort(404, Lang::txt('COM_TOOLS_ERR_STATUS_CANNOT_FIND'));
         return;
     }
     // get tickets/wishes/questions
     if ($status['published']) {
         $status['questions'] = 'N/A';
         if (Component::isEnabled('com_answers')) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'question.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'response.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'log.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'questionslog.php';
             $aq = new \Components\Answers\Tables\Question($this->database);
             $status['questions'] = $aq->getCount(array('filterby' => 'all', 'sortby' => 'date', 'tag' => 'tool' . $status['toolname']));
         }
         $status['wishes'] = 'N/A';
         if (Component::isEnabled('com_wishlist')) {
             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';
             $objWishlist = new \Components\Wishlist\Tables\Wishlist($this->database);
             $objWish = new \Components\Wishlist\Tables\Wish($this->database);
             $listid = $objWishlist->get_wishlistID($status['resourceid'], 'resource');
             if ($listid) {
                 $controller = new \Components\Wishlist\Controllers\Wishlist();
                 $filters = $controller->getFilters(1);
                 $wishes = $objWish->get_wishes($listid, $filters, 1, User::getRoot());
                 $status['wishes'] = count($wishes);
             } else {
                 $status['wishes'] = 0;
             }
         }
     }
     $this->view->status = $status;
     $this->view->msg = isset($this->_msg) ? $this->_msg : '';
     $this->view->config = $this->config;
     $this->view->admin = $this->config->get('access-admin-component');
     // Set the page title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_option . '_' . $this->_task));
     $this->view->title .= $status['toolname'] ? ' ' . Lang::txt('COM_TOOLS_FOR') . ' ' . $status['toolname'] : '';
     Document::setTitle($this->view->title);
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option);
     }
     Pathway::append(Lang::txt('COM_TOOLS_PIPELINE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=pipeline');
     Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $status['toolname']), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $status['toolname']);
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }