public function computeSample() { // Initialize the projects array. $this->projectIssueMetricInitProjects(array('new_issues' => 0, 'new_comments' => 0, 'new_total' => 0)); // Load options. $sample = $this->currentSample; $where_pieces = array(); $args = array(); $args = array_merge($args, array($sample->sample_startstamp, $sample->sample_endstamp)); // Restrict to only the passed projects. if (!empty($sample->options['object_ids'])) { $where_pieces[] = "pi.pid IN (" . db_placeholders($sample->options['object_ids']) . ")"; $args = array_merge($args, $sample->options['object_ids']); } if (empty($where_pieces)) { $where = ''; } else { $where = ' AND ' . implode(' AND ', $where_pieces); } // Pull the count of new issues per project. $projects = db_query("SELECT pi.pid, COUNT(pi.nid) AS count FROM {project_issues} pi INNER JOIN {node} n ON pi.nid = n.nid WHERE n.created >= %d AND n.created < %d{$where} GROUP BY pi.pid", $args); while ($project = db_fetch_object($projects)) { $this->currentSample->values[$project->pid]['new_issues'] = (int) $project->count; $this->currentSample->values[$project->pid]['new_total'] = (int) $project->count; } // Pull the count of new issue comments per project. $projects = db_query("SELECT pi.pid, COUNT(pi.cid) AS count FROM {project_issue_comments} pi WHERE pi.timestamp >= %d AND pi.timestamp < %d{$where} GROUP BY pi.pid", $args); while ($project = db_fetch_object($projects)) { $this->currentSample->values[$project->pid]['new_comments'] = (int) $project->count; // Add the comment count to the total. $this->currentSample->values[$project->pid]['new_total'] = $this->currentSample->values[$project->pid]['new_total'] + (int) $project->count; } }
public static function getLogItems($wids) { $plch = db_placeholders($wids); $res = db_query("SELECT * FROM {watchdog} WHERE wid IN({$plch})", $wids); $items = array(); while ($i = db_fetch_object($res)) { $items[] = $i; } return $items; }
/** * Find node title matches. * * Some code from CCK's nodereference.module */ function _notifications_node_references($string, $match = 'contains', $types = array(), $limit = 10) { $match_operators = array('contains' => "LIKE '%%%s%%'", 'equals' => "= '%s'", 'starts_with' => "LIKE '%s%%'"); if ($types) { $where[] = 'n.type IN (' . db_placeholders($types, 'char') . ') '; $args = $types; } $where[] = 'n.title ' . (isset($match_operators[$match]) ? $match_operators[$match] : $match_operators['contains']); $args[] = $string; $sql = db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE ' . implode(' AND ', $where) . ' ORDER BY n.title, n.type'); $result = db_query_range($sql, $args, 0, $limit); $references = array(); while ($node = db_fetch_object($result)) { $references[$node->nid] = array('title' => $node->title, 'rendered' => check_plain($node->title)); } return $references; }
/** * Builds the current values for total open/closed issues per project. * * @param $state * Issue state, 'open' or 'closed'. * @param $open_states * An array of state IDs that are considered 'open'. * @param $where * Additional filters for the query. * @param $args * Query arguments. */ protected function buildSampleResultsCurrent($state, $open_states, $where, $args) { // Determine IN or NOT IN based on the state we're querying for. $in = $state == 'open' ? 'IN' : 'NOT IN'; // Pull all issues grouped by project/category -- this query will miss any // projects that don't have issues, but we wouldn't want to show any data // for them, anyways. $result = db_query("SELECT pid, category, COUNT(nid) AS count FROM {project_issues} WHERE sid {$in} (" . db_placeholders($open_states) . "){$where} GROUP BY pid, category", $args); // TODO: When http://drupal.org/node/115553 lands, this hard-coded list of // categories will need to be handled differently. $categories = array('bug', 'feature', 'task', 'support'); while ($row = db_fetch_object($result)) { // Add the total count for the category to the values array. if (in_array($row->category, $categories)) { $this->currentSample->values[$row->pid]["{$row->category}_{$state}"] = (int) $row->count; } } }
public function computeSample() { // Initialize the projects array. $this->projectIssueMetricInitProjects(array('reporters' => 0, 'participants' => 0)); // Load options. $sample = $this->currentSample; $where_pieces = array(); $args = array(); $args = array_merge($args, array($sample->sample_startstamp, $sample->sample_endstamp)); // Restrict to only the passed projects. if (!empty($sample->options['object_ids'])) { $where_pieces[] = "pi.pid IN (" . db_placeholders($sample->options['object_ids']) . ")"; $args = array_merge($args, $sample->options['object_ids']); } if (empty($where_pieces)) { $where = ''; } else { $where = ' WHERE ' . implode(' AND ', $where_pieces); } // Pull the count of unique reporters per project. $projects = db_query("SELECT DISTINCT pi.pid, n.uid AS uid FROM {project_issues} pi INNER JOIN {node} n ON pi.nid = n.nid AND n.created >= %d AND n.created < %d{$where}", $args); $project_participants = array(); while ($project = db_fetch_object($projects)) { // Increment the number of reporters for the project, and also store // them as a participant. $this->currentSample->values[$project->pid]['reporters']++; $project_participants[$project->pid][$project->uid] = TRUE; } // Pull the count of unique participants per project. $projects = db_query("SELECT DISTINCT pi.pid, c.uid FROM {project_issue_comments} pi INNER JOIN {comments} c ON pi.cid = c.cid AND pi.timestamp >= %d AND pi.timestamp < %d{$where}", $args); // Add in participants from comments. This will overwrite the reporters if // they are the same uid, thus avoiding double counting. while ($project = db_fetch_object($projects)) { $project_participants[$project->pid][$project->uid] = TRUE; } // Store the total participants for each project. foreach ($project_participants as $pid => $participants) { $this->currentSample->values[$pid]['participants'] = count($participants); } unset($project_participants); }
/** * Counts new releases made for each project during any given sample period. * * @return * An associative array keyed by project nid, where the value is an array * containing the number of new releases created for that project in the * current sample period. */ public function computeSample() { $sample = $this->currentSample; $options = $sample->options; $args = array($sample->sample_startstamp, $sample->sample_endstamp); // Initialize the projects array. $data_types = array('releases' => 0); $this->projectReleaseMetricInitProjects($data_types); // Restrict to only the passed project nids. if (!empty($options['object_ids'])) { $where = " WHERE prn.pid IN (" . db_placeholders($options['object_ids']) . ")"; $args = array_merge($args, $options['object_ids']); } else { $where = ''; } // Pull all release nodes created during the specified time. $nodes = db_query("SELECT prn.pid, COUNT(nr.nid) AS releases FROM {project_release_nodes} prn INNER JOIN {node} nr ON prn.nid = nr.nid AND nr.created >= %d AND nr.created < %d{$where} GROUP BY prn.pid", $args); while ($node = db_fetch_object($nodes)) { $this->currentSample->values[$node->pid]['releases'] = (int) $node->releases; } }
/** * Figure out what project and API terms to generate the history for. */ function project_release_history_generate_all($project_id = 0) { if (!empty($project_id)) { if (is_numeric($project_id)) { $project_nid = $project_id; } else { $project_nid = db_result(db_query("SELECT nid FROM {project_projects} WHERE uri = '%s'", $project_id)); } if (empty($project_nid)) { wd_err(array('message' => 'Project ID %id not found', 'args' => array('%id' => $project_id))); return FALSE; } wd_msg(array('message' => 'Generating XML release history files for project: %id.', 'args' => array('%id' => $project_id))); } else { wd_msg(array('message' => 'Generating XML release history files for all projects.', 'args' => array())); } $api_terms = project_release_compatibility_list(); $i = 0; if (empty($project_nid)) { // Generate all.xml files for projects with releases. $query = db_query("SELECT DISTINCT(pid) FROM {project_release_nodes}"); while ($project = db_fetch_object($query)) { project_release_history_generate_project_xml($project->pid); $i++; } } else { project_release_history_generate_project_xml($project_nid); $i++; } if ($i == 1) { wd_msg(array('message' => 'Generated an XML release history summary for a project.')); } else { wd_msg(array('message' => 'Generated XML release history summaries for @count projects.', 'args' => array('@count' => $i))); } // Generate XML files based on API compatibility. $i = 0; $args = array_keys($api_terms); $placeholders = db_placeholders($args); $where = ''; if (!empty($project_nid)) { $args[] = $project_nid; $where = 'AND pid = %d'; } $query = db_query("SELECT DISTINCT(pid), version_api_tid FROM {project_release_nodes} WHERE version_api_tid IN ({$placeholders}) {$where}", $args); while ($project = db_fetch_object($query)) { project_release_history_generate_project_xml($project->pid, $project->version_api_tid); $i++; } if ($i == 1) { wd_msg(array('message' => 'Completed XML release history files for 1 project/version pair')); } else { wd_msg(array('message' => 'Completed XML release history files for @count project/version pairs', 'args' => array('@count' => $i))); } return TRUE; }
/** * Calculate and returns statistics about results for this component. * * This takes into account all submissions to this webform. The output of this * function will be displayed under the "Results" tab then "Analysis". * * @param $component * An array of information describing the component, directly correlating to * the webform_component database schema. * @param $sids * An optional array of submission IDs (sid). If supplied, the analysis will * be limited to these sids. * @param $single * Boolean flag determining if the details about a single component are being * shown. May be used to provided detailed information about a single * component's analysis, such as showing "Other" options within a select list. * @return * An array of data rows, each containing a statistic for this component's * submissions. */ function _webform_analysis_component($component, $sids = array(), $single = FALSE) { // Generate the list of options and questions. $options = _webform_component_options($component['extra']['options']); $questions = array_values(_webform_component_options($component['extra']['questions'])); // Generate a lookup table of results. $sidfilter = count($sids) ? " AND sid in (" . db_placeholders($sids, 'int') . ")" : ""; $query = 'SELECT no, data, count(data) as datacount ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND cid = %d ' . " AND data != '' " . $sidfilter . ' GROUP BY no, data'; $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); $counts = array(); while ($data = db_fetch_object($result)) { $counts[$data->no][$data->data] = $data->datacount; } // Create an entire table to be put into the returned row. $rows = array(); $header = array(''); // Add options as a header row. foreach ($options as $option) { $header[] = $option; } // Add questions as each row. foreach ($questions as $qkey => $question) { $row = array($question); foreach ($options as $okey => $option) { $row[] = !empty($counts[$qkey][$okey]) ? $counts[$qkey][$okey] : 0; } $rows[] = $row; } $output = theme('table', $header, $rows, array('class' => 'webform-grid')); return array(array(array('data' => $output, 'colspan' => 2))); }
/** * Check if the author can send a message to the recipients. * * This can be used to limit who can write whom based on other modules and/or * settings. * * @param $author * Author of the message to be sent * @param $recipients * Recipients of the message * @return * An indexed array of arrays with the keys uid and * message (The reason why the recipient has been blocked). */ function hook_privatemsg_block_message($author, $recipients) { $blocked = array(); // Loop through each recipient and ensure there is no rule blocking this // author from sending them private messages. Use a reference, so when // user_load() is needed here the array is updated, negating the need for // further calls to user_load() later in the code. foreach (array_keys($recipients) as $uid) { // Ensure we have a recipient user object which includes roles. if (!isset($recipients[$uid]->roles)) { $recipients[$uid] = user_load($uid); } // Note: this is checked whether the author may send the message (see third // parameter). Further below is a check whether the recipient may block it. if (_pm_block_user_rule_exists($author, $recipients[$uid], PM_BLOCK_USER_DISALLOW_SENDING)) { $blocked[] = array('uid' => $uid, 'message' => t('Sorry, private messaging rules forbid sending messages to !name.', array('!name' => $recipients[$uid]->name))); } } $args = array_merge(array($author->uid), array_keys($recipients)); $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN (' . db_placeholders($recipients) . ') GROUP BY recipient', $args); while ($row = db_fetch_array($result)) { $recipient = $recipients[$row['recipient']]; // If there's a rule disallowing blocking of this message, send it anyway. if (_pm_block_user_rule_exists($author, $recipient, PM_BLOCK_USER_DISALLOW_BLOCKING)) { continue; } $blocked[] = array('uid' => $row['recipient'], 'message' => t('%name has chosen to not recieve any more messages from you.', array('%name' => $recipients[$row['recipient']]->name))); } return $blocked; }
function ciclo20v2_taxonomy_term_page($tids, $result) { $str_tids = arg(2); $terms = taxonomy_terms_parse_string($str_tids); $title_result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN (' . db_placeholders($terms['tids']) . ')', 't', 'tid'), $terms['tids']); $title_tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. $names = array(); while ($term = db_fetch_object($title_result)) { $title_tids[] = $term->tid; $names[] = $term->name; } $last_name = array_pop($names); if (count($names) == 0) { $title = t("Pages containing '@tag'", array('@tag' => $last_name)); } elseif ($terms['operator'] == "or") { $title = t("Pages containing '@tags or @last_tag'", array('@tags' => implode(", ", $names), '@last_tag' => $last_name)); } else { $title = t("Pages containing '@tags and @last_tag'", array('@tags' => implode(", ", $names), '@last_tag' => $last_name)); } drupal_set_title($title); drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css'); $output = ''; // Only display the description if we have a single term, to avoid clutter and confusion. if (count($tids) == 1) { $term = taxonomy_get_term($tids[0]); $description = $term->description; // Check that a description is set. if (!empty($description)) { $output .= '<div class="taxonomy-term-description">'; $output .= filter_xss_admin($description); $output .= '</div>'; } } $output .= commons_connect_taxonomy_render_nodes($result); return $output; }
/** * Act on taxonomy terms when loaded. * * Modules implementing this hook can act on the term object returned by * taxonomy_term_load(). * For performance reasons, information to be added to term objects should be * loaded in a single query for all terms where possible. * * Since terms are stored and retrieved from cache during a page request, avoid * altering properties provided by the {term_data} table, since this may * affect the way results are loaded from cache in subsequent calls. * * @param $terms * An array of term objects, indexed by tid. */ function hook_taxonomy_term_load($terms) { $result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (' . db_placeholders(array_keys($terms)) . ')', array_keys($terms)); foreach ($result as $record) { $terms[$record->tid]->foo = $record->foo; } }
/** * Load node-type-specific information. * * This is a hook used by node modules. It is called to allow the module * a chance to load extra information that it stores about a node. The hook * should not be used to replace information from the core {node} table since * this may interfere with the way nodes are fetched from cache. * * @param $nodes * An array of the nodes being loaded, keyed by nid. At call time, * node.module has already loaded the basic information about the nodes, such * as node ID (nid), title, and body. * * For a detailed usage example, see node_example.module. */ function hook_load($nodes) { $result = db_fetch_object(db_query('SELECT nid, foo FROM {mytable} WHERE nid IN (' . db_placeholders(array_keys($nodes)) . ')', array_keys($nodes))); foreach ($result as $record) { $nodes[$record->nid]->foo = $record->foo; } }
/** * Provides access to the items after they are rendered. This hook is useful * for converting IDs to display names or adding the #options key to form * elements. * * @param &$items * An array containing the rendered facet arrays. In other words, they have * just been processed by the "callback" function in the $relam definition. * @param $realm * A string containing the machine readable realm name the facets are being * rendered in. * @param $module * A string containing the module handling the search. * @param $type * A string containing the type of content $module indexes, NULL if no type. * @return * NULL */ function hook_luceneapi_facet_postrender_alter(&$items, $realm, $module, $type = NULL) { // The following example is a simplified version of code in the // luceneapi_node_luceneapi_facet_postrender_alter() function. // The example is only valid for "node" content. if ('node' != $type) { return; } // Converts UIDs to usernames for the "author" facet in the "block" realm. if ('block' == $realm && isset($items['author'])) { // Gets all UIDs in the search result set. $values = array_keys($items['author']['items']); // NOTE: We should check to see if $values is empty, but the check has been // omitted in the spirit of simplicity. // Builds query that converts the UIDs to usernames. $sql = 'SELECT uid, name' . ' FROM {users}' . ' WHERE uid IN (' . db_placeholders($values, 'varchar') . ')'; // Adds usernames as the display text. if ($result = db_query($sql, $values)) { while ($row = db_fetch_object($result)) { $items['author']['items'][$row->uid]['text'] = $row->name; } } } // Adds content types as #options for the "type" facet in the "fieldset", // adds additional markup to surround the form element. if ('fieldset' == $realm && isset($items['type'])) { // Gets all available content types. $types = array_map('check_plain', node_get_types('names')); // Adds prefix, suffix, and options to the select box, removes description. $items['type'] = array_merge($items['type'], array('#title' => t('Only of the type(s)'), '#prefix' => '<div class="criterion">', '#suffix' => '</div>', '#options' => $types)); unset($items['type']['#description']); } }