Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Added PostgreSQL compatibility #259

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions classes/repos/notification_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public static function get_notification_for_course_user_or_null($notification_id
return $notification;
}

private static function get_all_for_course_sql($course_id, $user_id = null, $sort_by, $sort_dir, $as_count = false)
private static function get_all_for_course_sql($course_id, $user_id = null, $sort_by = null, $sort_dir, $as_count = false)
{
$sql = $as_count
? 'SELECT COUNT(DISTINCT n.id) '
? 'SELECT COUNT(res.id) FROM (select DISTINCT id' . ($sort_by? ','.$sort_by:'')
: 'SELECT DISTINCT n.* ';

$sql .= 'FROM {block_quickmail_notifs} n
Expand All @@ -143,8 +143,11 @@ private static function get_all_for_course_sql($course_id, $user_id = null, $sor
$sql .= ' AND n.user_id = :user_id';
}

$sql .= ' AND n.timedeleted = 0
ORDER BY ' . $sort_by . ' ' . $sort_dir;
$sql .= ' AND n.timedeleted = 0 ORDER BY ' . $sort_by . ' ' . $sort_dir;

$sql .= $as_count
? ') as res '
: '';

return $sql;
}
Expand Down
34 changes: 20 additions & 14 deletions classes/repos/queued_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,31 @@ public static function get_for_user($user_id, $course_id = 0, $params = [])
return $repo->result;
}

private static function get_for_user_sql($course_id, $sort_by, $sort_dir, $as_count = false)
{
$sql = $as_count
? 'SELECT COUNT(DISTINCT m.id) '
: 'SELECT DISTINCT m.* ';
private static function get_for_user_sql($course_id, $sort_by = null, $sort_dir, $as_count = false)
{


$sql = $as_count
? 'SELECT COUNT(res.id) FROM (select DISTINCT id' . ($sort_by? ','.$sort_by:'')
: 'SELECT DISTINCT m.* ';

$sql .= 'FROM {block_quickmail_messages} m
$sql .= ' FROM {block_quickmail_messages} m
WHERE m.user_id = :user_id';

if ($course_id) {
$sql .= ' AND m.course_id = :course_id';
}

$sql .= ' AND m.to_send_at <> 0 AND m.timedeleted = 0 AND m.sent_at = 0 AND m.is_draft = 0 ORDER BY ' . $sort_by . ' ' . $sort_dir;
if ($course_id) {
$sql .= ' AND m.course_id = :course_id';
}

return $sql;
}
$sql .= ' AND m.to_send_at <> 0 AND m.timedeleted = 0 AND m.sent_at = 0 AND m.is_draft = 0 ORDER BY ' . $sort_by . ' ' . $sort_dir;

/**
$sql .= $as_count
? ') as res '
: '';

return $sql;
}

/**
* Returns an array of all messages that should be sent by the system right now
*
* @return array
Expand Down
12 changes: 8 additions & 4 deletions classes/repos/sent_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,25 @@ public static function get_for_user($user_id, $course_id = 0, $params = [])
return $repo->result;
}

private static function get_for_user_sql($course_id, $sort_by, $sort_dir, $as_count = false)
private static function get_for_user_sql($course_id, $sort_by = null, $sort_dir, $as_count = false)
{
$sql = $as_count
? 'SELECT COUNT(DISTINCT m.id) '
? 'SELECT COUNT(res.id) FROM (select DISTINCT id' . ($sort_by? ','.$sort_by:'')
: 'SELECT DISTINCT m.* ';

$sql .= 'FROM {block_quickmail_messages} m
$sql .= ' FROM {block_quickmail_messages} m
WHERE m.user_id = :user_id';

if ($course_id) {
$sql .= ' AND m.course_id = :course_id';
}

$sql .= ' AND m.is_draft = 0 AND m.timedeleted = 0 AND m.sent_at > 0 ORDER BY ' . $sort_by . ' ' . $sort_dir;

$sql .= $as_count
? ') as res '
: '';

return $sql;
}

Expand Down