예제 #1
0
/**
 * Get all the connections for the given node types and link types
 *
 * @param string $groupid the id of the group to get social connections for
 * @param string $scope (either 'all' or 'my')
 * @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 $linklabels (optional, comma separated strings of the connection labels to filter the results by)
 * @param string $filternodetypes (optional, a list of node type names to filter by)
 * @param String $style (optional - default 'long') may be 'short' or 'long'
 * @return ConnectionSet or Error
 */
function getConnectionsByGroup($groupid, $scope, $start = 0, $max = 20, $orderby = 'date', $sort = 'ASC', $linklabels = '', $filternodetypes = '', $style = 'long')
{
    global $DB, $USER, $CFG, $HUB_SQL;
    $params = array();
    $params[0] = $groupid;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $sql = $HUB_SQL->APILIB_CONNECTIONS_BY_GROUP_SELECT;
    $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GROUP_FILTER;
    // FILTER BY NODE TYPES - AND
    if ($filternodetypes != "") {
        $sql .= $HUB_SQL->AND;
        $nodetypeArray = array();
        $innersql = getSQLForNodeTypeIDsForLabels($nodetypeArray, $filternodetypes);
        $params = array_merge($params, $nodetypeArray);
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_NODETYPE_FILTER_PART1;
        $sql .= $innersql;
        $params = array_merge($params, $nodetypeArray);
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_NODETYPE_FILTER_PART2;
        $sql .= $innersql;
        $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->CLOSING_BRACKET;
    }
    // FILTER BY LINK TYPES
    if ($linklabels != "") {
        $innersql = getSQLForLinkTypeIDsForLabels($params, $linklabels);
        $sql .= $HUB_SQL->AND;
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_LINKTYPE_FILTER;
        $sql .= $HUB_SQL->OPENING_BRACKET;
        $sql .= $innersql;
        $sql .= $HUB_SQL->CLOSING_BRACKET;
    }
    // PERMISSIONS
    if ($scope == "my") {
        $params[count($params)] = $currentuser;
        $sql .= $HUB_SQL->AND;
        $sql .= $HUB_SQL->FILTER_USER;
    }
    $sql .= $HUB_SQL->AND;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_PERMISSIONS;
    $cs = new ConnectionSet();
    //error_log(print_r($sql, true));
    return $cs->load($sql, $params, $start, $max, $orderby, $sort, $style);
}
예제 #2
0
/**
 * Get the country names and their counts for the node type with the name passed as type.
 * @param limit the number of results to return (ordered by use count DESC)
 *
 * @return array of arrays of 'Country' and 'UseCount' fields.
 */
function getCountriesForCloudByType($filternodetypes, $limit = 20)
{
    global $CFG, $DB, $USER, $HUB_SQL;
    $params = array();
    $sql = $HUB_SQL->UTILLIB_COUNTRIES_BY_TYPE_PART1;
    $innersql = getSQLForNodeTypeIDsForLabels($params, $filternodetypes);
    $sql .= $innersql;
    $sql .= $HUB_SQL->UTILLIB_COUNTRIES_BY_TYPE_PART2;
    if ($limit > 0) {
        // ADD LIMITING
        $sql = $DB->addLimitingResults($sql, 0, $limit);
    }
    $finalsql = $HUB_SQL->OPENING_BRACKET . $sql . $HUB_SQL->CLOSING_BRACKET;
    $finalsql .= $HUB_SQL->UTILLIB_COUNTRIES_BY_TYPE_PART3;
    $resArray = $DB->select($finalsql, $params);
    $array = array();
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $next = $resArray[$i];
            array_push($array, $next);
        }
    }
    return $array;
}