Add agenda events using resources

Lib beberlei/doctrineextensions added to use mysql date functions:
YEAR, MONTH, etc.
pull/3064/head
Julio 6 years ago
parent ad6737a786
commit e7997eae5c
  1. 3
      composer.json
  2. 10
      config/packages/doctrine.yaml
  3. 12
      public/main/calendar/agenda_list.php
  4. 18
      public/main/inc/ajax/agenda.ajax.php
  5. 1
      public/main/inc/ajax/model.ajax.php
  6. 456
      public/main/inc/lib/agenda.lib.php
  7. 7
      public/main/inc/lib/internationalization.lib.php
  8. 54
      src/CoreBundle/Repository/ResourceRepository.php
  9. 2
      src/CourseBundle/Entity/CCalendarEvent.php

@ -160,7 +160,8 @@
"maennchen/zipstream-php": "^1.2", "maennchen/zipstream-php": "^1.2",
"league/glide-symfony": "^1.0", "league/glide-symfony": "^1.0",
"cocur/slugify": "^3.2", "cocur/slugify": "^3.2",
"knpuniversity/oauth2-client-bundle": "^1.31" "knpuniversity/oauth2-client-bundle": "^1.31",
"beberlei/doctrineextensions": "^1.2"
}, },
"config": { "config": {
"component-dir": "public/assets" "component-dir": "public/assets"

@ -22,12 +22,6 @@ doctrine:
mappings: mappings:
SonataUserBundle: ~ SonataUserBundle: ~
FOSUserBundle: ~ FOSUserBundle: ~
# App:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/Entity'
# prefix: 'App\Entity'
# alias: App
gedmo_translatable: gedmo_translatable:
type: annotation type: annotation
prefix: ChamiloCore\Entity\Translation prefix: ChamiloCore\Entity\Translation
@ -53,3 +47,7 @@ doctrine:
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity" dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # (optional) it will default to the name set for the mapping alias: GedmoTree # (optional) it will default to the name set for the mapping
is_bundle: false is_bundle: false
dql:
string_functions:
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year

@ -1,22 +1,18 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* @package chamilo.calendar
*/
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'calendar_list'; $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'calendar_list';
$logInfo = [ $logInfo = [
'tool' => TOOL_CALENDAR_EVENT, 'tool' => TOOL_CALENDAR_EVENT,
'tool_id' => 0,
'tool_id_detail' => 0,
'action' => $action, 'action' => $action,
]; ];
Event::registerLog($logInfo); Event::registerLog($logInfo);
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $type = $_REQUEST['type'] ?? null;
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type='.Security::remove_XSS($type), 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type='.Security::remove_XSS($type),
@ -93,11 +89,11 @@ $tpl->assign('agenda_actions', $actions);
$tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit()); $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
if ($action == 'change_visibility') { if ($action === 'change_visibility') {
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$courseCondition = ''; $courseCondition = '';
// This happens when list agenda is not inside a course // This happens when list agenda is not inside a course
if (($type == 'course' || $type == 'session' && !empty($courseInfo))) { if (($type === 'course' || $type === 'session' && !empty($courseInfo))) {
// For course and session event types // For course and session event types
// Just needs course ID // Just needs course ID
$agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo); $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
@ -6,7 +7,7 @@
*/ */
$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], ['personal', 'course', 'admin']) ? $_REQUEST['type'] : 'personal'; $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], ['personal', 'course', 'admin']) ? $_REQUEST['type'] : 'personal';
if ($type == 'personal') { if ($type === 'personal') {
$cidReset = true; // fixes #5162 $cidReset = true; // fixes #5162
} }
@ -15,16 +16,13 @@ require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$group_id = api_get_group_id(); $group_id = api_get_group_id();
if ($type == 'course') { if ($type === 'course') {
api_protect_course_script(true); api_protect_course_script(true);
} }
$logInfo = [ $logInfo = [
'tool' => TOOL_CALENDAR_EVENT, 'tool' => TOOL_CALENDAR_EVENT,
'tool_id' => 0,
'tool_id_detail' => 0,
'action' => $action, 'action' => $action,
'info' => '',
]; ];
Event::registerLog($logInfo); Event::registerLog($logInfo);
@ -37,11 +35,11 @@ switch ($action) {
if (!$agenda->getIsAllowedToEdit()) { if (!$agenda->getIsAllowedToEdit()) {
break; break;
} }
$add_as_announcement = isset($_REQUEST['add_as_annonuncement']) ? $_REQUEST['add_as_annonuncement'] : null; $add_as_announcement = $_REQUEST['add_as_annonuncement'] ?? null;
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : null; $title = $_REQUEST['title'] ?? null;
$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null; $content = $_REQUEST['content'] ?? null;
$comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null; $comment = $_REQUEST['comment'] ?? null;
$userToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : []; $userToSend = $_REQUEST['users_to_send'] ?? [];
echo $agenda->addEvent( echo $agenda->addEvent(
$_REQUEST['start'], $_REQUEST['start'],

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use ChamiloSession as Session; use ChamiloSession as Session;

@ -255,7 +255,7 @@ class Agenda
$end = api_get_utc_datetime($end, false, true); $end = api_get_utc_datetime($end, false, true);
$allDay = isset($allDay) && $allDay === 'true' ? 1 : 0; $allDay = isset($allDay) && $allDay === 'true' ? 1 : 0;
$id = null; $id = null;
//$user = api_get_user_entity(api_get_user_id());
$em = Database::getManager(); $em = Database::getManager();
switch ($this->type) { switch ($this->type) {
case 'personal': case 'personal':
@ -396,7 +396,7 @@ class Agenda
$courseEntity, $courseEntity,
$sessionEntity, $sessionEntity,
$groupEntity, $groupEntity,
api_get_user_entity($userId) api_get_user_entity($userId)
); );
/*api_item_property_update( /*api_item_property_update(
$this->course, $this->course,
@ -530,8 +530,6 @@ class Agenda
$interval = 'P1M'; $interval = 'P1M';
break; break;
case 'monthlyByDay': case 'monthlyByDay':
// not yet implemented
break;
case 'monthlyByDayR': case 'monthlyByDayR':
// not yet implemented // not yet implemented
break; break;
@ -564,7 +562,6 @@ class Agenda
// @todo remove comment code // @todo remove comment code
$startDateInLocal = new DateTime($newStartDate, new DateTimeZone($timeZone)); $startDateInLocal = new DateTime($newStartDate, new DateTimeZone($timeZone));
//$originalOffset = $startDate->getOffset();
if ($startDateInLocal->format('I') == 0) { if ($startDateInLocal->format('I') == 0) {
// Is saving time? Then fix UTC time to add time // Is saving time? Then fix UTC time to add time
$seconds = $startDateInLocal->getOffset(); $seconds = $startDateInLocal->getOffset();
@ -572,16 +569,9 @@ class Agenda
$startDateFixed = $startDate->format('Y-m-d H:i:s'); $startDateFixed = $startDate->format('Y-m-d H:i:s');
$startDateInLocalFixed = new DateTime($startDateFixed, new DateTimeZone($timeZone)); $startDateInLocalFixed = new DateTime($startDateFixed, new DateTimeZone($timeZone));
$newStartDate = $startDateInLocalFixed->format('Y-m-d H:i:s'); $newStartDate = $startDateInLocalFixed->format('Y-m-d H:i:s');
} else {
/*$seconds = $startDateInLocal->getOffset();
$startDate->add(new DateInterval("PT".$seconds."S"));
$startDateFixed = $startDate->format('Y-m-d H:i:s');
$startDateInLocalFixed = new DateTime($startDateFixed, new DateTimeZone($timeZone));
$newStartDate = $startDateInLocalFixed->format('Y-m-d H:i:s');*/
} }
//var_dump($newStartDate.' - '.$startDateInLocal->format('I'));
$endDateInLocal = new DateTime($newEndDate, new DateTimeZone($timeZone));
$endDateInLocal = new DateTime($newEndDate, new DateTimeZone($timeZone));
if ($endDateInLocal->format('I') == 0) { if ($endDateInLocal->format('I') == 0) {
// Is saving time? Then fix UTC time to add time // Is saving time? Then fix UTC time to add time
$seconds = $endDateInLocal->getOffset(); $seconds = $endDateInLocal->getOffset();
@ -700,13 +690,8 @@ class Agenda
$table_agenda = Database::get_course_table(TABLE_AGENDA); $table_agenda = Database::get_course_table(TABLE_AGENDA);
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
// Check params
if (empty($item_id) || $item_id != strval(intval($item_id))) {
return -1;
}
// Get the agenda item. // Get the agenda item.
$item_id = intval($item_id); $item_id = (int) $item_id;
$sql = "SELECT * FROM $table_agenda $sql = "SELECT * FROM $table_agenda
WHERE c_id = $courseId AND id = ".$item_id; WHERE c_id = $courseId AND id = ".$item_id;
$res = Database::query($sql); $res = Database::query($sql);
@ -977,7 +962,6 @@ class Agenda
if (!empty($groupsToDelete)) { if (!empty($groupsToDelete)) {
foreach ($groupsToDelete as $group) { foreach ($groupsToDelete as $group) {
$groupIidItem = 0; $groupIidItem = 0;
$groupInfoItem = [];
if ($group) { if ($group) {
$groupInfoItem = GroupManager::get_group_properties( $groupInfoItem = GroupManager::get_group_properties(
$group $group
@ -1633,7 +1617,6 @@ class Agenda
} }
// Add plugin personal events // Add plugin personal events
$this->plugin = new AppPlugin(); $this->plugin = new AppPlugin();
$plugins = $this->plugin->getInstalledPluginListObject(); $plugins = $this->plugin->getInstalledPluginListObject();
/** @var Plugin $plugin */ /** @var Plugin $plugin */
@ -1773,8 +1756,11 @@ class Agenda
$user_id = 0, $user_id = 0,
$color = '' $color = ''
) { ) {
$start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null; $start = (int) $start;
$end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null; $end = (int) $end;
$start = !empty($start) ? api_get_utc_datetime($start) : null;
$end = !empty($end) ? api_get_utc_datetime($end) : null;
if (empty($courseInfo)) { if (empty($courseInfo)) {
return []; return [];
@ -1841,83 +1827,132 @@ class Agenda
} }
} }
$tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); $repo = Container::getCalendarEventRepository();
$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $courseEntity = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
if (empty($sessionId)) { $qb = $repo->getResourcesByCourseOnly($courseEntity, $courseEntity->getResourceNode());
$sessionCondition = " $userCondition = '';
(
agenda.session_id = 0 AND (ip.session_id IS NULL OR ip.session_id = 0)
) ";
} else {
$sessionCondition = "
(
agenda.session_id = $sessionId AND
ip.session_id = $sessionId
) ";
}
if ($isAllowToEdit) { if ($isAllowToEdit) {
// No group filter was asked // No group filter was asked
if (empty($groupId)) { if (empty($groupId)) {
if (empty($user_id)) { if (empty($user_id)) {
// Show all events not added in group // Show all events not added in group
$userCondition = ' (ip.to_group_id IS NULL OR ip.to_group_id = 0) '; $userCondition = ' (links.group IS NULL) ';
// admin see only his stuff // admin see only his stuff
if ($this->type === 'personal') { if ($this->type === 'personal') {
$userCondition = " (ip.to_user_id = ".api_get_user_id()." AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) ) "; $userCondition = " (links.user = ".api_get_user_id()." AND (links.group IS NULL) ";
$userCondition .= " OR ( (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) ) "; //$userCondition = " (ip.to_user_id = ".api_get_user_id()." AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) ) ";
$userCondition .= " OR ( (links.user IS NULL) AND (links.group IS NULL ))) ";
//$userCondition .= " OR ( (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) ) ";
} }
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
// Show events sent to selected groups // Show events sent to selected groups
$userCondition .= " OR (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition .= " OR (links.user IS NULL) AND (links.group IN (".implode(", ", $groupMemberships).")) ";
} }
} else { } else {
// Show events of requested user in no group // Show events of requested user in no group
$userCondition = " (ip.to_user_id = $user_id AND (ip.to_group_id IS NULL OR ip.to_group_id = 0)) "; $userCondition = " (links.user = $user_id AND links.group IS NULL) ";
// Show events sent to selected groups // Show events sent to selected groups
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
$userCondition .= " OR (ip.to_user_id = $user_id) AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition .= " OR (links.user = $user_id) AND (links.group IN (".implode(", ", $groupMemberships).")) ";
} }
} }
} else { } else {
// Show only selected groups (depending of user status) // Show only selected groups (depending of user status)
$userCondition = " (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition = " (links.user is NULL) AND (links.group IN (".implode(", ", $groupMemberships).")) ";
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
// Show send to $user_id in selected groups // Show send to $user_id in selected groups
$userCondition .= " OR (ip.to_user_id = $user_id) AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition .= " OR (links.user = $user_id) AND (links.group IN (".implode(", ", $groupMemberships).")) ";
} }
} }
} else { } else {
// No group filter was asked // No group filter was asked
if (empty($groupId)) { if (empty($groupId)) {
// Show events sent to everyone and no group // Show events sent to everyone and no group
$userCondition = ' ( (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) '; $userCondition = ' ( (links.user is NULL) AND (links.group IS NULL) ';
// Show events sent to selected groups // Show events sent to selected groups
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
$userCondition .= " OR (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IN (".implode(", ", $groupMemberships)."))) "; $userCondition .= " OR (links.user is NULL) AND (links.group IN (".implode(", ", $groupMemberships)."))) ";
} else { } else {
$userCondition .= " ) "; $userCondition .= " ) ";
} }
$userCondition .= " OR (ip.to_user_id = ".api_get_user_id()." AND (ip.to_group_id IS NULL OR ip.to_group_id = 0)) "; $userCondition .= " OR (links.user = ".api_get_user_id()." AND (links.group IS NULL )) ";
} else { } else {
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
// Show send to everyone - and only selected groups // Show send to everyone - and only selected groups
$userCondition = " (ip.to_user_id = 0 OR ip.to_user_id is NULL) AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition = " (links.user is NULL) AND (links.group IN (".implode(", ", $groupMemberships).")) ";
} }
} }
// Show sent to only me and no group // Show sent to only me and no group
if (!empty($groupMemberships)) { if (!empty($groupMemberships)) {
$userCondition .= " OR (ip.to_user_id = ".api_get_user_id().") AND (ip.to_group_id IN (".implode(", ", $groupMemberships).")) "; $userCondition .= " OR (links.user = ".api_get_user_id().") AND (links.group IN (".implode(", ", $groupMemberships).")) ";
} else {
// Show sent to only me and selected groups
} }
} }
if (!empty($userCondition)) {
$qb->andWhere($userCondition);
}
/*if (!empty($groupMemberships)) {
$orX = $qb->expr()->orX();
foreach ($groupMemberships as $groupId) {
$group = api_get_group_entity($groupId);
$orX->add("links.group = :group$groupId");
$qb->setParameter("group$groupId", $group);
}
$qb->andWhere($orX);
}*/
//$dateCondition = '';
if (!empty($start) && !empty($end)) {
$qb->andWhere(
$qb->expr()->orX(
'resource.startDate BETWEEN :start AND :end',
'resource.endDate BETWEEN :start AND :end',
$qb->expr()->orX(
'resource.startDate IS NOT NULL AND resource.endDate IS NOT NULL AND
YEAR(resource.startDate) = YEAR(resource.endDate) AND
MONTH(:start) BETWEEN MONTH(resource.startDate) AND MONTH(resource.endDate)
'
)
)
)
->setParameter('start', $start)
->setParameter('end', $end);
/*
$dateCondition .= "AND (
agenda.start_date BETWEEN '".$start."' AND '".$end."' OR
agenda.end_date BETWEEN '".$start."' AND '".$end."' OR
(
agenda.start_date IS NOT NULL AND agenda.end_date IS NOT NULL AND
YEAR(agenda.start_date) = YEAR(agenda.end_date) AND
MONTH('$start') BETWEEN MONTH(agenda.start_date) AND MONTH(agenda.end_date)
)
)";*/
}
/*
if (empty($sessionId)) {
$sessionCondition = "
(
agenda.session_id = 0 AND (ip.session_id IS NULL OR ip.session_id = 0)
) ";
} else {
$sessionCondition = "
(
agenda.session_id = $sessionId AND
ip.session_id = $sessionId
) ";
}
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$visibilityCondition = " (ip.visibility IN ('1', '0')) "; $visibilityCondition = " (ip.visibility IN ('1', '0')) ";
} else { } else {
@ -1958,171 +1993,173 @@ class Agenda
} }
$sql .= $dateCondition; $sql .= $dateCondition;
$result = Database::query($sql); $result = Database::query($sql);*/
$coachCanEdit = false; $coachCanEdit = false;
if (!empty($sessionId)) { if (!empty($sessionId)) {
$coachCanEdit = api_is_coach($sessionId, $courseId) || api_is_platform_admin(); $coachCanEdit = api_is_coach($sessionId, $courseId) || api_is_platform_admin();
} }
//var_dump($courseId); echo $qb->getQuery()->getSQL();exit;
if (Database::num_rows($result)) {
$eventsAdded = array_column($this->events, 'unique_id'); $events = $qb->getQuery()->getResult();
while ($row = Database::fetch_array($result, 'ASSOC')) { //$eventsAdded = array_column($this->events, 'unique_id');
$event = []; /** @var CCalendarEvent $row */
$event['id'] = 'course_'.$row['id']; foreach ($events as $row) {
$event['unique_id'] = $row['iid']; $eventId = $row->getIid();
// To avoid doubles $event = [];
if (in_array($event['unique_id'], $eventsAdded)) { $event['id'] = 'course_'.$eventId;
continue; $event['unique_id'] = $eventId;
} // To avoid doubles
/*if (in_array($event['unique_id'], $eventsAdded)) {
$eventsAdded[] = $event['unique_id']; continue;
$eventId = $row['ref']; }*/
$items = $this->getUsersAndGroupSubscribedToEvent(
$eventId, $eventsAdded[] = $eventId;
$courseId, //$eventId = $row['ref'];
$this->sessionId /*$items = $this->getUsersAndGroupSubscribedToEvent(
); $eventId,
$group_to_array = $items['groups']; $courseId,
$user_to_array = $items['users']; $this->sessionId
$attachmentList = $this->getAttachmentList( );
$row['id'], $group_to_array = $items['groups'];
$courseInfo $user_to_array = $items['users'];*/
); $attachmentList = $this->getAttachmentList(
$event['attachment'] = ''; $eventId,
if (!empty($attachmentList)) { $courseInfo
foreach ($attachmentList as $attachment) { );
$has_attachment = Display::return_icon( $event['attachment'] = '';
'attachment.gif', if (!empty($attachmentList)) {
get_lang('Attachment') foreach ($attachmentList as $attachment) {
); $has_attachment = Display::return_icon(
$user_filename = $attachment['filename']; 'attachment.gif',
$url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$courseId.'&'.api_get_cidreq(); get_lang('Attachment')
$event['attachment'] .= $has_attachment. );
Display::url( $user_filename = $attachment['filename'];
$user_filename, $url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$courseId.'&'.api_get_cidreq();
$url $event['attachment'] .= $has_attachment.
).'<br />'; Display::url(
} $user_filename,
$url
).'<br />';
} }
}
$event['title'] = $row['title']; $event['title'] = $row->getTitle();
$event['className'] = 'course'; $event['className'] = 'course';
$event['allDay'] = 'false'; $event['allDay'] = 'false';
$event['course_id'] = $courseId; $event['course_id'] = $courseId;
$event['borderColor'] = $event['backgroundColor'] = $this->event_course_color; $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color;
$sessionInfo = []; $sessionInfo = [];
if (isset($row['session_id']) && !empty($row['session_id'])) { if (!empty($row->getSessionId())) {
$sessionInfo = api_get_session_info($sessionId); $sessionInfo = api_get_session_info($row->getSessionId());
$event['borderColor'] = $event['backgroundColor'] = $this->event_session_color; $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color;
} }
$event['session_name'] = isset($sessionInfo['name']) ? $sessionInfo['name'] : ''; $event['session_name'] = $sessionInfo['name'] ?? '';
$event['course_name'] = isset($courseInfo['title']) ? $courseInfo['title'] : ''; $event['course_name'] = $courseInfo['title'] ?? '';
if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { /*if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
$event['borderColor'] = $event['backgroundColor'] = $this->event_group_color; $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
} }*/
if (!empty($color)) { if (!empty($color)) {
$event['borderColor'] = $event['backgroundColor'] = $color; $event['borderColor'] = $event['backgroundColor'] = $color;
} }
if (isset($row['color']) && !empty($row['color'])) { if ($row->getColor()) {
$event['borderColor'] = $event['backgroundColor'] = $row['color']; $event['borderColor'] = $event['backgroundColor'] = $row->getColor();
} }
$event['editable'] = false; $event['editable'] = false;
if ($this->getIsAllowedToEdit() && $this->type == 'course') { if ($this->getIsAllowedToEdit() && $this->type === 'course') {
$event['editable'] = true; $event['editable'] = true;
if (!empty($sessionId)) { if (!empty($sessionId)) {
if ($coachCanEdit == false) { if ($coachCanEdit == false) {
$event['editable'] = false; $event['editable'] = false;
}
if ($isAllowToEditByHrm) {
$event['editable'] = true;
}
} }
// if user is author then he can edit the item if ($isAllowToEditByHrm) {
if (api_get_user_id() == $row['insert_user_id']) {
$event['editable'] = true; $event['editable'] = true;
} }
} }
// if user is author then he can edit the item
if (!empty($row['start_date'])) { if (api_get_user_id() == $row->getResourceNode()->getCreator()->getId()) {
$event['start'] = $this->formatEventDate($row['start_date']); $event['editable'] = true;
$event['start_date_localtime'] = api_get_local_time($row['start_date']);
}
if (!empty($row['end_date'])) {
$event['end'] = $this->formatEventDate($row['end_date']);
$event['end_date_localtime'] = api_get_local_time($row['end_date']);
} }
}
$event['sent_to'] = ''; if (!empty($row->getStartDate())) {
$event['type'] = 'course'; $event['start'] = $this->formatEventDate($row->getStartDate()->format('Y-m-d H:i:s'));
if ($row['session_id'] != 0) { $event['start_date_localtime'] = api_get_local_time($row->getStartDate()->format('Y-m-d H:i:s'));
$event['type'] = 'session'; }
} if (!empty($row->getEndDate())) {
$event['end'] = $this->formatEventDate($row->getEndDate()->format('Y-m-d H:i:s'));
$event['end_date_localtime'] = api_get_local_time($row->getEndDate()->format('Y-m-d H:i:s'));
}
// Event Sent to a group? $event['sent_to'] = '';
if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { $event['type'] = 'course';
$sent_to = []; if ($row->getSessionId() != 0) {
if (!empty($group_to_array)) { $event['type'] = 'session';
foreach ($group_to_array as $group_item) { }
$sent_to[] = $groupNameList[$group_item];
}
}
$sent_to = implode('@@', $sent_to);
$sent_to = str_replace(
'@@',
'</div><div class="label_tag notice">',
$sent_to
);
$event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
$event['type'] = 'group';
}
// Event sent to a user? // Event Sent to a group?
if (isset($row['to_user_id'])) { /*if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
$sent_to = []; $sent_to = [];
if (!empty($user_to_array)) { if (!empty($group_to_array)) {
foreach ($user_to_array as $item) { foreach ($group_to_array as $group_item) {
$user_info = api_get_user_info($item); $sent_to[] = $groupNameList[$group_item];
// Add username as tooltip for $event['sent_to'] - ref #4226
$username = api_htmlentities(
sprintf(
get_lang('Login: %s'),
$user_info['username']
),
ENT_QUOTES
);
$sent_to[] = "<span title='".$username."'>".$user_info['complete_name']."</span>";
}
} }
$sent_to = implode('@@', $sent_to);
$sent_to = str_replace(
'@@',
'</div><div class="label_tag notice">',
$sent_to
);
$event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
} }
$sent_to = implode('@@', $sent_to);
//Event sent to everyone! $sent_to = str_replace(
if (empty($event['sent_to'])) { '@@',
$event['sent_to'] = '<div class="label_tag notice">'.get_lang('Everyone').'</div>'; '</div><div class="label_tag notice">',
$sent_to
);
$event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
$event['type'] = 'group';
}*/
// Event sent to a user?
/*if (isset($row['to_user_id'])) {
$sent_to = [];
if (!empty($user_to_array)) {
foreach ($user_to_array as $item) {
$user_info = api_get_user_info($item);
// Add username as tooltip for $event['sent_to'] - ref #4226
$username = api_htmlentities(
sprintf(
get_lang('Login: %s'),
$user_info['username']
),
ENT_QUOTES
);
$sent_to[] = "<span title='".$username."'>".$user_info['complete_name']."</span>";
}
} }
$sent_to = implode('@@', $sent_to);
$event['description'] = $row['content']; $sent_to = str_replace(
$event['visibility'] = $row['visibility']; '@@',
$event['real_id'] = $row['id']; '</div><div class="label_tag notice">',
$event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; $sent_to
$event['parent_event_id'] = $row['parent_event_id']; );
$event['has_children'] = $this->hasChildren($row['id'], $courseId) ? 1 : 0; $event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
$event['comment'] = $row['comment']; }*/
$this->events[] = $event;
} //Event sent to everyone!
/*if (empty($event['sent_to'])) {
$event['sent_to'] = '<div class="label_tag notice">'.get_lang('Everyone').'</div>';
}*/
$event['description'] = $row->getContent();
$event['visibility'] = 1;
$event['real_id'] = $eventId;
$event['allDay'] = $row->getAllDay();
$event['parent_event_id'] = $row->getParentEventId();
$event['has_children'] = $this->hasChildren($eventId, $courseId) ? 1 : 0;
$event['comment'] = $row->getComment();
$this->events[] = $event;
} }
return $this->events; return $this->events;
@ -3226,33 +3263,6 @@ class Agenda
$sentTo $sentTo
); );
} }
if (!empty($repeat['COUNT'])) {
/*$count = $repeat['COUNT'];
$interval = $repeat['INTERVAL'];
$endDate = null;
switch($freq) {
case 'daily':
$start = api_strtotime($startDateTime);
$date = new DateTime($startDateTime);
$days = $count * $interval;
var_dump($days);
$date->add(new DateInterval("P".$days."D"));
$endDate = $date->format('Y-m-d H:i');
//$endDate = $count *
for ($i = 0; $i < $count; $i++) {
$days = 86400 * 7
}
}
}*/
//$res = agenda_add_repeat_item($courseInfo, $id, $freq, $count, $attendee);
/*$this->addRepeatedItem(
$id,
$freq,
$endDate,
$sentTo
);*/
}
} }
} }
} }
@ -3279,10 +3289,10 @@ class Agenda
$groupId = null; $groupId = null;
$userId = null; $userId = null;
if ($filter == 'everyone') { if ($filter === 'everyone') {
$everyone = true; $everyone = true;
} else { } else {
if (substr($filter, 0, 1) == 'G') { if (substr($filter, 0, 1) === 'G') {
$groupId = str_replace('GROUP:', '', $filter); $groupId = str_replace('GROUP:', '', $filter);
} else { } else {
$userId = str_replace('USER:', '', $filter); $userId = str_replace('USER:', '', $filter);
@ -3308,7 +3318,7 @@ class Agenda
$month, $month,
$year $year
) { ) {
$user_id = intval($user_id); $user_id = (int) $user_id;
$items = []; $items = [];
$my_list = []; $my_list = [];

@ -288,7 +288,12 @@ function api_get_utc_datetime(
if (is_numeric($time)) { if (is_numeric($time)) {
$time = (int) $time; $time = (int) $time;
return gmdate('Y-m-d H:i:s', $time); $time = gmdate('Y-m-d H:i:s', $time);
if ($returnObj) {
return new DateTime($time, new DateTimeZone('UTC'));
}
return $time;
} }
try { try {
$fromTimezone = api_get_timezone(); $fromTimezone = api_get_timezone();

@ -424,9 +424,9 @@ class ResourceRepository extends BaseEntityRepository
$em = $this->getEntityManager(); $em = $this->getEntityManager();
if (!empty($userList)) { if (!empty($userList)) {
$userRepo = $em->getRepository('ChamiloUserBundle:User');
foreach ($userList as $userId) { foreach ($userList as $userId) {
$toUser = $em->getRepository('ChamiloUserBundle:User')->find($userId); $toUser = $userRepo->find($userId);
$resourceLink = $this->addResourceNodeToUser($resourceNode, $toUser); $resourceLink = $this->addResourceNodeToUser($resourceNode, $toUser);
$em->persist($resourceLink); $em->persist($resourceLink);
} }
@ -482,7 +482,6 @@ class ResourceRepository extends BaseEntityRepository
$checker->isGranted('ROLE_CURRENT_COURSE_TEACHER'); $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER');
// Do not show deleted resources // Do not show deleted resources
$qb $qb
->andWhere('links.visibility != :visibilityDeleted') ->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED) ->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
@ -519,7 +518,54 @@ class ResourceRepository extends BaseEntityRepository
$qb->andWhere('links.group IS NULL'); $qb->andWhere('links.group IS NULL');
} }
///var_dump($qb->getQuery()->getSQL(), $type->getId(), $parentNode->getId());exit; return $qb;
}
public function getResourcesByCourseOnly(Course $course, ResourceNode $parentNode = null)
{
$repo = $this->getRepository();
$className = $repo->getClassName();
$checker = $this->getAuthorizationChecker();
$type = $this->getResourceType();
$qb = $repo->getEntityManager()->createQueryBuilder()
->select('resource')
->from($className, 'resource')
->innerJoin(
ResourceNode::class,
'node',
Join::WITH,
'resource.resourceNode = node.id'
)
->innerJoin('node.resourceLinks', 'links')
->where('node.resourceType = :type')
->setParameter('type', $type);
$qb
->andWhere('links.course = :course')
->setParameter('course', $course)
;
$isAdmin = $checker->isGranted('ROLE_ADMIN') ||
$checker->isGranted('ROLE_CURRENT_COURSE_TEACHER');
// Do not show deleted resources
$qb
->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
;
if (false === $isAdmin) {
$qb
->andWhere('links.visibility = :visibility')
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
;
// @todo Add start/end visibility restrictrions
}
if (null !== $parentNode) {
$qb->andWhere('node.parent = :parentNode');
$qb->setParameter('parentNode', $parentNode);
}
return $qb; return $qb;
} }

@ -291,7 +291,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
*/ */
public function getAllDay() public function getAllDay()
{ {
return $this->allDay; return (int) $this->allDay;
} }
/** /**

Loading…
Cancel
Save