diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index ae59861b95..5578b461e6 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -1,6 +1,7 @@ see only the messages of this specific user + the messages of the group (s)he is member of. - //if (!empty($user_id)) { - if (0) { - if (is_array($group_memberships) && - count($group_memberships) > 0 - ) { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND ip.c_id = announcement.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool = 'announcement' AND - ( - ip.to_user_id = $user_id OR - ip.to_group_id IS NULL OR - ip.to_group_id IN (0, ".implode(", ", $group_memberships).") - ) AND - ip.visibility IN ('1', '0') - $condition_session - $searchCondition - ORDER BY display_order DESC"; - } else { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND ip.c_id = announcement.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool ='announcement' AND - (ip.to_user_id = $user_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND - ip.visibility IN ('1', '0') - $condition_session - $searchCondition - ORDER BY display_order DESC"; - } - } elseif ($group_id != 0) { - // A.2. you are a course admin with a GROUP filter - // => see only the messages of this specific group - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool='announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.visibility<>'2' AND - (ip.to_group_id = $group_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) - $condition_session - $searchCondition - $extraGroupCondition - $groupBy - ORDER BY display_order DESC"; - } else { - // A.3 you are a course admin without any group or user filter - // A.3.a you are a course admin without user or group filter but WITH studentview - // => see all the messages of all the users and groups without editing possibilities - if (isset($isStudentView) && $isStudentView == 'true') { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool='announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.visibility='1' - $condition_session - $searchCondition - $groupBy - ORDER BY display_order DESC"; - } else { - // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view) - // => see all the messages of all the users and groups with editing possibilities - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool = 'announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - (ip.visibility='0' OR ip.visibility='1') - $condition_session - $searchCondition - $groupBy - ORDER BY display_order DESC"; - } - } - } else { - // STUDENT - if (is_array($group_memberships) && count($group_memberships) > 0) { - if ($allowUserEditSetting && !api_is_anonymous()) { - if ($group_id == 0) { - // No group - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) OR - (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) - ) - ) "; - } else { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.") - )"; - $cond_user_id .= $extraGroupCondition; - } - } else { - if ($group_id == 0) { - $cond_user_id = " AND ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) - ) "; - } else { - $cond_user_id = " AND ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.")) - )"; - $cond_user_id .= $extraGroupCondition; - } - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement INNER JOIN - $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition - AND ip.visibility='1' - $groupBy - ORDER BY display_order DESC"; - } else { - if ($user_id) { - if ($allowUserEditSetting && !api_is_anonymous()) { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".api_get_user_id()."' OR - ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id='0' OR ip.to_group_id IS NULL)) - ) "; - } else { - $cond_user_id = " AND ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition - AND ip.visibility='1' - AND announcement.session_id IN(0, ".$session_id.") - $groupBy - ORDER BY display_order DESC"; - } else { - if (($allowUserEditSetting && !api_is_anonymous())) { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL - )"; - } else { - $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL "; - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition AND - ip.visibility='1' AND - announcement.session_id IN ( 0,".api_get_session_id().") - $groupBy - "; - } - } } - if (!is_null($start) && !is_null($limit)) { - $start = intval($start); - $limit = intval($limit); - $sql .= " LIMIT $start, $limit"; - } + $result = Container::$container + ->get('chamilo_course.entity.manager.announcement_manager') + ->getAnnouncements( + api_get_user_entity($user_id), + api_get_course_entity($courseId), + api_get_group_entity($group_id), + api_get_session_entity($session_id), + api_get_course_setting('allow_user_edit_announcement') === 'true', + api_get_configuration_value('hide_base_course_announcements_in_group') === true, + $getCount, + $start, + $limit, + $titleToSearch, + $userIdToSearch ? api_get_user_entity($userIdToSearch) : null + ); - $result = Database::query($sql); if ($getCount) { - $result = Database::fetch_array($result, 'ASSOC'); - - return $result['count']; + return $result; } $iterator = 1; @@ -1806,107 +1577,107 @@ class AnnouncementManager ); } - while ($row = Database::fetch_array($result, 'ASSOC')) { - if (!in_array($row['id'], $displayed)) { - $sent_to_icon = ''; - // the email icon - if ($row['email_sent'] == '1') { - $sent_to_icon = ' '.$emailIcon; - } - $groupReference = ($row['to_group_id'] > 0) ? ' '.get_lang('Group').' ' : ''; - $title = $row['title'].$groupReference.$sent_to_icon; - $item_visibility = api_get_item_visibility( - $courseInfo, - TOOL_ANNOUNCEMENT, - $row['id'], - $session_id - ); - $row['visibility'] = $item_visibility; + for ($z = 0; $z < count($result); $z += 2) { + /** @var CAnnouncement $a */ + $a = $result[$z]; + /** @var CItemProperty $i */ + $i = $result[$z + 1]; - // show attachment list - $attachment_list = self::get_attachment($row['id']); + if (in_array($a->getId(), $displayed)) { + continue; + } - $attachment_icon = ''; - if (count($attachment_list) > 0) { - $attachment_icon = ' '.$attachmentIcon; - } + $sent_to_icon = $a->getEmailSent() ? " $emailIcon" : ''; - /* TITLE */ - $user_info = api_get_user_info($row['insert_user_id']); - $username = sprintf(get_lang("LoginX"), $user_info['username']); + $groupReference = $i->getGroup() !== null + ? ' '.get_lang('Group').' ' + : ''; + $title = $a->getTitle().$groupReference.$sent_to_icon; + $item_visibility = api_get_item_visibility($courseInfo, TOOL_ANNOUNCEMENT, $a->getId(), $sessionId); + $i->setVisibility($item_visibility); - $username_span = Display::tag( - 'span', - $user_info['complete_name'], - ['title' => $username] - ); + // show attachment list + $attachment_list = self::get_attachment($a->getId()); - $title = Display::url( - $title.$attachment_icon, - $actionUrl.'&action=view&id='.$row['id'] - ); + $attachment_icon = ''; + if (count($attachment_list) > 0) { + $attachment_icon = ' '.$attachmentIcon; + } - // we can edit if : we are the teacher OR the element belongs to - // the session we are coaching OR the option to allow users to edit is on - if (api_is_allowed_to_edit(false, true) || - (api_is_session_general_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $row['id'])) || - (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) || - ($row['to_group_id'] == $group_id && $isTutor) - ) { - $modify_icons = "".$editIcon.""; - if ($row['visibility'] == 1) { - $image_visibility = "visible"; - $alt_visibility = get_lang('Hide'); - } else { - $image_visibility = "invisible"; - $alt_visibility = get_lang('Visible'); - } - $modify_icons .= "". - Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL).""; + /* TITLE */ + $username_span = Display::tag( + 'span', + UserManager::formatUserFullName($i->getInsertUser()), + ['title' => $i->getInsertUser()->getUsername()] + ); - // DISPLAY MOVE UP COMMAND only if it is not the top announcement - if ($iterator != 1) { - $modify_icons .= "". - Display::return_icon('up.gif', get_lang('Up')).""; - } else { - $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up')); - } - if ($iterator < $bottomAnnouncement) { - $modify_icons .= "". - Display::return_icon('down.gif', get_lang('Down')).""; - } else { - $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down')); - } - if (api_is_allowed_to_edit(false, true)) { - $modify_icons .= "". - $deleteIcon.""; - } - $iterator++; + $title = Display::url( + $title.$attachment_icon, + $actionUrl.'&action=view&id='.$a->getId() + ); + + $aGroupId = $i->getGroup() ? $i->getGroup()->getId() : 0; + + // we can edit if : we are the teacher OR the element belongs to + // the session we are coaching OR the option to allow users to edit is on + if (api_is_allowed_to_edit(false, true) || + (api_is_session_general_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $a->getId())) || + (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) || + ($aGroupId == $group_id && $isTutor) + ) { + $modify_icons = "getId()."\">".$editIcon.""; + if ($i->getVisibility() == 1) { + $image_visibility = "visible"; + $alt_visibility = get_lang('Hide'); } else { - $modify_icons = Display::url( - Display::return_icon('default.png'), - $actionUrl.'&action=view&id='.$row['id'] - ); + $image_visibility = "invisible"; + $alt_visibility = get_lang('Visible'); } + $modify_icons .= "getId()."&sec_token=".$stok."\">". + Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL).""; - $announcement = [ - 'id' => $row['id'], - 'title' => $title, - 'username' => $username_span, - 'insert_date' => api_convert_and_format_date( - $row['insert_date'], - DATE_TIME_FORMAT_LONG - ), - 'lastedit_date' => api_convert_and_format_date( - $row['lastedit_date'], - DATE_TIME_FORMAT_LONG - ), - 'actions' => $modify_icons, - ]; - - $results[] = $announcement; + // DISPLAY MOVE UP COMMAND only if it is not the top announcement + if ($iterator != 1) { + $modify_icons .= "getId()."&sec_token=".$stok."\">". + Display::return_icon('up.gif', get_lang('Up')).""; + } else { + $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up')); + } + if ($iterator < $bottomAnnouncement) { + $modify_icons .= "getId()."&sec_token=".$stok."\">". + Display::return_icon('down.gif', get_lang('Down')).""; + } else { + $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down')); + } + if (api_is_allowed_to_edit(false, true)) { + $modify_icons .= "getId()."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, api_get_system_encoding()))."')) return false;\">". + $deleteIcon.""; + } + $iterator++; + } else { + $modify_icons = Display::url( + Display::return_icon('default.png'), + $actionUrl.'&action=view&id='.$a->getId() + ); } - $displayed[] = $row['id']; + + $announcement = [ + 'id' => $a->getId(), + 'title' => $title, + 'username' => $username_span, + 'insert_date' => api_convert_and_format_date( + $i->getInsertDate(), + DATE_TIME_FORMAT_LONG + ), + 'lastedit_date' => api_convert_and_format_date( + $i->getLasteditDate(), + DATE_TIME_FORMAT_LONG + ), + 'actions' => $modify_icons, + ]; + + $results[] = $announcement; + $displayed[] = $a->getId(); } return $results; diff --git a/src/ApiBundle/GraphQL/Resolver/CourseAnnouncementResolver.php b/src/ApiBundle/GraphQL/Resolver/CourseAnnouncementResolver.php new file mode 100644 index 0000000000..2c12aa5c50 --- /dev/null +++ b/src/ApiBundle/GraphQL/Resolver/CourseAnnouncementResolver.php @@ -0,0 +1,88 @@ +fieldName); + + if (method_exists($this, $method)) { + return $this->$method($announcement, $itemProperty, $args, $context); + } + + $method = 'get'.ucfirst($info->fieldName); + + if (method_exists($announcement, $method)) { + return $announcement->$method(); + } + + if (method_exists($itemProperty, $method)) { + return $itemProperty->$method(); + } + + return null; + } + + /** + * @param CAnnouncement $announcement + * + * @return int + */ + public function resolveId(CAnnouncement $announcement) + { + return $announcement->getIid(); + } + + /** + * @param CAnnouncement $announcement + * @param CItemProperty $itemProperty + * + * @return User + */ + public function resolveBy(CAnnouncement $announcement, CItemProperty $itemProperty) + { + return $itemProperty->getInsertUser(); + } + + /** + * @param CAnnouncement $announcement + * @param CItemProperty $itemProperty + * + * @return \DateTime + */ + public function resolveLastUpdateDate(CAnnouncement $announcement, CItemProperty $itemProperty) + { + return $itemProperty->getLasteditDate(); + } +} \ No newline at end of file diff --git a/src/ApiBundle/GraphQL/Resolver/CourseResolver.php b/src/ApiBundle/GraphQL/Resolver/CourseResolver.php index e426fd127c..f90c4a3443 100644 --- a/src/ApiBundle/GraphQL/Resolver/CourseResolver.php +++ b/src/ApiBundle/GraphQL/Resolver/CourseResolver.php @@ -113,6 +113,7 @@ class CourseResolver implements ResolverInterface, ContainerAwareInterface $tools = array_filter($tools, function ($tool) { switch ($tool['name']) { case TOOL_COURSE_DESCRIPTION: + case TOOL_ANNOUNCEMENT: return true; default: return false; diff --git a/src/ApiBundle/GraphQL/Resolver/CourseToolResolver.php b/src/ApiBundle/GraphQL/Resolver/CourseToolResolver.php index c71395e355..5dab76a8c0 100644 --- a/src/ApiBundle/GraphQL/Resolver/CourseToolResolver.php +++ b/src/ApiBundle/GraphQL/Resolver/CourseToolResolver.php @@ -52,6 +52,8 @@ class CourseToolResolver implements ResolverInterface, ContainerAwareInterface switch ($tool->getName()) { case TOOL_COURSE_DESCRIPTION: return $this->typeResolver->resolve('ToolDescription'); + case TOOL_ANNOUNCEMENT: + return $this->typeResolver->resolve('ToolAnnouncements'); } } } diff --git a/src/ApiBundle/GraphQL/Resolver/ToolAnnouncementsResolver.php b/src/ApiBundle/GraphQL/Resolver/ToolAnnouncementsResolver.php new file mode 100644 index 0000000000..309c63c5c9 --- /dev/null +++ b/src/ApiBundle/GraphQL/Resolver/ToolAnnouncementsResolver.php @@ -0,0 +1,74 @@ +offsetGet('course'); + /** @var Session $session */ + $session = null; + + if ($context->offsetExists('session')) { + $session = $context->offsetGet('session'); + } + + $em = $this->container->get('chamilo_course.entity.manager.announcement_manager'); + + try { + $announcementsInfo = $em->getAnnouncements( + $this->getCurrentUser(), + $course, + null, + $session, + api_get_course_setting('allow_user_edit_announcement') === 'true', + api_get_configuration_value('hide_base_course_announcements_in_group') === true + ); + } catch (\Exception $exception) { + throw new UserError($exception->getMessage()); + } + + if (empty($announcementsInfo)) { + return []; + } + + $announcements = []; + + for ($z = 0; $z < count($announcementsInfo); $z += 2) { + $announcements[] = [ + 'announcement' => $announcementsInfo[$z], + 'item_property' => $announcementsInfo[$z + 1], + ]; + } + + return $announcements; + } +} \ No newline at end of file diff --git a/src/ApiBundle/GraphQL/Resources/config/Query.types.yaml b/src/ApiBundle/GraphQL/Resources/config/Query.types.yaml index 629bd54bc9..b9e0c47c3a 100644 --- a/src/ApiBundle/GraphQL/Resources/config/Query.types.yaml +++ b/src/ApiBundle/GraphQL/Resources/config/Query.types.yaml @@ -241,3 +241,40 @@ CourseDescription: type: 'String' type: type: 'Int' + +ToolAnnouncements: + type: object + config: + description: 'Announcements related to the course.' + interfaces: [CourseTool] + resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\ToolAnnouncementsResolver", [value, args, info, context])' + fields: + name: + type: 'String' + category: + type: 'String' + image: + type: 'String' + customIcon: + type: 'String' + isVisible: + type: 'Boolean' + announcements: + type: '[CourseAnnouncement]!' + +CourseAnnouncement: + type: object + config: + description: 'Course announcement.' + resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\CourseAnnouncementResolver", [value, args, info, context])' + fields: + id: + type: 'Int' + title: + type: 'String' + content: + type: 'String' + by: + type: 'User' + lastUpdateDate: + type: 'DateTime' diff --git a/src/CourseBundle/Entity/Manager/AnnouncementManager.php b/src/CourseBundle/Entity/Manager/AnnouncementManager.php new file mode 100644 index 0000000000..25d0ecd73b --- /dev/null +++ b/src/CourseBundle/Entity/Manager/AnnouncementManager.php @@ -0,0 +1,190 @@ +getId() : 0; + + $conditionSession = api_get_session_condition( + $sessionId, + true, + true, + 'announcement.sessionId' + ); + + $select = 'DISTINCT announcement, ip'; + $groupBy = 'GROUP BY announcement.iid'; + + if ($getCount) { + $groupBy = ''; + $select = 'COUNT(DISTINCT announcement) AS count'; + } + + $parameters = []; + $searchCondition = ''; + + if (!empty($titleToSearch)) { + $parameters['search_title'] = "%$titleToSearch%"; + $searchCondition .= " AND (title LIKE :search_title) "; + } + + if (!empty($userToSearch)) { + $searchCondition .= " AND (ip.insertUser = ".$userToSearch->getId().") "; + } + + $extraGroupCondition = ''; + + if ($allowOnlyGroup) { + $extraGroupCondition = ' AND ip.group = '.$group->getId().' '; + } + + if (api_is_allowed_to_edit(false, true) + || ($allowUserEditSetting && !api_is_anonymous()) + ) { + $dqlCondition = "AND (ip.visibility = 0 OR ip.visibility = 1)"; + + if (!empty($group)) { + $dqlCondition = "AND ip.visibility != 2 AND + (ip.group = ".$group->getId()." OR ip.group IS NULL ) + $extraGroupCondition"; + } + } else { + $groupMemberships = \GroupManager::get_group_ids( + $course->getId(), + $user->getId() + ); + + if (is_array($groupMemberships) && count($groupMemberships) > 0) { + if ($allowUserEditSetting && !api_is_anonymous()) { + $condUserId = " AND ( + ip.lasteditUserId = ".$user->getId()." OR( + (ip.toUser = ".$user->getId()." OR ip.toUser IS NULL) OR + (ip.group IS NULL OR ip.group IN (0, ".implode(', ', $groupMemberships).")) + ) + ) "; + + if (!empty($group)) { + $condUserId = " AND ( + ip.lasteditUserId = ".$user->getId()." OR ip.group IS NULL OR ip.group IN (0, ".$group->getId() + .") + ) ".$extraGroupCondition; + } + } else { + $condUserId = " AND ( + (ip.toUser = ".$user->getId().") OR ip.toUser IS NULL) AND + (ip.group IS NULL OR ip.group IN (0, ".implode(', ', $groupMemberships).")) + ) "; + + if (!empty($group)) { + $condUserId = " AND ( + (ip.toUser = ".$user->getId().") OR ip.toUser IS NULL) AND + (ip.group IS NULL OR ip.group IN (0, ".$group->getId().")) + ) ".$extraGroupCondition; + } + } + + $dqlCondition = "$condUserId AND ip.visibility = 1"; + } else { + if (!empty($user->getId())) { + $condUserId = " AND ( + (ip.toUser = ".$user->getId()." OR ip.toUser IS NULL) AND + (ip.group = 0 OR ip.group IS NULL) + ) "; + + if ($allowUserEditSetting && !api_is_anonymous()) { + $condUserId = " AND ( + ip.lasteditUserId = ".$user->getId()." OR + ( + (ip.toUser = ".$user->getId()." OR ip.toUser IS NULL) AND + (ip.group = 0 OR ip.group IS NULL) + ) + ) "; + } + + $dqlCondition = "$condUserId + AND ip.visibility = 1 + AND announcement.sessionId IN (0, $sessionId)"; + } else { + $condUserId = " AND ip.group = 0 OR ip.group IS NULL "; + + if ($allowUserEditSetting && !api_is_anonymous()) { + $condUserId = " AND ( + ip.lastEditUserId = ".$user->getId()." OR ip.group = 0 OR ip.group IS NULL + ) "; + } + + $dqlCondition = "$condUserId + AND ip.visibility = 1 + AND announcement.sessionId IN (0, $sessionId)"; + } + } + } + + $dql = "SELECT $select + FROM ChamiloCourseBundle:CAnnouncement announcement + INNER JOIN ChamiloCourseBundle:CItemProperty AS ip + WITH (announcement.id = ip.ref AND announcement.cId = ip.course) + WHERE + ip.tool = 'announcement' AND + announcement.cId = ".$course->getId()." + $dqlCondition + $conditionSession + $searchCondition + $groupBy + ORDER BY announcement.displayOrder DESC"; + + $query = $this->getEntityManager() + ->createQuery($dql) + ->setParameters($parameters); + + if (!is_null($start) && !is_null($limit)) { + $query + ->setFirstResult($start) + ->setMaxResults($limit); + } + + if ($getCount) { + return $query->getResult(); + } + + return $query->getResult(); + } +} diff --git a/src/CourseBundle/Resources/config/services.yml b/src/CourseBundle/Resources/config/services.yml index cee1d6b4d6..10a5e5e457 100644 --- a/src/CourseBundle/Resources/config/services.yml +++ b/src/CourseBundle/Resources/config/services.yml @@ -5,7 +5,9 @@ parameters: chamilo_course.settings.manager.class: Chamilo\CourseBundle\Manager\SettingsManager chamilo_course.settings.schema_registry.class: Sylius\Component\Registry\ServiceRegistry chamilo_course.entity.manager.group_manager.class: Chamilo\CourseBundle\Entity\Manager\GroupManager + chamilo_course.entity.manager.announcement_manager.class: Chamilo\CourseBundle\Entity\Manager\AnnouncementManager chamilo_course.entity.group: Chamilo\CourseBundle\Entity\CGroupInfo + chamilo_course.entity.announcement: Chamilo\CourseBundle\Entity\CAnnouncement services: # Managers @@ -13,6 +15,10 @@ services: class: '%chamilo_course.entity.manager.group_manager.class%' arguments: ['%chamilo_course.entity.group%', '@doctrine'] + chamilo_course.entity.manager.announcement_manager: + class: '%chamilo_course.entity.manager.announcement_manager.class%' + arguments: ['%chamilo_course.entity.announcement%', '@doctrine'] + # Event Listeners chamilo_course.listener.course: class: Chamilo\CourseBundle\EventListener\CourseListener