/** * Add one or more owners * * @param string $what Owner type to add * @param mixed $data integer|string|array * @return object */ public function add($what, $data) { $data = $this->_toArray($data); $what = strtolower($what); switch ($what) { case 'advisory': if ($this->config('allow_advisory', 0)) { $tbl = new Tables\Owner($this->_db); if (!$tbl->save_owners($this->get('id'), $this->config(), $data, 2)) { $this->setError($tbl->getError()); } } break; case 'individuals': $tbl = new Tables\Owner($this->_db); if (!$tbl->save_owners($this->get('id'), $this->config(), $data)) { $this->setError($tbl->getError()); } break; case 'groups': $tbl = new Tables\OwnerGroup($this->_db); if (!$tbl->save_owner_groups($this->get('id'), $this->config(), $data)) { $this->setError($tbl->getError()); } break; default: //throw new \InvalidArgumentException(Lang::txt('Owner type not supported.')); throw new \RuntimeException("Lang::txt('Owner type not supported.')", 404); break; } // Reset the owners lists $this->_cache['owners.list0'] = null; $this->_cache['owners.list1'] = null; return $this; }
/** * 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; }