Internal: Refactor announcement CRUD

pull/3466/head
Julio Montoya 4 years ago
parent a638fef9aa
commit fa08e8cccb
  1. 3
      public/main/announcements/announcements.php
  2. 5
      public/main/inc/lib/AnnouncementEmail.php
  3. 20
      public/main/inc/lib/AnnouncementManager.php
  4. 16
      public/main/inc/lib/display.lib.php

@ -798,6 +798,7 @@ if (($allowToEdit || $allowStudentInGroupToSend) && (empty($_GET['origin']) || '
}
}
/*
if ($allowToEdit && 0 == api_get_group_id()) {
$allow = api_get_configuration_value('disable_delete_all_announcements');
if (false === $allow && api_is_allowed_to_edit()) {
@ -813,7 +814,7 @@ if ($allowToEdit && 0 == api_get_group_id()) {
).'</a>';
}
}
}
}*/
if ($show_actions) {
echo Display::toolbarAction('toolbar', [$actionsLeft, $searchFormToString]);

@ -359,14 +359,11 @@ class AnnouncementEmail
public function logMailSent()
{
$id = $this->announcement->getIid();
$courseId = $this->course['real_id'];
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
$sql = "UPDATE $table SET
email_sent = 1
WHERE
c_id = $courseId AND
id = $id AND
session_id = {$this->session_id}
iid = $id
";
Database::query($sql);
}

@ -264,11 +264,7 @@ class AnnouncementManager
public static function delete_announcement($courseInfo, $id)
{
$repo = Container::getAnnouncementRepository();
$criteria = [
'cId' => $courseInfo['real_id'],
'id' => $id,
];
$announcement = $repo->findOneBy($criteria);
$announcement = $repo->find($id);
if ($announcement) {
$repo->getEntityManager()->remove($announcement);
$repo->getEntityManager()->flush();
@ -586,6 +582,7 @@ class AnnouncementManager
if (!isset($courseInfo['real_id'])) {
return false;
}
return false;
$courseId = $courseInfo['real_id'];
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
@ -1065,14 +1062,10 @@ class AnnouncementManager
public static function update_mail_sent($insert_id)
{
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
if ($insert_id != strval(intval($insert_id))) {
return false;
}
$insert_id = intval($insert_id);
$courseId = api_get_course_int_id();
// store the modifications in the table tbl_annoucement
$sql = "UPDATE $table SET email_sent='1'
WHERE c_id = $courseId AND id = $insert_id";
WHERE iid = $insert_id";
Database::query($sql);
}
@ -1368,11 +1361,10 @@ class AnnouncementManager
{
$table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$announcementId = (int) $announcementId;
$courseId = api_get_course_int_id();
$row = [];
$sql = 'SELECT id, path, filename, comment
$sql = 'SELECT iid, path, filename, comment
FROM '.$table.'
WHERE c_id = '.$courseId.' AND announcement_id = '.$announcementId;
WHERE announcement_id = '.$announcementId;
$result = Database::query($sql);
$repo = Container::getAnnouncementAttachmentRepository();
if (0 != Database::num_rows($result)) {
@ -1507,7 +1499,7 @@ class AnnouncementManager
comment = '$safe_file_comment',
path = '$safe_new_file_name',
size ='".intval($file['size'])."'
WHERE c_id = $courseId AND id = '$id_attach'";
WHERE iid = '$id_attach'";
$result = Database::query($sql);
if (false === $result) {
$return = -1;

@ -1961,25 +1961,25 @@ class Display
*
* @return string|null
*/
public static function badge($count, $type = "warning")
public static function badge($count, $type = 'warning')
{
$class = '';
switch ($type) {
case 'success':
$class = 'badge-success';
$class = 'bg-success';
break;
case 'warning':
$class = 'badge-warning';
$class = 'bg-warning text-dark';
break;
case 'important':
$class = 'badge-important';
$class = 'bg-important';
break;
case 'info':
$class = 'badge-info';
$class = 'bg-info';
break;
case 'inverse':
$class = 'badge-inverse';
$class = 'bg-inverse';
break;
}
@ -2019,7 +2019,7 @@ class Display
$class = 'success';
break;
case 'warning':
$class = 'warning';
$class = 'warning text-dark';
break;
case 'important':
case 'danger':
@ -2038,7 +2038,7 @@ class Display
$html = '';
if (!empty($content)) {
$html = '<span class="badge badge-'.$class.'">';
$html = '<span class="badge bg-'.$class.'">';
$html .= $content;
$html .= '</span>';
}

Loading…
Cancel
Save