Agenda - Fix CRUD + update entities, fix repeat events

pull/3844/head
Julio Montoya 5 years ago
parent 539af53a08
commit 1c7bba8b91
  1. 13
      public/main/calendar/agenda.php
  2. 8
      public/main/inc/lib/agenda.lib.php
  3. 51
      src/CoreBundle/Entity/PersonalAgenda.php
  4. 8
      src/CoreBundle/Entity/ResourceFile.php
  5. 12
      src/CoreBundle/Entity/SysCalendar.php
  6. 43
      src/CourseBundle/Entity/CCalendarEvent.php

@ -68,7 +68,8 @@ function add_image_form() {
filepaths.appendChild(elem1); filepaths.appendChild(elem1);
id_elem1 = "filepath_"+counter_image; id_elem1 = "filepath_"+counter_image;
id_elem1 = "\'"+id_elem1+"\'"; id_elem1 = "\'"+id_elem1+"\'";
document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" />&nbsp; <br />'.get_lang('Description').'&nbsp;&nbsp;<input type=\"text\" name=\"legend[]\" /><br /><br />"; document.
getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" />&nbsp; <br />'.get_lang('Description').'&nbsp;&nbsp;<input type=\"text\" name=\"legend[]\" /><br /><br />";
if (filepaths.childNodes.length == 6) { if (filepaths.childNodes.length == 6) {
var link_attach = document.getElementById("link-more-attach"); var link_attach = document.getElementById("link-more-attach");
if (link_attach) { if (link_attach) {
@ -120,12 +121,12 @@ if ($allowToEdit) {
if ($form->validate()) { if ($form->validate()) {
$values = $form->getSubmitValues(); $values = $form->getSubmitValues();
$sendEmail = isset($values['add_announcement']) ? true : false; $sendEmail = isset($values['add_announcement']);
$allDay = isset($values['all_day']) ? 'true' : 'false'; $allDay = isset($values['all_day']) ? 'true' : 'false';
$sendAttachment = isset($_FILES) && !empty($_FILES) ? true : false; $sendAttachment = isset($_FILES) && !empty($_FILES);
$attachmentCommentList = isset($values['legend']) ? $values['legend'] : null; $attachmentCommentList = $values['legend'] ?? null;
$comment = isset($values['comment']) ? $values['comment'] : null; $comment = $values['comment'] ?? null;
$usersToSend = isset($values['users_to_send']) ? $values['users_to_send'] : ''; $usersToSend = $values['users_to_send'] ?? '';
$startDate = $values['date_range_start']; $startDate = $values['date_range_start'];
$endDate = $values['date_range_end']; $endDate = $values['date_range_end'];

@ -489,7 +489,6 @@ class Agenda
return false; return false;
} }
$courseId = $this->course['real_id'];
$eventId = (int) $eventId; $eventId = (int) $eventId;
$sql = "SELECT title, content, start_date, end_date, all_day $sql = "SELECT title, content, start_date, end_date, all_day
@ -510,15 +509,15 @@ class Agenda
'yearly', 'yearly',
]; ];
if (!in_array($type, $typeList)) { if (!in_array($type, $typeList, true)) {
return false; return false;
} }
$now = time(); $now = time();
$endTimeStamp = api_strtotime($end, 'UTC');
// The event has to repeat *in the future*. We don't allow repeated // The event has to repeat *in the future*. We don't allow repeated
// events in the past // events in the past
if ($end > $now) { if ($endTimeStamp < $now) {
return false; return false;
} }
@ -530,7 +529,6 @@ class Agenda
$type = Database::escape_string($type); $type = Database::escape_string($type);
$end = Database::escape_string($end); $end = Database::escape_string($end);
$endTimeStamp = api_strtotime($end, 'UTC');
$sql = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end) $sql = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end)
VALUES ('$eventId', '$type', '$endTimeStamp')"; VALUES ('$eventId', '$type', '$endTimeStamp')";
Database::query($sql); Database::query($sql);

@ -75,13 +75,16 @@ class PersonalAgenda
protected ?string $color; protected ?string $color;
/** /**
* Set title. * Get id.
*
* @param string $title
* *
* @return PersonalAgenda * @return int
*/ */
public function setTitle($title) public function getId()
{
return $this->id;
}
public function setTitle(string $title): self
{ {
$this->title = $title; $this->title = $title;
@ -98,26 +101,14 @@ class PersonalAgenda
return $this->title; return $this->title;
} }
/** public function setText(string $text): self
* Set text.
*
* @param string $text
*
* @return PersonalAgenda
*/
public function setText($text)
{ {
$this->text = $text; $this->text = $text;
return $this; return $this;
} }
/** public function getText(): string
* Get text.
*
* @return string
*/
public function getText()
{ {
return $this->text; return $this->text;
} }
@ -126,10 +117,8 @@ class PersonalAgenda
* Set date. * Set date.
* *
* @param DateTime $date * @param DateTime $date
*
* @return PersonalAgenda
*/ */
public function setDate($date) public function setDate($date): self
{ {
$this->date = $date; $this->date = $date;
@ -153,7 +142,7 @@ class PersonalAgenda
* *
* @return PersonalAgenda * @return PersonalAgenda
*/ */
public function setEndDate($value) public function setEndDate($value): self
{ {
$this->endDate = $value; $this->endDate = $value;
@ -175,7 +164,7 @@ class PersonalAgenda
* *
* @return PersonalAgenda * @return PersonalAgenda
*/ */
public function setParentEventId($parentEventId) public function setParentEventId($parentEventId): self
{ {
$this->parentEventId = $parentEventId; $this->parentEventId = $parentEventId;
@ -199,7 +188,7 @@ class PersonalAgenda
* *
* @return PersonalAgenda * @return PersonalAgenda
*/ */
public function setAllDay($allDay) public function setAllDay($allDay): self
{ {
$this->allDay = $allDay; $this->allDay = $allDay;
@ -216,16 +205,6 @@ class PersonalAgenda
return $this->allDay; return $this->allDay;
} }
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/** /**
* @return string * @return string
*/ */
@ -239,7 +218,7 @@ class PersonalAgenda
* *
* @return PersonalAgenda * @return PersonalAgenda
*/ */
public function setColor($color) public function setColor($color): self
{ {
$this->color = $color; $this->color = $color;

@ -218,7 +218,7 @@ class ResourceFile
return $this->name; return $this->name;
} }
public function setName($name): self public function setName(?string $name): self
{ {
$this->name = $name; $this->name = $name;
@ -235,8 +235,6 @@ class ResourceFile
/** /**
* @param string $crop * @param string $crop
*
* @return $this
*/ */
public function setCrop($crop): self public function setCrop($crop): self
{ {
@ -245,12 +243,12 @@ class ResourceFile
return $this; return $this;
} }
public function getSize(): int public function getSize(): ?int
{ {
return $this->size; return $this->size;
} }
public function setSize(int $size): self public function setSize(?int $size): self
{ {
$this->size = $size; $this->size = $size;

@ -61,7 +61,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setTitle($title) public function setTitle($title): self
{ {
$this->title = $title; $this->title = $title;
@ -85,7 +85,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setContent($content) public function setContent($content): self
{ {
$this->content = $content; $this->content = $content;
@ -109,7 +109,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setStartDate($startDate) public function setStartDate($startDate): self
{ {
$this->startDate = $startDate; $this->startDate = $startDate;
@ -133,7 +133,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setEndDate($endDate) public function setEndDate($endDate): self
{ {
$this->endDate = $endDate; $this->endDate = $endDate;
@ -157,7 +157,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setAccessUrlId($accessUrlId) public function setAccessUrlId($accessUrlId): self
{ {
$this->accessUrlId = $accessUrlId; $this->accessUrlId = $accessUrlId;
@ -181,7 +181,7 @@ class SysCalendar
* *
* @return SysCalendar * @return SysCalendar
*/ */
public function setAllDay($allDay) public function setAllDay($allDay): self
{ {
$this->allDay = $allDay; $this->allDay = $allDay;

@ -11,6 +11,7 @@ use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\Room; use Chamilo\CoreBundle\Entity\Room;
use DateTime; use DateTime;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -55,7 +56,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
protected ?DateTime $endDate; protected ?DateTime $endDate;
/** /**
* @var ArrayCollection|CCalendarEvent[] * @var Collection|CCalendarEvent[]
* @ORM\OneToMany(targetEntity="CCalendarEvent", mappedBy="parentEvent") * @ORM\OneToMany(targetEntity="CCalendarEvent", mappedBy="parentEvent")
*/ */
protected $children; protected $children;
@ -67,7 +68,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
protected ?CCalendarEvent $parentEvent = null; protected ?CCalendarEvent $parentEvent = null;
/** /**
* @var ArrayCollection|CCalendarEventRepeat[] * @var Collection|CCalendarEventRepeat[]
* *
* @ORM\OneToMany(targetEntity="CCalendarEventRepeat", mappedBy="event", cascade={"persist"}, orphanRemoval=true) * @ORM\OneToMany(targetEntity="CCalendarEventRepeat", mappedBy="event", cascade={"persist"}, orphanRemoval=true)
*/ */
@ -95,10 +96,10 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
protected ?Room $room = null; protected ?Room $room = null;
/** /**
* @var ArrayCollection|CCalendarEventAttachment[] * @var Collection|CCalendarEventAttachment[]
* *
* @ORM\OneToMany( * @ORM\OneToMany(
* targetEntity="CCalendarEventAttachment", mappedBy="event", cascade={"persist", "remove"}, orphanRemoval=true * targetEntity="CCalendarEventAttachment", mappedBy="event", cascade={"persist", "remove"}
* ) * )
*/ */
protected $attachments; protected $attachments;
@ -106,6 +107,8 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
public function __construct() public function __construct()
{ {
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->repeatEvents = new ArrayCollection();
} }
public function __toString(): string public function __toString(): string
@ -120,12 +123,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
return $this; return $this;
} }
/** public function getTitle(): string
* Get title.
*
* @return string
*/
public function getTitle()
{ {
return $this->title; return $this->title;
} }
@ -189,7 +187,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
} }
/** /**
* @return ArrayCollection|CCalendarEvent[] * @return Collection|CCalendarEvent[]
*/ */
public function getChildren() public function getChildren()
{ {
@ -240,28 +238,19 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
return $this->comment; return $this->comment;
} }
/** public function setComment(string $comment): self
* @param string $comment
*/
public function setComment($comment): self
{ {
$this->comment = $comment; $this->comment = $comment;
return $this; return $this;
} }
/** public function getRoom(): ?Room
* @return Room
*/
public function getRoom()
{ {
return $this->room; return $this->room;
} }
/** public function setRoom(Room $room): self
* @param Room $room
*/
public function setRoom($room): self
{ {
$this->room = $room; $this->room = $room;
@ -295,7 +284,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
} }
/** /**
* @return ArrayCollection|CCalendarEventAttachment[] * @return Collection|CCalendarEventAttachment[]
*/ */
public function getAttachments() public function getAttachments()
{ {
@ -303,7 +292,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
} }
/** /**
* @param ArrayCollection|CCalendarEventAttachment[] $attachments * @param Collection|CCalendarEventAttachment[] $attachments
*/ */
public function setAttachments($attachments): self public function setAttachments($attachments): self
{ {
@ -320,7 +309,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
} }
/** /**
* @return ArrayCollection|CCalendarEventRepeat[] * @return Collection|CCalendarEventRepeat[]
*/ */
public function getRepeatEvents() public function getRepeatEvents()
{ {
@ -328,7 +317,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
} }
/** /**
* @param ArrayCollection|CCalendarEventRepeat[] $repeatEvents * @param Collection|CCalendarEventRepeat[] $repeatEvents
* *
* @return CCalendarEvent * @return CCalendarEvent
*/ */

Loading…
Cancel
Save