/** * 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'); }
/** * 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; }
/** * 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; }