/** * Display module contents * * @return void */ public function display() { $database = \App::get('db'); include_once Component::path('com_wishlist') . DS . 'models' . DS . 'wishlist.php'; $objWishlist = new Wishlist($database); // Which list is being viewed? $listid = Request::getInt('id', 0); $refid = Request::getInt('rid', 0); $category = Request::getVar('category', ''); // Figure list id if ($category && $refid) { $listid = $objWishlist->get_wishlistID($refid, $category); } // Cannot rank a wish if list/wish is not found if (!$listid) { echo '<p class="warning">' . Lang::txt('MOD_WISHVOTERS_ERROR_LOADING') . '</p>'; return; } $database->setQuery("SELECT DISTINCT v.userid, SUM(v.importance) as imp, COUNT(v.wishid) as times " . " FROM #__wishlist_vote as v JOIN #__wishlist_item as w ON w.id=v.wishid WHERE w.wishlist='" . $listid . "'" . " GROUP BY v.userid ORDER BY times DESC, v.voted DESC "); $this->rows = $database->loadObjectList(); if ($database->getErrorNum()) { $this->setError($database->stderr()); return '<p class="error">' . Lang::txt('MOD_WISHVOTERS_ERROR_RETRIEVING') . '</p>'; } require $this->getLayoutPath(); }
/** * Get the groups ow a wishlist owner * * @param integer $listid List ID * @param string $controlgroup Control group name * @param object $wishlist Wishlist * @param integer $native Get groups assigned to this wishlist? * @param array $groups List of gorups * @return mixed False if errors, array on success */ public function get_owner_groups($listid, $controlgroup = '', $wishlist = null, $native = 0, $groups = array()) { if ($listid === NULL) { return false; } $wishgroups = array(); $obj = new Wishlist($this->_db); // if tool, get tool group if (!$wishlist) { $wishlist = $obj->get_wishlist($listid); } if (isset($wishlist->resource) && $wishlist->resource->type == 7) { $toolgroup = $obj->getToolDevGroup($wishlist->referenceid); if ($toolgroup) { $groups[] = $toolgroup; } } // if primary list, add all site admins if ($controlgroup && $wishlist->category == 'general') { $instance = Group::getInstance($controlgroup); if (is_object($instance)) { $gid = $instance->get('gidNumber'); if ($gid) { $groups[] = $gid; } } } // if private group list, add the group if ($wishlist->category == 'group') { $groups[] = $wishlist->referenceid; } // get groups assigned to this wishlist if (!$native) { $sql = "SELECT o.groupid FROM `#__wishlist_ownergroups` AS o WHERE o.wishlist=" . $this->_db->quote($listid); $this->_db->setQuery($sql); $wishgroups = $this->_db->loadObjectList(); if ($wishgroups) { foreach ($wishgroups as $wg) { if (Group::exists($wg->groupid)) { $groups[] = $wg->groupid; } } } } $groups = array_unique($groups); sort($groups); return $groups; }
/** * Edit a category * * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); $this->view->wishlist = Request::getInt('wishlist', 0); if (!is_object($row)) { // Incoming $id = Request::getVar('id', array(0)); if (is_array($id) && !empty($id)) { $id = $id[0]; } // Load category $row = new Wish($this->database); $row->load($id); } $this->view->row = $row; if (!$this->view->row->id) { $this->view->row->wishlist = $this->view->wishlist; } else { if (!$this->view->wishlist) { $this->view->wishlist = $this->view->row->wishlist; } } /* $m = new Models\AdminWish(); $this->view->form = $m->getForm(); */ $obj = new Wishlist($this->database); $filters = array(); $filters['sort'] = 'title'; $filters['sort_Dir'] = 'ASC'; $this->view->lists = $obj->getRecords($filters); // who are list owners? $this->admingroup = $this->config->get('group', 'hubadmin'); $objOwner = new Owner($this->database); $objG = new OwnerGroup($this->database); $this->view->ownerassignees = array(); $this->view->ownerassignees[-1] = array(); $none = new stdClass(); $none->id = '-1'; $none->name = Lang::txt('COM_WISHLIST_SELECT'); $this->view->ownerassignees[-1][] = $none; $this->view->assignees = null; if ($this->view->lists) { foreach ($this->view->lists as $k => $list) { if ($list->category == 'resource') { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php'; $list->resource = new \Components\Resources\Tables\Resource($this->database); $list->resource->load($list->referenceid); } $this->view->ownerassignees[$list->id] = array(); $none = new stdClass(); $none->id = '0'; $none->name = Lang::txt('COM_WISHLIST_NONE'); $this->view->ownerassignees[$list->id][] = $none; $owners = $objOwner->get_owners($list->id, $this->admingroup, $list); if (count($owners['individuals']) > 0) { $query = "SELECT a.id, a.name FROM `#__users` AS a WHERE a.block = '0' AND a.id IN (" . implode(',', $owners['individuals']) . ") ORDER BY a.name"; $this->database->setQuery($query); $users = $this->database->loadObjectList(); foreach ($users as $row2) { $this->view->ownerassignees[$list->id][] = $row2; } if ($list->id == $this->view->row->wishlist) { $this->view->assignees = $this->view->ownerassignees[$list->id]; } } } } // Get the plan for this wish $objPlan = new Plan($this->database); $plan = $objPlan->getPlan($this->view->row->id); $this->view->plan = $plan ? $plan[0] : $objPlan; // Get tags on this wish include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'tags.php'; $tagging = new Tags($this->view->row->id); $this->view->tags = $tagging->render('string'); // Set any errors foreach ($this->getErrors() as $error) { \Notify::error($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Set the state of an entry * * @return void */ public function stateTask() { $state = $this->getTask() == 'publish' ? 1 : 0; // Incoming $cid = Request::getInt('cid', 0); $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Check for an ID if (count($ids) < 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $state == 1 ? Lang::txt('COM_WISHLIST_SELECT_PUBLISH') : Lang::txt('COM_WISHLIST_SELECT_UNPUBLISH'), 'error'); return; } // Update record(s) foreach ($ids as $id) { // Updating a category $row = new Wishlist($this->database); $row->load($id); $row->state = $state; $row->store(); } // Set message switch ($state) { case '-1': $message = Lang::txt('COM_WISHLIST_ARCHIVED', count($ids)); break; case '1': $message = Lang::txt('COM_WISHLIST_PUBLISHED', count($ids)); break; case '0': $message = Lang::txt('COM_WISHLIST_UNPUBLISHED', count($ids)); break; } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . ($cid ? '&id=' . $cid : ''), false), $message); }
/** * Get a list of owners * * @param integer $listid List ID * @param object $admingroup Admin Group * @param object $wishlist Wish list * @param integer $native Get groups assigned to this wishlist? * @param integer $wishid Wish ID * @param array $owners Owners * @return mixed False if errors, array on success */ public function get_owners($listid, $admingroup, $wishlist = '', $native = 0, $wishid = 0, $owners = array()) { if ($listid === NULL) { return false; } $obj = new Wishlist($this->_db); $objG = new OwnerGroup($this->_db); if (!$wishlist) { $wishlist = $obj->get_wishlist($listid); } // If private user list, add the user if ($wishlist->category == 'user') { $owners[] = $wishlist->referenceid; } // If resource, get contributors if ($wishlist->category == 'resource' && $wishlist->resource->type != 7) { $cons = $obj->getCons($wishlist->referenceid); if ($cons) { foreach ($cons as $con) { $owners[] = $con->id; } } } // Get groups $groups = $objG->get_owner_groups($listid, is_object($admingroup) ? $admingroup->get('group') : $admingroup, $wishlist, $native); if ($groups) { foreach ($groups as $g) { // Load the group $group = \Hubzero\User\Group::getInstance($g); if ($group && $group->get('gidNumber')) { $members = $group->get('members'); $managers = $group->get('managers'); $members = array_merge($members, $managers); if ($members) { foreach ($members as $member) { $owners[] = $member; } } } } } // Get individuals if (!$native) { $sql = "SELECT o.userid FROM `#__wishlist_owners` AS o WHERE o.wishlist=" . $this->_db->quote($listid) . " AND o.type!=2"; $this->_db->setQuery($sql); if ($results = $this->_db->loadObjectList()) { foreach ($results as $result) { $owners[] = $result->userid; } } } $owners = array_unique($owners); sort($owners); // Are we also including advisory committee? $wconfig = Component::params('com_wishlist'); $advisory = array(); if ($wconfig->get('allow_advisory')) { $sql = "SELECT DISTINCT o.userid FROM `#__wishlist_owners` AS o WHERE o.wishlist=" . $this->_db->quote($listid) . " AND o.type=2"; $this->_db->setQuery($sql); if ($results = $this->_db->loadObjectList()) { foreach ($results as $result) { $advisory[] = $result->userid; } } } // Find out those who voted - for distribution of points if ($wishid) { $activeowners = array(); $query = "SELECT v.userid FROM `#__wishlist_vote` AS v LEFT JOIN `#__wishlist_item` AS i ON v.wishid = i.id "; $query .= "WHERE i.wishlist = " . $this->_db->quote($listid) . " AND v.wishid=" . $this->_db->quote($wishid) . " AND (v.userid IN ('" . implode("','", $owners) . "')) "; $this->_db->setQuery($query); if ($result = $this->_db->loadObjectList()) { foreach ($result as $r) { $activeowners[] = $r->userid; } $owners = $activeowners; } } $collect = array(); $collect['individuals'] = $owners; $collect['groups'] = $groups; $collect['advisory'] = $advisory; return $collect; }