Beispiel #1
0
/**
 * Make all the users nodes and connections in a group private or public.
 * Requires login, user must be member of the group, and this will only update the nodes/connections
 * that the user is the owner of.
 *
 * @param string $groupid
 * @param string $private (must be either 'Y' or 'N')
 * @return Result or Error
 */
function setGroupPrivacy($groupid, $private)
{
    global $DB, $CFG, $USER, $HUB_SQL;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $params = array();
    $params[0] = $groupid;
    $params[1] = $currentuser;
    // set the nodes
    $sql = $HUB_SQL->APILIB_NODE_GROUP_PRIVACY_SELECT;
    $resArray = $DB->select($sql, $params);
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $array = $resArray[$i];
            $n = new CNode($array['NodeID']);
            $n->load();
            $n->setPrivacy($private);
        }
    }
    // set the connections
    $sql = APILIB_CONNECTION_GROUP_PRIVACY_SELECT;
    $resArray = $DB->select($sql, $params);
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $array = $resArray[$i];
            $c = new Connection($array['TripleID']);
            $c = $c->load();
            $c->setPrivacy($private);
        }
    }
    return new Result("privacy updated", "true");
}