Esempio n. 1
0
/**
 * Get the nodes the current user has permission to see.
 *
 * @param integer $viewid the id of the view to get nodes for
 * @param integer $start (optional - default: 0)
 * @param integer $max (optional - default: 20)
 * @param string $orderby (optional, either 'date', 'nodeid', 'name', 'connectedness' or 'moddate' - default: 'date')
 * @param string $sort (optional, either 'ASC' or 'DESC' - default: 'DESC')
 * @param string $filternodetypes (optional, a list of node type names to filter by)
 * @param String $style (optional - default 'long') may be 'short' or 'long'  - how much of a nodes details to load (long includes: description, tags, groups and urls).
 * @param string $q the query term(s)
 * @param string $scope (optional, either 'my' or 'all' - default: 'all')
 * @param boolean $tagsonly (optional, either true or false) if true, only return nodes where they have tags mathing the passed query terms
 * @param string $connectionfilter filter by connections. Defaults to empty string which means disregard connection count. Possible values; '','connected','unconnected'.
 * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired)
 * @return NodeSet or Error
 */
function getNodesByView($viewid, $start = 0, $max = 20, $orderby = 'date', $sort = 'DESC', $filternodetypes = "", $style = 'long', $q = '', $scope = 'all', $tagsonly = false, $connectionfilter = '', $status = 0)
{
    global $CFG, $USER, $HUB_SQL;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $params = array();
    $sql = $HUB_SQL->APILIB_NODES_BY_GLOBAL_SELECT;
    // FILTER NODE TYPES
    if ($filternodetypes != "") {
        $pieces = explode(",", $filternodetypes);
        $sqlList = "";
        $loopCount = 0;
        foreach ($pieces as $value) {
            $params[count($params)] = $value;
            if ($loopCount == 0) {
                $sqlList .= "?";
            } else {
                $sqlList .= ",?";
            }
            $loopCount++;
        }
        $sql .= $HUB_SQL->APILIB_FILTER_NODETYPES . $HUB_SQL->OPENING_BRACKET;
        $sql .= $sqlList;
        $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
    } else {
        $sql .= $HUB_SQL->WHERE;
    }
    // SEARCH
    if (isset($q) && $q != "") {
        if ($tagsonly) {
            $pieces = explode(",", $q);
            $loopCount = 0;
            $search = "";
            foreach ($pieces as $value) {
                $value = trim($value);
                $params[count($params)] = $value;
                if ($loopCount == 0) {
                    $search .= $HUB_SQL->APILIB_TAG_SEARCH;
                } else {
                    $search .= $HUB_SQL->OR . $HUB_SQL->APILIB_TAG_SEARCH;
                }
                $loopCount++;
            }
            $sql .= $HUB_SQL->OPENING_BRACKET;
            $sql .= $search;
            $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
        } else {
            $querySQL = getSearchQueryString($params, $q, true, true);
            $sql .= $querySQL . $HUB_SQL->AND;
        }
    }
    // FILTER ON VIEW
    $params[count($params)] = $viewid;
    $sql .= $HUB_SQL->APLILIB_NODES_BY_VIEW . $HUB_SQL->AND;
    // PERMISSIONS
    if ($scope == 'my') {
        $params[count($params)] = currentuser;
        $sql .= $HUB_SQL->APILIB_NODES_PERMISSIONS_MY;
    } else {
        $params[count($params)] = 'N';
        $params[count($params)] = $currentuser;
        $params[count($params)] = $currentuser;
        $sql .= $HUB_SQL->APILIB_NODES_PERMISSIONS_ALL;
    }
    // FILTER STATUS
    $params[count($params)] = $status;
    $sql .= $HUB_SQL->AND . $HUB_SQL->APILIB_FILTER_STATUS;
    if ($orderby == 'vote') {
        $sql = $HUB_SQL->APILIB_NODE_ORDERBY_VOTE_PART1 . $sql . $HUB_SQL->APILIB_NODE_ORDERBY_VOTE_PART2;
    }
    if ($connectionfilter == 'unconnected') {
        $sql .= $HUB_SQL->APILIB_HAVING_UNCONNECTED;
    } else {
        if ($connectionfilter == 'connected') {
            $sql .= $HUB_SQL->APILIB_HAVING_CONNECTED;
        }
    }
    //error_log("Search=".$sql);
    $ns = new NodeSet();
    return $ns->load($sql, $params, $start, $max, $orderby, $sort, $style);
}
Esempio n. 2
0
/**
 * Get all the groups the current user has permissions to see
 *
 * @param integer $start (optional - default: 0)
 * @param integer $max (optional - default: 20)
 * @param string $orderby (optional, either 'date', 'name' or 'moddate' - default: 'date')
 * @param string $sort (optional, either 'ASC' or 'DESC' - default: 'DESC')
 * @param string $style (optional - default 'long') may be 'short' or 'long'  - how much of a user's details to load (long includes: tags and groups).
 * @param string $q the query term(s)
 * @return GroupSet or Error
 */
function getGroupsByGlobal($start = 0, $max = 20, $orderby = 'date', $sort = 'DESC', $style = 'long', $q = '')
{
    global $CFG, $HUB_SQL;
    $params = array();
    $params[0] = $CFG->USER_STATUS_ACTIVE;
    $params[1] = $CFG->USER_STATUS_REPORTED;
    $params[2] = $CFG->defaultUserID;
    $sql = $HUB_SQL->APILIB_GROUPS_BY_GLOBAL_PART1;
    if ($q != "") {
        $querySQL = getSearchQueryString($params, $q, true, false);
        $sql .= $HUB_SQL->AND . $querySQL;
    }
    $gs = new GroupSet();
    return $gs->loadFromUsers($sql, $params, $start, $max, $orderby, $sort, $style);
}