Commit 86e00dbf authored by Penny Leach's avatar Penny Leach
Browse files

more dml refactoring. updated all calls to get_rows * and changed

resulting stuff to objects rather than arrays
parent c145b82e
......@@ -64,12 +64,12 @@ $userid = $SESSION->get('id');
if ($type == 'all') {
$count = count_records('notification_internal_activity', 'usr', $userid);
$records = get_rows('notification_internal_activity', 'usr', $userid,
$records = get_records_array('notification_internal_activity', 'usr', $userid,
'ctime DESC', '*', $offset, $limit);
} else {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?',
array($userid,$type));
$records = get_rows_select('notification_internal_activity', 'usr = ? AND type = ?',
$records = get_records_select_array('notification_internal_activity', 'usr = ? AND type = ?',
array($userid, $type),
'ctime DESC', '*', $offset, $limit);
}
......@@ -82,8 +82,8 @@ $star = theme_get_image_path('star.png');
$unread = get_string('unread', 'activity');
foreach ($records as &$r) {
$r['date'] = format_date(strtotime($r['ctime']));
$r['type'] = get_string('type' . $r['type'], 'activity');
$r->date = format_date(strtotime($r->ctime));
$r->type = get_string('type' . $r->type, 'activity');
}
$activity = array(
......
......@@ -81,7 +81,7 @@ if ($type == 'views') {
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?
ORDER BY v.mtime DESC';
if ($records = get_rows_sql($sql, array($userid), $offset, $limit)) {
if ($records = get_records_sql_array($sql, array($userid), $offset, $limit)) {
foreach ($records as &$r) {
// @todo session expandey stuff
}
......@@ -94,7 +94,7 @@ else if ($type == 'communities') {
JOIN ' . $prefix . 'usr_watchlist_community w ON w.community = c.id
WHERE w.usr = ?
ORDER BY c.mtime DESC';
$records = get_rows_sql($sql, array($userid), $offset, $limit);
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
if (empty($records)) {
......
......@@ -38,8 +38,7 @@ if ($institution || $add) {
if (!$add) {
$data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array) get_rows('institution_locked_profile_field', 'name', $institution);
$lockedprofilefields = array_map(create_function('$a', 'return $a[\'profilefield\'];'), $lockedprofilefields);
$lockedprofilefields = (array)get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
}
else {
$data = new StdClass;
......
......@@ -51,11 +51,11 @@ if ($itemid == 'new') {
$data->public = $public;
// set displayorder to be after all the existing menu items
try {
$displayorders = get_rows('site_menu', 'public', $data->public, '', 'displayorder');
$displayorders = get_records_array('site_menu', 'public', $data->public, '', 'displayorder');
$max = 0;
if ($displayorders) {
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
$max = $r->displayorder >= $max ? $r->displayorder + 1 : $max;
}
}
$data->displayorder = $max;
......
......@@ -45,20 +45,20 @@ if ($profile_data) {
}
$profilefields['email'] = array();
$profilefields['email']['all'] = get_rows('artefact_internal_profile_email', 'owner', $USER->id);
$profilefields['email']['all'] = get_records_array('artefact_internal_profile_email', 'owner', $USER->id);
$profilefields['email']['validated'] = array();
$profilefields['email']['unvalidated'] = array();
if ($profilefields['email']['all']) {
foreach ($profilefields['email']['all'] as $email) {
if ($email['verified']) {
$profilefields['email']['validated'][] = $email['email'];
if ($email->verified) {
$profilefields['email']['validated'][] = $email->email;
}
else {
$profilefields['email']['unvalidated'][] = $email['email'];
$profilefields['email']['unvalidated'][] = $email->email;
}
if ($email['principal']) {
$profilefields['email']['default'] = $email['email'];
if ($email->principal) {
$profilefields['email']['default'] = $email->email;
}
}
}
......
......@@ -37,7 +37,7 @@ $dbprefix = get_config('dbprefix');
$count = get_field('usr_group', 'COUNT(*)', 'owner', $USER->id);
$data = get_rows_sql(
$data = get_records_sql_array(
'SELECT g.id, g.name, COUNT(m.*) AS count FROM ' . $dbprefix . 'usr_group g INNER JOIN ' . $dbprefix . 'usr_group_member m ON m.grp=g.id WHERE g.owner=? GROUP BY 1, 2 ORDER BY g.name',
array($USER->id),
$offset,
......
......@@ -50,14 +50,14 @@ $offset = param_integer('offset', 0);
$data = search_user($query, $limit, $offset);
foreach ($data['results'] as &$result) {
$result['name'] = display_name($result);
$result->name = display_name($result);
unset($result['email']);
unset($result['institution']);
unset($result['username']);
unset($result['firstname']);
unset($result['lastname']);
unset($result['preferredname']);
unset($result->email);
unset($result->institution);
unset($result->username);
unset($result->firstname);
unset($result->lastname);
unset($result->preferredname);
}
print json_encode($data);
......
......@@ -62,7 +62,7 @@ log_debug('---------- cron running ' . $now . ' ----------');
foreach (plugin_types() as $plugintype) {
// get list of cron jobs to run for this plugin type
$jobs = get_rows_select(
$jobs = get_records_select_array(
$plugintype . '_cron',
'nextrun >= ? AND nextrun < ?',
array(db_format_timestamp($now - MAXRUNAGE), db_format_timestamp($now)),
......@@ -73,17 +73,17 @@ foreach (plugin_types() as $plugintype) {
if ($jobs) {
// for each cron entry
foreach ($jobs as $job) {
$classname = generate_class_name($plugintype, $job['plugin']);
$classname = generate_class_name($plugintype, $job->plugin);
log_debug("Running $classname::" . $job['callfunction']);
log_debug("Running $classname::" . $job->callfunction);
safe_require($plugintype, $job['plugin'], 'lib.php', 'require_once');
safe_require($plugintype, $job->plugin, 'lib.php', 'require_once');
call_static_method(
$classname,
$job['callfunction']
$job->callfunction
);
$nextrun = cron_next_run_time($now, $job);
$nextrun = cron_next_run_time($now, (array)$job);
// update next run time
set_field(
......@@ -99,7 +99,7 @@ foreach (plugin_types() as $plugintype) {
}
// get a list of cron jobs that should have, but didn't get run
$jobs = get_rows_select(
$jobs = get_records_select_array(
$plugintype . '_cron',
'nextrun < ? OR nextrun IS NULL',
array(db_format_timestamp($now - MAXRUNAGE)),
......@@ -110,11 +110,11 @@ foreach (plugin_types() as $plugintype) {
if ($jobs) {
// for each cron entry
foreach ($jobs as $job) {
if ($job['nextrun']) {
log_warn('cronjob "' . $job['plugin'] . '.' . $job['callfunction'] . '" didn\'t get run because the nextrun time was too old');
if ($job->nextrun) {
log_warn('cronjob "' . $job->plugin . '.' . $job->callfunction . '" didn\'t get run because the nextrun time was too old');
}
$nextrun = cron_next_run_time($now, $job);
$nextrun = cron_next_run_time($now, (array)$job);
// update next run time
set_field(
......@@ -122,43 +122,43 @@ foreach (plugin_types() as $plugintype) {
'nextrun',
db_format_timestamp($nextrun),
'plugin',
$job['plugin'],
$job->plugin,
'callfunction',
$job['callfunction']
$job->callfunction
);
}
}
}
// and now the core ones (much simpler)
if ($jobs = get_rows_select('cron', 'nextrun >= ? AND nextrun < ?',
if ($jobs = get_records_select_array('cron', 'nextrun >= ? AND nextrun < ?',
array(db_format_timestamp($now - MAXRUNAGE), db_format_timestamp($now)))) {
foreach ($jobs as $job) {
log_debug("Running core cron " . $job['callfunction']);
log_debug("Running core cron " . $job->callfunction);
$function = $job['callfunction'];
$function = $job->callfunction;
$function();
$nextrun = cron_next_run_time($now, $job);
$nextrun = cron_next_run_time($now, (array)$job);
// update next run time
set_field('cron', 'nextrun', db_format_timestamp($nextrun), 'id', $job['id']);
set_field('cron', 'nextrun', db_format_timestamp($nextrun), 'id', $job->id);
}
}
// and missed ones...
if ($jobs = get_rows_select('cron', 'nextrun < ? OR nextrun IS NULL',
if ($jobs = get_records_select_array('cron', 'nextrun < ? OR nextrun IS NULL',
array(db_format_timestamp($now - MAXRUNAGE)))) {
foreach ($jobs as $job) {
if ($job['nextrun']) {
log_warn('core cronjob "' . $job['callfunction']
if ($job->nextrun) {
log_warn('core cronjob "' . $job->callfunction
. '" didn\'t get run because the nextrun time was too old');
}
$nextrun = cron_next_run_time($now, $job);
$nextrun = cron_next_run_time($now, (array)$job);
// update next run time
set_field('cron', 'nextrun', db_format_timestamp($nextrun), 'id', $job['id']);
set_field('cron', 'nextrun', db_format_timestamp($nextrun), 'id', $job->id);
}
}
......
......@@ -371,6 +371,7 @@ function recordset_to_array($rs) {
foreach ($array as &$a) {
$a = (object)$a;
}
return $array;
}
else {
return false;
......@@ -417,7 +418,7 @@ function recordset_to_assoc($rs) {
* Get a number of records as an associative array of objects. (WARNING: this
* does not return an array, it returns an associative array keyed by the first
* column in the result set. As a result, you may lose some rows! Please use
* {@link get_rows} instead where possible)
* {@link get_records_*_array} instead where possible)
*
* If the query succeeds and returns at least one record, the
* return value is an array of objects, one object for each
......@@ -487,7 +488,7 @@ function get_records_select_assoc($table, $select='', $values=null, $sort='', $f
/**
* Get a number of records as an array of objects.
*
* Return value as for {@link get_rows}.
* Return value as for {@link get_records_array}.
*
* @param string $table the table to query.
* @param string $select A fragment of SQL to be used in a where clause in the SQL call.
......@@ -523,7 +524,7 @@ function get_records_sql_assoc($sql,$values, $limitfrom='', $limitnum='') {
/**
* Get a number of records as an array of objects.
*
* Return value as for {@link get_rows}
* Return value as for {@link get_records_array}
*
* @param string $sql the SQL select query to execute.
* @param array values of placeholders in the SQL
......
......@@ -898,14 +898,14 @@ function main_nav() {
),
);
if ($plugins = get_rows('artefact_installed')) {
if ($plugins = get_records_array('artefact_installed')) {
foreach ($plugins as &$plugin) {
safe_require('artefact', $plugin['name'], 'lib.php', 'require_once');
$plugin_menu = call_static_method(generate_class_name('artefact',$plugin['name']), 'menu_items');
safe_require('artefact', $plugin->name, 'lib.php', 'require_once');
$plugin_menu = call_static_method(generate_class_name('artefact',$plugin->name), 'menu_items');
foreach ($plugin_menu as &$menu_item) {
$menu_item['link'] = $wwwroot . 'artefact/' . $plugin['name'] . '/' . $menu_item['link'];
$menu_item['section'] = 'artefact.' . $plugin['name'];
$menu_item['link'] = $wwwroot . 'artefact/' . $plugin->name . '/' . $menu_item['link'];
$menu_item['section'] = 'artefact.' . $plugin->name;
}
$menu = array_merge($menu, $plugin_menu);
......
......@@ -37,9 +37,9 @@ function load_activity_preferences($userid) {
if (empty($userid)) {
throw new InvalidArgumentException("couldn't load activity preferences, no user id specified");
}
if ($prefs = get_rows('usr_activity_preference', 'usr', $userid)) {
if ($prefs = get_records_array('usr_activity_preference', 'usr', $userid)) {
foreach ($prefs as $p) {
$prefs[$p['activity']] = $p['method'];
$prefs[$p->activity] = $p->method;
}
}
return $prefs;
......@@ -60,9 +60,9 @@ function load_account_preferences($userid) {
if (empty($userid)) {
throw new InvalidArgumentException("couldn't load account preferences, no user id specified");
}
if ($prefs = get_rows('usr_account_preference', 'usr', $userid)) {
if ($prefs = get_records_array('usr_account_preference', 'usr', $userid)) {
foreach ($prefs as $p) {
$prefs[$p['field']] = $p['value'];
$prefs[$p->field] = $p->value;
}
}
foreach ($expectedprefs as $field => $default) {
......
......@@ -68,7 +68,7 @@ class PluginSearchInternal extends PluginSearch {
*/
public static function search_user($query_string, $limit, $offset = 0) {
if ( is_postgres() ) {
$data = get_rows_sql("
$data = get_records_sql_array("
SELECT
id, username, institution, firstname, lastname, preferredname, email
FROM
......
......@@ -45,8 +45,8 @@ $data = search_user($query, $limit, $offset);
if ($data['results']) {
foreach ($data['results'] as $key => $value) {
$data['data'][$key]['name'] = display_name($value);
$data['data'][$key]['id'] = $value['id'];
$data['data'][$key]->name = display_name($value);
$data['data'][$key]->id = $value->id;
}
}
unset($data['results']);
......
......@@ -30,7 +30,7 @@ require(dirname(dirname(__FILE__)).'/init.php');
$userid = param_integer('id','');
$profile = array();
if (!$user = @get_record('usr', 'id', $userid)) {
if (!$user = get_record('usr', 'id', $userid)) {
$name = get_string('usernotfound');
}
else {
......@@ -40,10 +40,10 @@ else {
foreach (array_keys($publicfields) as $field) {
$classname = generate_artefact_class_name($field);
if ($field == 'email') { // There may be multiple email records
if ($emails = @get_rows('artefact_internal_profile_email', 'owner', $userid)) {
if ($emails = get_records_array('artefact_internal_profile_email', 'owner', $userid)) {
foreach ($emails as $email) {
$fieldname = $email['principal'] ? 'principalemailaddress' : 'emailaddress';
$profile[] = array('name' => $fieldname, 'value' => $email['email']);
$fieldname = $email->principal ? 'principalemailaddress' : 'emailaddress';
$profile[] = array('name' => $fieldname, 'value' => $email->email);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment