Announcements, use resources [WIP]

pull/3064/head
Julio 5 years ago
parent 5e8c0661c3
commit 79ef87a1e4
  1. 35
      public/main/inc/lib/AnnouncementManager.php

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\ExtraField as ExtraFieldEntity; use Chamilo\CoreBundle\Entity\ExtraField as ExtraFieldEntity;
@ -13,8 +14,6 @@ use Chamilo\CourseBundle\Entity\CItemProperty;
* *
* @author jmontoya * @author jmontoya
* *
* @package chamilo.announcements
*
* @todo use OOP * @todo use OOP
*/ */
class AnnouncementManager class AnnouncementManager
@ -321,7 +320,7 @@ class AnnouncementManager
* @param int $userId * @param int $userId
* @param int $groupId * @param int $groupId
* *
* @return array * @return CAnnouncement
*/ */
public static function getAnnouncementInfoById( public static function getAnnouncementInfoById(
$announcementId, $announcementId,
@ -330,6 +329,10 @@ class AnnouncementManager
$groupId = 0 $groupId = 0
) { ) {
$announcementId = (int) $announcementId; $announcementId = (int) $announcementId;
$repo = Container::getAnnouncementRepository();
return $repo->find($announcementId);
$courseId = (int) $courseId; $courseId = (int) $courseId;
$userId = (int) $userId; $userId = (int) $userId;
$groupId = (int) $groupId; $groupId = (int) $groupId;
@ -425,26 +428,18 @@ class AnnouncementManager
return ''; return '';
} }
global $charset;
$html = ''; $html = '';
$result = self::getAnnouncementInfoById( $course = api_get_course_entity(api_get_course_int_id());
$session = api_get_session_entity(api_get_session_id());
$announcement = self::getAnnouncementInfoById(
$id, $id,
api_get_course_int_id(), api_get_course_int_id(),
api_get_user_id(), api_get_user_id(),
api_get_group_id() api_get_group_id()
); );
if (empty($result)) { if (empty($announcement)) {
return '';
}
/** @var CAnnouncement $announcement */
$announcement = $result['announcement'];
/** @var CItemProperty $itemProperty */
$itemProperty = $result['item_property'];
if (empty($announcement) || empty($itemProperty)) {
return ''; return '';
} }
@ -462,7 +457,7 @@ class AnnouncementManager
$image_visibility = 'invisible'; $image_visibility = 'invisible';
$alt_visibility = get_lang('Visible'); $alt_visibility = get_lang('Visible');
if ($itemProperty->getVisibility() === 1) { if ($announcement->isVisible($course, $session)) {
$image_visibility = 'visible'; $image_visibility = 'visible';
$alt_visibility = get_lang('Hide'); $alt_visibility = get_lang('Hide');
} }
@ -471,7 +466,7 @@ class AnnouncementManager
Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL)."</a>"; Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL)."</a>";
if (api_is_allowed_to_edit(false, true)) { if (api_is_allowed_to_edit(false, true)) {
$modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete&id=".$id."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES, $charset))."')) return false;\">". $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete&id=".$id."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."')) return false;\">".
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL). Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
"</a>"; "</a>";
} }
@ -490,7 +485,7 @@ class AnnouncementManager
$html .= "<tr><td>$content</td></tr>"; $html .= "<tr><td>$content</td></tr>";
$html .= "<tr>"; $html .= "<tr>";
$html .= "<td class=\"announcements_datum\">".get_lang('Latest update')." : "; $html .= "<td class=\"announcements_datum\">".get_lang('Latest update')." : ";
$lastEdit = $itemProperty->getLasteditDate(); $lastEdit = $announcement->getResourceNode()->getUpdatedAt();
$html .= Display::dateToStringAgoAndLongDate($lastEdit); $html .= Display::dateToStringAgoAndLongDate($lastEdit);
$html .= "</td></tr>"; $html .= "</td></tr>";
@ -1311,6 +1306,8 @@ class AnnouncementManager
*/ */
public static function sent_to($tool, $id) public static function sent_to($tool, $id)
{ {
return [];
$table = Database::get_course_table(TABLE_ITEM_PROPERTY); $table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tool = Database::escape_string($tool); $tool = Database::escape_string($tool);
$id = (int) $id; $id = (int) $id;

Loading…
Cancel
Save