function get_records($filter) { global $CURMAN, $USER; $id = $this->required_param('id', PARAM_INT); $sort = $this->optional_param('sort', 'name', PARAM_ALPHA); $dir = $this->optional_param('dir', 'ASC', PARAM_ALPHA); $pagenum = $this->optional_param('page', 0, PARAM_INT); $FULLNAME = sql_concat('usr.firstname', "' '", 'usr.lastname'); $sql = " FROM {$CURMAN->db->prefix_table(USRTABLE)} usr\n LEFT OUTER JOIN {$CURMAN->db->prefix_table(CLSTASSTABLE)} ca ON ca.userid = usr.id AND ca.clusterid = {$id} AND ca.plugin = 'manual'\n WHERE ca.userid IS NULL"; $extrasql = $filter->get_sql_filter(); if ($extrasql) { $sql .= " AND {$extrasql}"; } if (!clusterpage::_has_capability('block/curr_admin:cluster:enrol')) { //perform SQL filtering for the more "conditional" capability //get the context for the "indirect" capability $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:enrol_cluster_user', $USER->id); $allowed_clusters = cluster::get_allowed_clusters($id); if (empty($allowed_clusters)) { $sql .= ' AND 0=1'; } else { $cluster_filter = implode(',', $allowed_clusters); $sql .= " AND usr.id IN (\n SELECT userid FROM " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . "\n WHERE clusterid IN ({$cluster_filter}))"; } } $count = $CURMAN->db->count_records_sql('SELECT COUNT(usr.id) ' . $sql); if ($sort) { if ($sort == 'name') { $sort = 'lastname'; } $sql .= " ORDER BY {$sort} {$dir}"; } $users = $CURMAN->db->get_records_sql("SELECT usr.*, {$FULLNAME} AS name" . $sql, $pagenum * 30, 30); return array($users, $count); }
public static function delete_for_cluster($id) { global $CURMAN; $status = $CURMAN->db->delete_records(CLSTASSTABLE, 'clusterid', $id); cluster::cluster_update_assignments($id, null); return $status; }
function cluster_manual_deassign_user($clusterid, $userid) { global $CURMAN, $CFG; if (!is_numeric($clusterid) || !is_numeric($userid) || $clusterid <= 0 || $userid <= 0) { return false; } $return = $CURMAN->db->delete_records(CLSTASSTABLE, 'userid', $userid, 'clusterid', $clusterid, 'plugin', 'manual'); if ($return) { cluster::cluster_update_assignments($clusterid, $userid); } return $return; }
/** * Handler for the confirm action. Assigns a child cluster to specified cluster. */ function action_subcluster() { global $CFG; $id = $this->required_param('id', PARAM_INT); $target_page = $this->get_new_page(array('id' => $id)); $sub_cluster_id = $this->required_param('subclusterid', PARAM_INT); $cluster = new cluster($sub_cluster_id); $cluster->parent = $id; $cluster->update(); redirect($target_page->get_url(), get_string('cluster_assigned', 'block_curr_admin')); }
<?php // analysis script // load configuration file include_once "config.php"; // load the database class include_once "includes/db_mysql.php"; $db = new DB($config); $class_lookup = array(1 => "no_news", 2 => "news", 3 => "news_op"); $class_mapping = array(1 => 1, 2 => 2, 3 => 2); $class_name_mapping = array("no_news" => "no_news", "news" => "news", "news_op" => "news"); include_once "page_base.php"; include_once "classify.php"; include_once "stemmer.php"; include_once "cluster.php"; $cluster_main = new cluster(); $db->query("SELECT * FROM `init_tweets` WHERE `test`=1 ORDER BY RAND() LIMIT 10"); while ($tweet = $db->fetch_row()) { $cluster_main->tf_idf($tweet['tweet'], $tweet['id']); echo "<br /><br />"; } /* $main_class = new classify(array(1=>"no_news", 2=>"news"), $class_mapping, false); $main_class->add_tweets(array(), 591); $class_totals = array(1=>0, 2=>0); $news_items = array(); $missdirect = array(); $db->query("SELECT * FROM `init_tweets` WHERE `test`=1"); while($tweet = $db->fetch_row()) {
$api1->bingApi($query2, $_SESSION['results'], $offset); // Set BING JSON Data $formatter1->setBingJson($api1->returnBingJsonData(), $api1->returnBingJsonResultFlag()); $formatter1->formatBingJson($_SESSION['results'], $i * 50); } // Blekko Results $api1->blekkoApi($query3, $_SESSION['results'], 0); // Set BLEKKO JSON Data $formatter1->setBlekkoJson($api1->returnBlekkoJsonData(), $api1->returnBlekkoJsonResultFlag()); $formatter1->formatBlekkoJson($_SESSION['results'], 0); // Instantate Aggregator $aggregator1 = new aggregator(new resultSet()); // Send result sets 1,2 & 3 to Data Fusion Function $aggregator1->dataFusion($api1->returnGoogleJsonResultFlag(), $api1->returnBingJsonResultFlag(), $api1->returnBlekkoJsonResultFlag(), $formatter1->returnResultSet('resultSet1'), $formatter1->returnResultSet('resultSet2'), $formatter1->returnResultSet('resultSet3')); // Instantiate Cluster Object $cluster1 = new cluster(); // Instantiate Stopword Dictionary $stopwordDictionary = new dictionary('stop-words-english2-short.txt'); //$stopwordDictionary->loadStopwordFile(); // Add Query to Stopwords $stopwordDictionary->addQueryToStopwords($cluster1->tokeniseString($q)); $stopwords = $stopwordDictionary->returnStopwords(); // Find the cluster terms of interest $cluster1->findBinaTerms($aggregator1->returnResultSetAggSnippets()); // Count Term Freq //$cluster1->countTermFrequency($aggTitles); //$cluster1->countTermFrequency($aggregator1->returnResultSetAggSnippets()); // Set most frequet terms //$cluster1->setMostFrequentTerms(10); //$cluster1->stopwordRemoval($stopwords); //echo $cluster1->countClusteredTerms();
function update() { global $CFG; global $CURMAN; $old = new cluster($this->id); $parent_obj = new cluster($this->parent); $this->depth = empty($parent_obj->depth) ? 1 : $parent_obj->depth + 1; $result = parent::update(); if ($this->parent != $old->parent) { $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $cluster_context_instance = get_context_instance($cluster_context_level, $this->id); // find all subclusters and adjust their depth $delta_depth = $this->depth - $old->depth; $sql = "UPDATE {$CURMAN->db->prefix_table(CLSTTABLE)}\n SET depth = depth + {$delta_depth}\n WHERE id IN (SELECT instanceid\n FROM {$CURMAN->db->prefix_table('context')}\n WHERE contextlevel = {$cluster_context_level}\n AND path LIKE '{$cluster_context_instance->path}/%')"; execute_sql($sql, false); // Blank out the depth and path for associated records and child records in context table $sql = "UPDATE {$CFG->prefix}context\n SET depth=0, path=NULL\n WHERE id={$cluster_context_instance->id} OR path LIKE '{$cluster_context_instance->path}/%'"; execute_sql($sql, false); // Rebuild any blanked out records in context table build_context_path(); } $plugins = cluster::get_plugins(); foreach ($plugins as $plugin) { require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php'; call_user_func('cluster_' . $plugin . '_update', $this); } $result = $result && field_data::set_for_context_from_datarecord('cluster', $this); events_trigger('crlm_cluster_updated', $this); return $result; }
function cluster_profile_update_handler($userdata) { global $CURMAN, $CFG; // make sure a CM user exists cm_moodle_user_to_cm($userdata); $cuid = cm_get_crlmuserid($userdata->id); if (empty($cuid)) { // not a curriculum user -- (guest?) return true; } $usrtable = $CURMAN->db->prefix_table(USRTABLE); $clstproftable = $CURMAN->db->prefix_table(CLSTPROFTABLE); $clstasstable = $CURMAN->db->prefix_table(CLSTASSTABLE); // the cluster assignments that the plugin wants to exist $new_assignments = "(SELECT DISTINCT cu.id as userid, cp.clusterid\n FROM {$CFG->prefix}crlm_cluster_profile cp\n INNER JOIN {$CFG->prefix}crlm_user cu ON cu.id = {$cuid}\n INNER JOIN {$CFG->prefix}user mu on cu.idnumber=mu.idnumber AND mu.mnethostid = {$CFG->mnet_localhost_id}\n WHERE (SELECT COUNT(*)\n FROM {$CFG->prefix}crlm_cluster_profile cp1\n JOIN (SELECT i.userid, i.fieldid, i.data FROM {$CFG->prefix}user_info_data i\n WHERE i.userid = {$userdata->id}\n UNION\n SELECT {$userdata->id} as userid, uif.id as fieldid, uif.defaultdata as data\n FROM {$CFG->prefix}user_info_field uif\n LEFT JOIN {$CFG->prefix}user_info_data i ON i.userid={$userdata->id} AND uif.id = i.fieldid\n WHERE i.id IS NULL\n ) inf ON inf.fieldid = cp1.fieldid AND inf.data = cp1.value\n WHERE cp.clusterid=cp1.clusterid AND inf.userid = mu.id)\n = (SELECT COUNT(*) FROM {$CFG->prefix}crlm_cluster_profile cp1 WHERE cp.clusterid = cp1.clusterid))"; // delete existing assignments that should not be there any more if ($CFG->dbfamily == 'postgres') { $delete = "DELETE FROM {$clstasstable}\n WHERE id IN (\n SELECT id FROM {$clstasstable} a\n LEFT OUTER JOIN {$new_assignments} b ON a.clusterid = b.clusterid AND a.userid = b.userid\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL\n ) AND plugin='profile'"; } else { $delete = "DELETE a FROM {$clstasstable} a\n LEFT OUTER JOIN {$new_assignments} b ON a.clusterid = b.clusterid AND a.userid = b.userid\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL AND a.plugin='profile'"; } $CURMAN->db->execute_sql($delete, false); // add new assignments $insert = "INSERT INTO {$clstasstable}\n (clusterid, userid, plugin)\n SELECT a.clusterid, a.userid, 'profile'\n FROM {$new_assignments} a\n LEFT OUTER JOIN {$clstasstable} b ON a.clusterid = b.clusterid AND a.userid = b.userid AND b.plugin='profile'\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL"; $CURMAN->db->execute_sql($insert, false); cluster::cluster_update_assignments(null, $cuid); return true; }
/** * Determines whether the current user is allowed to create, edit, and delete associations * between a user and a cluster * * @param int $userid The id of the user being associated to the cluster * @param int $clustid The id of the cluster we are associating the user to * * @return boolean True if the current user has the required permissions, otherwise false */ public static function can_manage_assoc($userid, $clustid) { global $USER; $allowed_clusters = array(); if (!clusterpage::can_enrol_into_cluster($clustid)) { //the users who satisfty this condition are a superset of those who can manage associations return false; } else { if (clusterpage::_has_capability('block/curr_admin:cluster:enrol', $clustid)) { //current user has the direct capability return true; } } $allowed_clusters = cluster::get_allowed_clusters($clustid); //query to get users associated to at least one enabling cluster $cluster_select = ''; if (empty($allowed_clusters)) { $cluster_select = '0=1'; } else { $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')'; } $select = "userid = {$userid} AND {$cluster_select}"; //user just needs to be in one of the possible clusters if (record_exists_select(CLSTUSERTABLE, $select)) { return true; } return false; }