Exemplo n.º 1
0
     } else {
         $nodeid = $node->nodeid;
         $node = getNode($nodeid);
         if ($node instanceof Error) {
             echo "<h1>" . $LNG->ISSUE_NAME . " " . $LNG->ITEM_NOT_FOUND_ERROR . "</h1>";
             include_once $HUB_FLM->getCodeDirPath("ui/footer.php");
             die;
         }
     }
 } else {
     if ($nodetype == "Pro" || $nodetype == "Con" || $nodetype == "Comment") {
         $selectednodeid = $nodeid;
         $conSetSol = getConnectionsByNode($node->nodeid, 0, 1, 'date', 'ASC', 'all', '', 'Solution');
         $consol = $conSetSol->connections[0];
         $nodesol = $consol->to;
         $consSet = getConnectionsByNode($nodesol->nodeid, 0, 1, 'date', 'ASC', 'all', '', 'Issue');
         $con = $consSet->connections[0];
         $localnode = $con->to;
         if ($localnode instanceof Error) {
             echo "<h1>" . $LNG->ITEM_NOT_FOUND_ERROR . "</h1>";
             include_once $HUB_FLM->getCodeDirPath("ui/footer.php");
             die;
         } else {
             $nodeid = $localnode->nodeid;
             $node = getNode($nodeid);
             if ($node instanceof Error) {
                 echo "<h1>" . $LNG->ITEM_NOT_FOUND_ERROR . "</h1>";
                 include_once $HUB_FLM->getCodeDirPath("ui/footer.php");
                 die;
             }
         }
Exemplo n.º 2
0
function mergeSelectedNodes($issuenodeid, $groupid, $ids, $title, $desc)
{
    global $CFG;
    $mainConnections = getConnectionsByNode($issuenodeid, 0, -1, 'date', 'ASC', 'all', '', 'Solution');
    $mainconns = $mainConnections->connections;
    $r = getRoleByName("Solution");
    $rolesolution = $r->roleid;
    // CREATE THE solution NODE
    $solutionnode = addNode($title, $desc, 'N', $rolesolution);
    if (!$solutionnode instanceof Error) {
        // Add to group
        if (isset($groupid) && $groupid != "") {
            addGroupToNode($solutionnode->nodeid, $groupid);
        }
        // CONNECT NODE TO FOCAL
        $node = getNode($issuenodeid);
        $r = getRoleByName($node->role->name);
        $focalroleid = $r->roleid;
        $lt = getLinkTypeByLabel($CFG->LINK_SOLUTION_ISSUE);
        $linkType = $lt->linktypeid;
        $conndesc = "";
        $connection = addConnection($solutionnode->nodeid, $rolesolution, $linkType, $issuenodeid, $focalroleid, "N", $conndesc);
        if (!$connection instanceof Error) {
            // add to group
            if (isset($groupid) && $groupid != "") {
                addGroupToConnection($connection->connid, $groupid);
            }
            // CONNECT NEW NODE TO SELECT NODES
            $lt2 = getLinkTypeByLabel($CFG->LINK_COMMENT_BUILT_FROM);
            $linkTypeBuiltFrom = $lt2->linktypeid;
            //error_log(print_r($linkTypeBuiltFrom, true));
            $nodesArr = split(",", $ids);
            foreach ($nodesArr as $nodeid2) {
                $n = new CNode($nodeid2);
                $n = $n->load();
                $r = getRoleByName($n->role->name);
                $roleid = $r->roleid;
                $connection2 = addConnection($solutionnode->nodeid, $rolesolution, $linkTypeBuiltFrom, $nodeid2, $roleid, "N", $conndesc);
                //error_log(print_r($connection2, true));
                if (!$connection2 instanceof Error) {
                    // add to group
                    if (isset($groupid) && $groupid != "") {
                        addGroupToConnection($connection2->connid, $groupid);
                    }
                    // Link kids to new parent
                    $conSetKids = getConnectionsByNode($nodeid2, 0, -1, 'date', 'ASC', 'all', '', 'Pro,Con,Comment');
                    $conns = $conSetKids->connections;
                    foreach ($conns as $con) {
                        $from = $con->from;
                        $lt3 = getLinkTypeByLabel($CFG->LINK_COMMENT_NODE);
                        $linkType3 = $lt3->linktypeid;
                        if ($from->role->name == "Pro") {
                            $lt3 = getLinkTypeByLabel($CFG->LINK_PRO_SOLUTION);
                            $linkType3 = $lt3->linktypeid;
                        } else {
                            if ($from->role->name == "Con") {
                                $lt3 = getLinkTypeByLabel($CFG->LINK_CON_SOLUTION);
                                $linkType3 = $lt3->linktypeid;
                            }
                        }
                        // Connect the children of each node being merged to the new node
                        $connection3 = addConnection($from->nodeid, $from->role->roleid, $linkType3, $solutionnode->nodeid, $rolesolution, "N", $conndesc);
                        if (!$connection3 instanceof Error) {
                            // add to group
                            if (isset($groupid) && $groupid != "") {
                                addGroupToConnection($connection3->connid, $groupid);
                            }
                        } else {
                            return $connection3;
                        }
                        // retire old connection
                        $con->updateStatus($CFG->STATUS_RETIRED);
                    }
                    // retire connection to parent
                    foreach ($mainconns as $con) {
                        $from = $con->from;
                        if ($from->nodeid == $nodeid2) {
                            $con->updateStatus($CFG->STATUS_RETIRED);
                        }
                    }
                    // retire node
                    $n->updateStatus($CFG->STATUS_RETIRED);
                } else {
                    return $connection2;
                }
            }
        } else {
            return $connection;
        }
    }
    return $solutionnode;
}
Exemplo n.º 3
0
     $response = getConnection($connid, $style);
     break;
 case "getconnectionsbyuser":
     $query = required_param('q', PARAM_TEXT);
     $userid = required_param('userid', PARAM_ALPHANUMEXT);
     $response = getConnectionsByUser($userid, $start, $max, $o, $s, $filterlinkgroup, $filterlinktypes, $filternodetypes, $style, $query, $status);
     break;
 case "getconnectionsbyglobal":
     $query = optional_param('q', "", PARAM_TEXT);
     $scope = optional_param('scope', 'all', PARAM_TEXT);
     $tagsonly = optional_param('tagsonly', false, PARAM_BOOL);
     $response = getConnectionsByGlobal($start, $max, $o, $s, $filterlinkgroup, $filterlinktypes, $filternodetypes, $style, $query, $scope, $tagsonly, $status);
     break;
 case "getconnectionsbynode":
     $nodeid = required_param('nodeid', PARAM_ALPHANUMEXT);
     $response = getConnectionsByNode($nodeid, $start, $max, $o, $s, $filterlinkgroup, $filterlinktypes, $filternodetypes, $style, $status);
     break;
 case "getconnectionsbyurl":
     $url = required_param('url', PARAM_URL);
     $response = getConnectionsByURL($url, $start, $max, $o, $s, $filterlinkgroup, $filterlinktypes, $filternodetypes, $style, $status);
     break;
 case "getconnectionsbysocial":
     $linklabels = required_param('linklabels', PARAM_TEXT);
     $filternodetypes = required_param('filternodetypes', PARAM_TEXT);
     $scope = optional_param('scope', 'all', PARAM_ALPHANUM);
     $userid = optional_param('userid', '', PARAM_ALPHANUMEXT);
     $response = getConnectionsBySocial($scope, $start, $max, $o, $s, $linklabels, $filternodetypes, $userid, $style, $status);
     break;
 case "getmulticonnections":
     $connectionids = parseToJSON(required_param('connectionids', PARAM_TEXT));
     // needs this parsing to convert single speech marks back.
Exemplo n.º 4
0
/**
 * Get the connections to solutions for the issue with the given issueid and apply lemoning filter and return just the removed ideas
 *
 * @param string $issueid the id of the issue to get ideas for
 * @return ConnectionSet or Error
 */
function getDebateIdeaConnectionsRemoved($issueid)
{
    $connectionSet = getConnectionsByNode($issueid, 0, -1, 'date', 'ASC', 'selected', 'responds to', 'Solution', 'long', 0);
    $conns = $connectionSet->connections;
    $count = count($conns);
    $connectionSet->totalno = $count;
    $connectionsWithoutLemonsList = array();
    $connectionsWithLemonsList = array();
    $connectionsGroupedByLemons = array();
    // process the connections and filter into list based on lemoning.
    for ($i = 0; $i < $count; $i++) {
        $conn = $conns[$i];
        $from = $conn->from;
        $lemonvotes = $from->lemonvotes;
        if ($lemonvotes > 0) {
            array_push($connectionsWithLemonsList, $conn);
            if (array_key_exists($lemonvotes, $connectionsGroupedByLemons)) {
                $next = $connectionsGroupedByLemons[$lemonvotes];
                array_push($next, $conn);
                $connectionsGroupedByLemons[$lemonvotes] = $next;
            } else {
                $array = array();
                array_push($array, $conn);
                $connectionsGroupedByLemons[$lemonvotes] = $array;
            }
        } else {
            array_push($connectionsWithoutLemonsList, $conn);
        }
    }
    // If there are no lemon votes, just return an empty list as nothing would be removed.
    $lemonvotecount = count($connectionsWithLemonsList);
    if ($lemonvotecount == 0) {
        return new ConnectionSet();
    }
    // calulate what would be 60% of list.
    $sixtycount = floor($count / 100 * 60);
    // We want the final sort order to be by lemon count DESC so always do this bit.
    $dumpedconns = array();
    $runningtotal = 0;
    krsort($connectionsGroupedByLemons, SORT_NUMERIC);
    foreach ($connectionsGroupedByLemons as $key => $batch) {
        $batchcount = count($batch);
        $potentialcount = $runningtotal + $batchcount;
        if ($potentialcount > $sixtycount) {
            break;
        } else {
            $runningtotal = $runningtotal + $batchcount;
            $dumpedconns = array_merge($dumpedconns, $batch);
        }
    }
    $connectionSet->connections = $dumpedconns;
    $connectionSet->count = count($dumpedconns);
    return $connectionSet;
}
Exemplo n.º 5
0
/** EVIDENCE HUB SPECIFIC FUNCTIONS **/
function updateConnectionsForTypeChange($nodeid, $type)
{
    global $USER, $CFG;
    $connectionSet = getConnectionsByNode($nodeid, 0, -1);
    $connections = $connectionSet->connections;
    $count = count($connections);
    for ($i = 0; $i < $count; $i++) {
        $con = $connections[$i];
        if ($con->from->nodeid == $nodeid) {
            $currentuser = $USER;
            $conUserID = $con->userid;
            $conUser = new User($conUserID);
            $conUser = $conUser->load();
            $USER = $conUser;
            $r = getRoleByName($type);
            $roleid = $r->roleid;
            $con->edit($con->from->nodeid, $roleid, $con->linktype->linktypeid, $con->to->nodeid, $con->torole->roleid, $con->private, $con->description);
            $USER = $currentuser;
        } else {
            if ($con->to->nodeid == $nodeid) {
                $currentuser = $USER;
                $conUserID = $con->userid;
                $conUser = new User($conUserID);
                $conUser = $conUser->load();
                $USER = $conUser;
                $r = getRoleByName($type);
                $roleid = $r->roleid;
                $con->edit($con->from->nodeid, $con->fromrole->roleid, $con->linktype->linktypeid, $con->to->nodeid, $roleid, $con->private, $con->description);
                $USER = $currentuser;
            }
        }
    }
}
Exemplo n.º 6
0
 /**
  * Loads the data for the node from the database
  *
  * @param String $style (optional - default 'long') may be 'short' or 'long' or 'mini' or 'full' or 'shortactivity' (mini used for graphs)
  * 'mini' include the base information like name, description, role, user, private, creation and modifications dates, connectedness, image, thumb.
  * 'short' includes 'mini' plus address information, start and end date, otherconnections, userfollow.
  * 'long' includes 'short' and associated website objects, tag objects, group objects, votes, view counts and extra properties.
  * 'full' includes 'long' and all activity and voting data. This is likely to be very heavy. Use wisely.
  * 'shortactivity' includes 'short' plus the activity and voting data.
  * 'cif' just what is needed for cif.
  * @return Node object (this)
  */
 function load($style = 'long')
 {
     global $DB, $CFG, $USER, $ERROR, $HUB_FLM, $HUB_SQL;
     try {
         $this->canview();
     } catch (Exception $e) {
         return access_denied_error();
     }
     $this->style = $style;
     $this->cachetime = time();
     $params = array();
     $params[0] = $this->nodeid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_SELECT, $params);
     if ($resArray !== false) {
         $count = count($resArray);
         if ($count == 0) {
             $ERROR = new error();
             $ERROR->createNodeNotFoundError($this->nodeid);
             return $ERROR;
         } else {
             for ($i = 0; $i < $count; $i++) {
                 $array = $resArray[$i];
                 $this->name = stripslashes(trim($array['Name']));
                 $this->creationdate = $array['CreationDate'];
                 $this->modificationdate = $array['ModificationDate'];
                 if (isset($array['NodeTypeID'])) {
                     $role = new Role($array['NodeTypeID']);
                     $this->role = $role->load();
                 }
                 if (trim($array['Description']) != "") {
                     $this->hasdesc = true;
                 }
                 $this->description = stripslashes(trim($array['Description']));
                 $this->users = array();
                 if ($style == 'cif') {
                     //CIF does not need the whole user info at present
                     // or just userid at this level?
                     $this->users[0] = new User($array['UserID']);
                 } else {
                     $this->connectedness = $array['connectedness'];
                     $this->private = $array['Private'];
                     $this->users[0] = getUser($array['UserID'], $style);
                     if ($array['Image']) {
                         $this->filename = $array['Image'];
                         $imagedir = $HUB_FLM->getUploadsNodeDir($this->nodeid, $array['UserID']);
                         $originalphotopath = $HUB_FLM->createUploadsDirPath($imagedir . "/" . stripslashes($array['Image']));
                         if (file_exists($originalphotopath)) {
                             $this->image = $HUB_FLM->getUploadsWebPath($imagedir . "/" . stripslashes($array['Image']));
                             $this->thumb = $HUB_FLM->getUploadsWebPath($imagedir . "/" . str_replace('.', '_thumb.', stripslashes($array['Image'])));
                             if (!file_exists($this->thumb)) {
                                 create_image_thumb($array['Image'], $CFG->IMAGE_THUMB_WIDTH, $imagedir);
                             }
                         } else {
                             if ($this->role->name == 'Issue') {
                                 $this->image = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_ISSUE_PHOTO);
                                 $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_ISSUE_PHOTO)));
                             }
                         }
                     } else {
                         if ($this->role->name == 'Issue') {
                             $this->image = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_ISSUE_PHOTO);
                             $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_ISSUE_PHOTO)));
                         }
                     }
                     //if(isset($array['Image'])){
                     //    $this->imageurlid = $array['Image'];
                     //}
                     //if(isset($array['ImageThumbnail'])){
                     //    $this->thum = $array['ImageThumbnail'];
                     //}
                     if ($style != 'mini') {
                         if (isset($array['StartDate'])) {
                             $this->startdatetime = $array['StartDate'];
                         }
                         if (isset($array['EndDate'])) {
                             $this->enddatetime = $array['EndDate'];
                         }
                         if (isset($array['LocationText'])) {
                             $this->location = $array['LocationText'];
                         } else {
                             $this->location = '';
                         }
                         if (isset($array['LocationCountry'])) {
                             $cs = getCountryList();
                             $this->countrycode = $array['LocationCountry'];
                             if (isset($cs[$array['LocationCountry']])) {
                                 $this->country = $cs[$array['LocationCountry']];
                             }
                         }
                         if (isset($array['LocationLat'])) {
                             $this->locationlat = $array['LocationLat'];
                         }
                         if (isset($array['LocationLng'])) {
                             $this->locationlng = $array['LocationLng'];
                         }
                         if (isset($array['LocationAddress1'])) {
                             $this->locationaddress1 = $array['LocationAddress1'];
                         }
                         if (isset($array['LocationAddress2'])) {
                             $this->locationaddress2 = $array['LocationAddress2'];
                         }
                         if (isset($array['LocationPostCode'])) {
                             $this->locationpostcode = $array['LocationPostCode'];
                         }
                         if (isset($array['AdditionalIdentifier'])) {
                             $this->identifier = $array['AdditionalIdentifier'];
                         }
                         if (isset($array['CurrentStatus'])) {
                             $this->status = $array['CurrentStatus'];
                         }
                     }
                 }
             }
         }
     } else {
         return database_error();
     }
     $currentuser = '';
     if (isset($USER->userid)) {
         $currentuser = $USER->userid;
     }
     if ($style != 'mini' && $style != 'cif') {
         $params = array();
         $params[0] = $this->nodeid;
         $params[1] = $this->nodeid;
         $params[2] = $currentuser;
         $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_EXTERNAL_CONNECTIONS, $params);
         if ($resArray !== false) {
             if (count($resArray) > 0) {
                 $this->otheruserconnections = $resArray[0]['connectedness'];
             } else {
                 $this->otheruserconnections = 0;
             }
         }
         $this->userfollow = "N";
         //load the current user's following status for this node if any
         $params = array();
         $params[0] = $currentuser;
         $params[1] = $this->nodeid;
         $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_USER_FOLLOW, $params);
         if ($resArray !== false) {
             if (count($resArray) > 0) {
                 $this->userfollow = "Y";
             }
         }
     }
     if ($style == 'long' || $style == 'full' || $style == 'cif') {
         $this->loadWebsites($style);
     }
     if ($style == 'long' || $style == 'full') {
         $this->loadTags();
         $this->loadGroups();
         $this->loadVotes();
         $this->loadProperties();
         $this->loadViewCount();
     }
     if ($style == 'full' || $style == 'shortactivity') {
         $this->activity = getAllNodeActivity($this->nodeid, 0, 0, -1);
         $this->votes = getVotes($this->nodeid);
     }
     //load comments, pro count and con count if Solution.
     if ($this->role->name == "Solution") {
         $this->haschildren = 'N';
         $conSetKids = getConnectionsByNode($this->nodeid, 0, 0, 'date', 'ASC', 'all', '', 'Pro,Con,Comment');
         if (!$conSetKids instanceof Error) {
             if ($conSetKids->totalno > 0) {
                 $this->haschildren = 'Y';
             }
         } else {
             return database_error();
         }
     }
     return $this;
 }
Exemplo n.º 7
0
 if ($summary == "") {
     array_push($errors, $LNG->FORM_EVIDENCE_ENTER_SUMMARY_ERROR);
 }
 if (empty($errors)) {
     $currentUser = $USER;
     $private = optional_param("private", "Y", PARAM_ALPHA);
     $r = getRoleByName($nodetypename);
     $roleType = $r->roleid;
     $desc = stripslashes(trim($desc));
     $evidencenode = editNode($nodeid, $summary, $desc, $private, $roleType);
     if ($evidencenode instanceof Error) {
         array_push($errors, $LNG->FORM_EVIDENCE_ALREADY_EXISTS);
     } else {
         // Get all connections this node is used in and update any that are now using the wrong link type or role type.
         if ($node->role->name != $nodetypename) {
             $mainConnections = getConnectionsByNode($nodeid, 0, -1, 'date', 'ASC', 'all', '', 'Solution');
             $count = count($mainConnections->connections);
             $currentuser = $USER;
             for ($i = 0; $i < $count; $i++) {
                 $con = $mainConnections->connections[$i];
                 // Temporarily be the connection owner.
                 $USER = $con->users[0];
                 // Update ContextTypeID on Change
                 $r = getRoleByName($nodetypename);
                 $newroleid = $r->roleid;
                 $newfromroleid = $con->fromcontexttypeid;
                 $newtoroleid = $con->tocontexttypeid;
                 if ($con->from->nodeid == $nodeid) {
                     $newfromroleid = $newroleid;
                 } else {
                     if ($con->to->nodeid == $nodeid) {