You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
4.5 KiB
190 lines
4.5 KiB
|
5 years ago
|
<?php
|
||
|
5 years ago
|
|
||
|
5 years ago
|
/* For licensing terms, see /license.txt */
|
||
|
|
|
||
|
|
namespace Chamilo\PluginBundle\Zoom;
|
||
|
|
|
||
|
|
use Chamilo\PluginBundle\Zoom\API\RecordingMeeting;
|
||
|
|
use Database;
|
||
|
|
use DateInterval;
|
||
|
|
use DateTime;
|
||
|
|
use DateTimeZone;
|
||
|
|
use Doctrine\ORM\Mapping as ORM;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Class RecordingEntity.
|
||
|
5 years ago
|
*
|
||
|
5 years ago
|
* @ORM\Entity(repositoryClass="Chamilo\PluginBundle\Zoom\RecordingRepository")
|
||
|
5 years ago
|
* @ORM\Table(
|
||
|
|
* name="plugin_zoom_recording",
|
||
|
|
* indexes={
|
||
|
|
* @ORM\Index(name="meeting_id_index", columns={"meeting_id"}),
|
||
|
|
* }
|
||
|
|
* )
|
||
|
|
* @ORM\HasLifecycleCallbacks
|
||
|
|
*/
|
||
|
5 years ago
|
class Recording
|
||
|
5 years ago
|
{
|
||
|
5 years ago
|
/** @var DateTime */
|
||
|
|
public $startDateTime;
|
||
|
|
|
||
|
|
/** @var string */
|
||
|
|
public $formattedStartTime;
|
||
|
|
|
||
|
|
/** @var DateInterval */
|
||
|
|
public $durationInterval;
|
||
|
|
|
||
|
|
/** @var string */
|
||
|
|
public $formattedDuration;
|
||
|
|
|
||
|
5 years ago
|
/**
|
||
|
|
* @var string
|
||
|
5 years ago
|
* @ORM\Column(type="integer")
|
||
|
5 years ago
|
* @ORM\Id
|
||
|
5 years ago
|
* @ORM\GeneratedValue()
|
||
|
|
*/
|
||
|
5 years ago
|
protected $id;
|
||
|
5 years ago
|
|
||
|
|
/**
|
||
|
|
* @var string
|
||
|
|
* @ORM\Column(type="string")
|
||
|
5 years ago
|
*/
|
||
|
5 years ago
|
protected $uuid;
|
||
|
5 years ago
|
|
||
|
|
/**
|
||
|
5 years ago
|
* @var Meeting
|
||
|
|
* @ORM\ManyToOne(targetEntity="Meeting", inversedBy="recordings")
|
||
|
5 years ago
|
* @ORM\JoinColumn(name="meeting_id")
|
||
|
|
*/
|
||
|
5 years ago
|
protected $meeting;
|
||
|
5 years ago
|
|
||
|
|
/**
|
||
|
|
* @var string
|
||
|
|
* @ORM\Column(type="text", name="recording_meeting_json", nullable=true)
|
||
|
|
*/
|
||
|
5 years ago
|
protected $recordingMeetingJson;
|
||
|
5 years ago
|
|
||
|
|
/** @var RecordingMeeting */
|
||
|
5 years ago
|
protected $recordingMeeting;
|
||
|
5 years ago
|
|
||
|
|
/**
|
||
|
|
* @param $name
|
||
|
|
*
|
||
|
|
* @throws Exception
|
||
|
|
*
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function __get($name)
|
||
|
|
{
|
||
|
|
$object = $this->getRecordingMeeting();
|
||
|
|
if (property_exists($object, $name)) {
|
||
|
|
return $object->$name;
|
||
|
|
}
|
||
|
|
throw new Exception(sprintf('%s does not know property %s', $this, $name));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function __toString()
|
||
|
|
{
|
||
|
|
return sprintf('Recording %d', $this->uuid);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
5 years ago
|
* @return Meeting
|
||
|
5 years ago
|
*/
|
||
|
|
public function getMeeting()
|
||
|
|
{
|
||
|
|
return $this->meeting;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws Exception
|
||
|
5 years ago
|
*
|
||
|
|
* @return RecordingMeeting
|
||
|
5 years ago
|
*/
|
||
|
|
public function getRecordingMeeting()
|
||
|
|
{
|
||
|
|
return $this->recordingMeeting;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
5 years ago
|
* @param Meeting $meeting
|
||
|
5 years ago
|
*
|
||
|
|
* @return $this
|
||
|
|
*/
|
||
|
|
public function setMeeting($meeting)
|
||
|
|
{
|
||
|
|
$this->meeting = $meeting;
|
||
|
|
$this->meeting->getRecordings()->add($this);
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param RecordingMeeting $recordingMeeting
|
||
|
|
*
|
||
|
5 years ago
|
* @return Recording
|
||
|
|
*@throws Exception
|
||
|
5 years ago
|
*
|
||
|
|
*/
|
||
|
|
public function setRecordingMeeting($recordingMeeting)
|
||
|
|
{
|
||
|
5 years ago
|
if (null === $this->uuid) {
|
||
|
5 years ago
|
$this->uuid = $recordingMeeting->uuid;
|
||
|
|
} elseif ($this->uuid !== $recordingMeeting->uuid) {
|
||
|
|
throw new Exception('the RecordingEntity identifier differs from the RecordingMeeting identifier');
|
||
|
|
}
|
||
|
5 years ago
|
if (null === $this->meeting) {
|
||
|
5 years ago
|
$this->meeting = Database::getManager()->getRepository(Meeting::class)->find($recordingMeeting->id);
|
||
|
5 years ago
|
} elseif ($this->meeting->getId() != $recordingMeeting->id) {
|
||
|
5 years ago
|
// $this->meeting remains null when the remote RecordingMeeting refers to a deleted meeting.
|
||
|
5 years ago
|
throw new Exception('The RecordingEntity meeting id differs from the RecordingMeeting meeting id');
|
||
|
|
}
|
||
|
|
$this->recordingMeeting = $recordingMeeting;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\PostLoad
|
||
|
|
*
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function postLoad()
|
||
|
|
{
|
||
|
5 years ago
|
if (null !== $this->recordingMeetingJson) {
|
||
|
5 years ago
|
$this->recordingMeeting = RecordingMeeting::fromJson($this->recordingMeetingJson);
|
||
|
|
}
|
||
|
|
$this->initializeExtraProperties();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\PreFlush
|
||
|
|
*/
|
||
|
|
public function preFlush()
|
||
|
|
{
|
||
|
5 years ago
|
if (null !== $this->recordingMeeting) {
|
||
|
5 years ago
|
$this->recordingMeetingJson = json_encode($this->recordingMeeting);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function initializeExtraProperties()
|
||
|
|
{
|
||
|
|
$this->startDateTime = new DateTime($this->recordingMeeting->start_time);
|
||
|
|
$this->startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||
|
5 years ago
|
$this->formattedStartTime = $this->startDateTime->format('Y-m-d H:i');
|
||
|
5 years ago
|
|
||
|
|
$now = new DateTime();
|
||
|
|
$later = new DateTime();
|
||
|
|
$later->add(new DateInterval('PT'.$this->recordingMeeting->duration.'M'));
|
||
|
|
$this->durationInterval = $later->diff($now);
|
||
|
|
$this->formattedDuration = $this->durationInterval->format(get_lang('DurationFormat'));
|
||
|
|
}
|
||
|
|
}
|