Skip to content

Commit 8821d0d

Browse files
committed
Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x
2 parents 920135d + 4c596ce commit 8821d0d

File tree

14 files changed

+406
-265
lines changed

14 files changed

+406
-265
lines changed

plugin/ims_lti/Entity/ImsLtiTool.php

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<?php
2+
/* For licensing terms, see /license.txt */
3+
4+
namespace Chamilo\PluginBundle\Entity\ImsLti;
5+
6+
use Doctrine\ORM\Mapping as ORM;
7+
8+
/**
9+
* Class ImsLtiTool
10+
*
11+
* @ORM\Table(name="plugin_ims_lti_tool")
12+
* @ORM\Entity()
13+
*/
14+
class ImsLtiTool
15+
{
16+
/**
17+
* @var integer
18+
*
19+
* @ORM\Column(name="id", type="integer")
20+
* @ORM\Id
21+
* @ORM\GeneratedValue
22+
*/
23+
protected $id;
24+
/**
25+
* @var string
26+
*
27+
* @ORM\Column(name="name", type="string")
28+
*/
29+
private $name = '';
30+
/**
31+
* @var string|null
32+
*
33+
* @ORM\Column(name="description", type="text", nullable=true)
34+
*/
35+
private $description = null;
36+
/**
37+
* @var string
38+
*
39+
* @ORM\Column(name="launch_url", type="string")
40+
*/
41+
private $launchUrl = '';
42+
/**
43+
* @var string
44+
*
45+
* @ORM\Column(name="consumer_key", type="string")
46+
*/
47+
private $consumerKey = '';
48+
/**
49+
* @var string
50+
*
51+
* @ORM\Column(name="shared_secret", type="string")
52+
*/
53+
private $sharedSecret = '';
54+
/**
55+
* @var string|null
56+
*
57+
* @ORM\Column(name="custom_params", type="text", nullable=true)
58+
*/
59+
private $customParams = null;
60+
/**
61+
* @var bool
62+
*
63+
* @ORM\Column(name="is_global", type="boolean")
64+
*/
65+
private $isGlobal = false;
66+
67+
/**
68+
* @return int
69+
*/
70+
public function getId()
71+
{
72+
return $this->id;
73+
}
74+
75+
/**
76+
* @return string
77+
*/
78+
public function getName()
79+
{
80+
return $this->name;
81+
}
82+
83+
/**
84+
* @param string $name
85+
* @return ImsLtiTool
86+
*/
87+
public function setName($name)
88+
{
89+
$this->name = $name;
90+
91+
return $this;
92+
}
93+
94+
/**
95+
* @return null|string
96+
*/
97+
public function getDescription()
98+
{
99+
return $this->description;
100+
}
101+
102+
/**
103+
* @param null|string $description
104+
* @return ImsLtiTool
105+
*/
106+
public function setDescription($description)
107+
{
108+
$this->description = $description;
109+
110+
return $this;
111+
}
112+
113+
/**
114+
* @return string
115+
*/
116+
public function getLaunchUrl()
117+
{
118+
return $this->launchUrl;
119+
}
120+
121+
/**
122+
* @param string $launchUrl
123+
* @return ImsLtiTool
124+
*/
125+
public function setLaunchUrl($launchUrl)
126+
{
127+
$this->launchUrl = $launchUrl;
128+
129+
return $this;
130+
}
131+
132+
/**
133+
* @return string
134+
*/
135+
public function getConsumerKey()
136+
{
137+
return $this->consumerKey;
138+
}
139+
140+
/**
141+
* @param string $consumerKey
142+
* @return ImsLtiTool
143+
*/
144+
public function setConsumerKey($consumerKey)
145+
{
146+
$this->consumerKey = $consumerKey;
147+
148+
return $this;
149+
}
150+
151+
/**
152+
* @return string
153+
*/
154+
public function getSharedSecret()
155+
{
156+
return $this->sharedSecret;
157+
}
158+
159+
/**
160+
* @param string $sharedSecret
161+
* @return ImsLtiTool
162+
*/
163+
public function setSharedSecret($sharedSecret)
164+
{
165+
$this->sharedSecret = $sharedSecret;
166+
167+
return $this;
168+
}
169+
170+
/**
171+
* @return null|string
172+
*/
173+
public function getCustomParams()
174+
{
175+
return $this->customParams;
176+
}
177+
178+
/**
179+
* @param null|string $customParams
180+
* @return ImsLtiTool
181+
*/
182+
public function setCustomParams($customParams)
183+
{
184+
$this->customParams = $customParams;
185+
186+
return $this;
187+
}
188+
189+
/**
190+
* @return bool
191+
*/
192+
public function isGlobal()
193+
{
194+
return $this->isGlobal;
195+
}
196+
197+
/**
198+
* @param bool $isGlobal
199+
* @return ImsLtiTool
200+
*/
201+
public function setIsGlobal($isGlobal)
202+
{
203+
$this->isGlobal = $isGlobal;
204+
205+
return $this;
206+
}
207+
208+
/**
209+
* @return array
210+
*/
211+
public function parseCustomParams()
212+
{
213+
$strings = explode($this->customParams, "\n");
214+
$pairs = explode('=', $strings);
215+
216+
return [
217+
'key' => 'custom_'.$pairs[0],
218+
'value' => $pairs[1]
219+
];
220+
}
221+
}

plugin/ims_lti/ImsLtiPlugin.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Doctrine\DBAL\Schema\Schema;
77
use Doctrine\DBAL\Types\Type;
88
use Doctrine\DBAL\DBALException;
9+
use Symfony\Component\Filesystem\Filesystem;
10+
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
911

1012
/**
1113
* Description of MsiLti
@@ -14,7 +16,7 @@
1416
*/
1517
class ImsLtiPlugin extends Plugin
1618
{
17-
const TABLE_TOOL = 'plugin_msi_lti_tool';
19+
const TABLE_TOOL = 'plugin_ims_lti_tool';
1820

1921
public $isAdminPlugin = true;
2022

@@ -23,7 +25,7 @@ class ImsLtiPlugin extends Plugin
2325
*/
2426
protected function __construct()
2527
{
26-
$version = '1.0';
28+
$version = '1.0 (beta)';
2729
$author = 'Angel Fernando Quiroz Campos';
2830

2931
parent::__construct($version, $author, ['enabled' => 'boolean']);
@@ -56,20 +58,39 @@ public function get_name()
5658
*/
5759
public function install()
5860
{
59-
try {
60-
$this->setupDatabase();
61-
} catch (DBALException $e) {
62-
error_log('Error while installing IMS/LTI plugin: '.$e->getMessage());
61+
$pluginEntityPath = $this->getEntityPath();
62+
63+
if (!is_dir($pluginEntityPath)) {
64+
if (!is_writable(dirname($pluginEntityPath))) {
65+
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
66+
Display::addFlash(Display::return_message($message, 'error'));
67+
68+
return false;
69+
}
70+
71+
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
6372
}
73+
74+
$fs = new Filesystem();
75+
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
76+
77+
$this->createPluginTables();
6478
}
6579

6680
/**
6781
* Unistall plugin. Clear the database
6882
*/
6983
public function uninstall()
7084
{
85+
$pluginEntityPath = $this->getEntityPath();
86+
$fs = new Filesystem();
87+
88+
if ($fs->exists($pluginEntityPath)) {
89+
$fs->remove($pluginEntityPath);
90+
}
91+
7192
try {
72-
$this->clearDatabase();
93+
$this->dropPluginTables();
7394
$this->removeTools();
7495
} catch (DBALException $e) {
7596
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage());
@@ -81,7 +102,7 @@ public function uninstall()
81102
* @return boolean
82103
* @throws \Doctrine\DBAL\DBALException
83104
*/
84-
private function setupDatabase()
105+
private function createPluginTables()
85106
{
86107
$entityManager = Database::getManager();
87108
$connection = $entityManager->getConnection();
@@ -99,7 +120,7 @@ private function setupDatabase()
99120
$toolTable->addColumn('launch_url', Type::TEXT);
100121
$toolTable->addColumn('consumer_key', Type::STRING);
101122
$toolTable->addColumn('shared_secret', Type::STRING);
102-
$toolTable->addColumn('custom_params', Type::TEXT);
123+
$toolTable->addColumn('custom_params', Type::TEXT)->setNotnull(false);
103124
$toolTable->addColumn('is_global', Type::BOOLEAN);
104125
$toolTable->setPrimaryKey(['id']);
105126

@@ -117,7 +138,7 @@ private function setupDatabase()
117138
* @return boolean
118139
* @throws \Doctrine\DBAL\DBALException
119140
*/
120-
private function clearDatabase()
141+
private function dropPluginTables()
121142
{
122143
$entityManager = Database::getManager();
123144
$connection = $entityManager->getConnection();
@@ -166,14 +187,13 @@ private function setCourseSettings()
166187
* Add the course tool
167188
* @param Course $course
168189
* @param ImsLtiTool $tool
190+
* @throws \Doctrine\ORM\OptimisticLockException
169191
*/
170192
public function addCourseTool(Course $course, ImsLtiTool $tool)
171193
{
172194
$em = Database::getManager();
173-
$cToolId = AddCourse::generateToolId($course->getId());
174195
$cTool = new CTool();
175196
$cTool
176-
->setId($cToolId)
177197
->setCId($course->getId())
178198
->setName($tool->getName())
179199
->setLink($this->get_name().'/start.php?'.http_build_query(['id' => $tool->getId()]))
@@ -188,6 +208,11 @@ public function addCourseTool(Course $course, ImsLtiTool $tool)
188208

189209
$em->persist($cTool);
190210
$em->flush();
211+
212+
$cTool->setId($cTool->getIid());
213+
214+
$em->persist($cTool);
215+
$em->flush();
191216
}
192217

193218
/**
@@ -203,4 +228,12 @@ protected function getConfigExtraText()
203228

204229
return $text;
205230
}
231+
232+
/**
233+
* @return string
234+
*/
235+
public function getEntityPath()
236+
{
237+
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
238+
}
206239
}

0 commit comments

Comments
 (0)