123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <?php
- /* For licensing terms, see /license.txt */
- namespace Chamilo\PluginBundle\Entity\ImsLti;
- use Chamilo\CoreBundle\Entity\Course;
- use Chamilo\CoreBundle\Entity\GradebookEvaluation;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * Class ImsLtiTool
- *
- * @ORM\Table(name="plugin_ims_lti_tool")
- * @ORM\Entity()
- */
- class ImsLtiTool
- {
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue
- */
- protected $id;
- /**
- * @var string
- *
- * @ORM\Column(name="name", type="string")
- */
- private $name = '';
- /**
- * @var string|null
- *
- * @ORM\Column(name="description", type="text", nullable=true)
- */
- private $description = null;
- /**
- * @var string
- *
- * @ORM\Column(name="launch_url", type="string")
- */
- private $launchUrl = '';
- /**
- * @var string
- *
- * @ORM\Column(name="consumer_key", type="string", nullable=true)
- */
- private $consumerKey = '';
- /**
- * @var string
- *
- * @ORM\Column(name="shared_secret", type="string", nullable=true)
- */
- private $sharedSecret = '';
- /**
- * @var string|null
- *
- * @ORM\Column(name="custom_params", type="text", nullable=true)
- */
- private $customParams = null;
- /**
- * @var bool
- *
- * @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false})
- */
- private $activeDeepLinking = false;
- /**
- * @var null|string
- *
- * @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null})
- */
- private $privacy = null;
- /**
- * @var Course|null
- *
- * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
- * @ORM\JoinColumn(name="c_id", referencedColumnName="id")
- */
- private $course = null;
- /**
- * @var GradebookEvaluation|null
- *
- * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\GradebookEvaluation")
- * @ORM\JoinColumn(name="gradebook_eval_id", referencedColumnName="id", onDelete="SET NULL")
- */
- private $gradebookEval = null;
- /**
- * @var ImsLtiTool|null
- *
- * @ORM\ManyToOne(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", inversedBy="children")
- * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
- */
- private $parent;
- /**
- * @var ArrayCollection
- *
- * @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent")
- */
- private $children;
- /**
- * ImsLtiTool constructor.
- */
- public function __construct()
- {
- $this->description = null;
- $this->customParams = null;
- $this->activeDeepLinking = false;
- $this->course = null;
- $this->gradebookEval =null;
- $this->privacy = null;
- $this->children = new ArrayCollection();
- $this->consumerKey = null;
- $this->sharedSecret = null;
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @param string $name
- * @return ImsLtiTool
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @return null|string
- */
- public function getDescription()
- {
- return $this->description;
- }
- /**
- * @param null|string $description
- * @return ImsLtiTool
- */
- public function setDescription($description)
- {
- $this->description = $description;
- return $this;
- }
- /**
- * @return string
- */
- public function getLaunchUrl()
- {
- return $this->launchUrl;
- }
- /**
- * @param string $launchUrl
- * @return ImsLtiTool
- */
- public function setLaunchUrl($launchUrl)
- {
- $this->launchUrl = $launchUrl;
- return $this;
- }
- /**
- * @return string
- */
- public function getConsumerKey()
- {
- return $this->consumerKey;
- }
- /**
- * @param string $consumerKey
- * @return ImsLtiTool
- */
- public function setConsumerKey($consumerKey)
- {
- $this->consumerKey = $consumerKey;
- return $this;
- }
- /**
- * @return string
- */
- public function getSharedSecret()
- {
- return $this->sharedSecret;
- }
- /**
- * @param string $sharedSecret
- * @return ImsLtiTool
- */
- public function setSharedSecret($sharedSecret)
- {
- $this->sharedSecret = $sharedSecret;
- return $this;
- }
- /**
- * @return null|string
- */
- public function getCustomParams()
- {
- return $this->customParams;
- }
- /**
- * @param null|string $customParams
- * @return ImsLtiTool
- */
- public function setCustomParams($customParams)
- {
- $this->customParams = $customParams;
- return $this;
- }
- /**
- * @return bool
- */
- public function isGlobal()
- {
- return $this->course === null;
- }
- /**
- * @param array $params
- *
- * @return null|string
- */
- public function encodeCustomParams(array $params)
- {
- if (empty($params)) {
- return null;
- }
- $pairs = [];
- foreach ($params as $key => $value) {
- $pairs[] = "$key=$value";
- }
- return implode("\n", $pairs);
- }
- /**
- * @return array
- */
- public function parseCustomParams()
- {
- if (empty($this->customParams)) {
- return [];
- }
- $params = [];
- $strings = explode("\n", $this->customParams);
- foreach ($strings as $string) {
- if (empty($string)) {
- continue;
- }
- $pairs = explode('=', $string, 2);
- $key = self::parseCustomKey($pairs[0]);
- $value = $pairs[1];
- $params['custom_'.$key] = $value;
- }
- return $params;
- }
- /**
- * Map the key from custom param.
- *
- * @param string $key
- *
- * @return string
- */
- private static function parseCustomKey($key)
- {
- $newKey = '';
- $key = strtolower($key);
- $split = str_split($key);
- foreach ($split as $char) {
- if (
- ($char >= 'a' && $char <= 'z') || ($char >= '0' && $char <= '9')
- ) {
- $newKey .= $char;
- continue;
- }
- $newKey .= '_';
- }
- return $newKey;
- }
- /**
- * Set activeDeepLinking.
- *
- * @param bool $activeDeepLinking
- *
- * @return ImsLtiTool
- */
- public function setActiveDeepLinking($activeDeepLinking)
- {
- $this->activeDeepLinking = $activeDeepLinking;
- return $this;
- }
- /**
- * Get activeDeepLinking.
- *
- * @return bool
- */
- public function isActiveDeepLinking()
- {
- return $this->activeDeepLinking;
- }
- /**
- * Get course.
- *
- * @return Course|null
- */
- public function getCourse()
- {
- return $this->course;
- }
- /**
- * Set course.
- *
- * @param Course|null $course
- *
- * @return ImsLtiTool
- */
- public function setCourse(Course $course = null)
- {
- $this->course = $course;
- return $this;
- }
- /**
- * Get gradebookEval.
- *
- * @return GradebookEvaluation|null
- */
- public function getGradebookEval()
- {
- return $this->gradebookEval;
- }
- /**
- * Set gradebookEval.
- *
- * @param GradebookEvaluation|null $gradebookEval
- *
- * @return ImsLtiTool
- */
- public function setGradebookEval($gradebookEval)
- {
- $this->gradebookEval = $gradebookEval;
- return $this;
- }
- /**
- * Get privacy.
- *
- * @return null|string
- */
- public function getPrivacy()
- {
- return $this->privacy;
- }
- /**
- * Set privacy.
- *
- * @param bool $shareName
- * @param bool $shareEmail
- * @param bool $sharePicture
- *
- * @return ImsLtiTool
- */
- public function setPrivacy($shareName = false, $shareEmail = false, $sharePicture = false)
- {
- $this->privacy = serialize(
- [
- 'share_name' => $shareName,
- 'share_email' => $shareEmail,
- 'share_picture' => $sharePicture,
- ]
- );
- return $this;
- }
- /**
- * @return bool
- */
- public function isSharingName()
- {
- $unserialize = $this->unserializePrivacy();
- return (bool) $unserialize['share_name'];
- }
- /**
- * @return bool
- */
- public function isSharingEmail()
- {
- $unserialize = $this->unserializePrivacy();
- return (bool) $unserialize['share_email'];
- }
- /**
- * @return bool
- */
- public function isSharingPicture()
- {
- $unserialize = $this->unserializePrivacy();
- return (bool) $unserialize['share_picture'];
- }
- /**
- * @return mixed
- */
- public function unserializePrivacy()
- {
- return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy);
- }
- /**
- * @return ImsLtiTool|null
- */
- public function getParent()
- {
- return $this->parent;
- }
- /**
- * @param ImsLtiTool $parent
- *
- * @return ImsLtiTool
- */
- public function setParent(ImsLtiTool $parent)
- {
- $this->parent = $parent;
- $this->sharedSecret = $parent->getSharedSecret();
- $this->consumerKey = $parent->getConsumerKey();
- $this->privacy = $parent->getPrivacy();
- return $this;
- }
- }
|