parent
20482534a3
commit
002b907867
@ -0,0 +1,221 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\PluginBundle\Entity\ImsLti; |
||||||
|
|
||||||
|
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") |
||||||
|
*/ |
||||||
|
private $consumerKey = ''; |
||||||
|
/** |
||||||
|
* @var string |
||||||
|
* |
||||||
|
* @ORM\Column(name="shared_secret", type="string") |
||||||
|
*/ |
||||||
|
private $sharedSecret = ''; |
||||||
|
/** |
||||||
|
* @var string|null |
||||||
|
* |
||||||
|
* @ORM\Column(name="custom_params", type="text", nullable=true) |
||||||
|
*/ |
||||||
|
private $customParams = null; |
||||||
|
/** |
||||||
|
* @var bool |
||||||
|
* |
||||||
|
* @ORM\Column(name="is_global", type="boolean") |
||||||
|
*/ |
||||||
|
private $isGlobal = false; |
||||||
|
|
||||||
|
/** |
||||||
|
* @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->isGlobal; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param bool $isGlobal |
||||||
|
* @return ImsLtiTool |
||||||
|
*/ |
||||||
|
public function setIsGlobal($isGlobal) |
||||||
|
{ |
||||||
|
$this->isGlobal = $isGlobal; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function parseCustomParams() |
||||||
|
{ |
||||||
|
$strings = explode($this->customParams, "\n"); |
||||||
|
$pairs = explode('=', $strings); |
||||||
|
|
||||||
|
return [ |
||||||
|
'key' => 'custom_'.$pairs[0], |
||||||
|
'value' => $pairs[1] |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,185 +0,0 @@ |
|||||||
<?php |
|
||||||
/* For license terms, see /license.txt */ |
|
||||||
/** |
|
||||||
* ImsLtiTool |
|
||||||
* |
|
||||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> |
|
||||||
*/ |
|
||||||
class ImsLtiTool |
|
||||||
{ |
|
||||||
private $id = 0; |
|
||||||
private $name = ''; |
|
||||||
private $description = null; |
|
||||||
private $launchUrl = ''; |
|
||||||
private $consumerKey = ''; |
|
||||||
private $sharedSecret = ''; |
|
||||||
private $customParams = null; |
|
||||||
private $isGlobal = false; |
|
||||||
|
|
||||||
public function getId() |
|
||||||
{ |
|
||||||
return $this->id; |
|
||||||
} |
|
||||||
|
|
||||||
public function getName() |
|
||||||
{ |
|
||||||
return $this->name; |
|
||||||
} |
|
||||||
|
|
||||||
public function getDescription() |
|
||||||
{ |
|
||||||
return $this->description; |
|
||||||
} |
|
||||||
|
|
||||||
public function getLaunchUrl() |
|
||||||
{ |
|
||||||
return $this->launchUrl; |
|
||||||
} |
|
||||||
|
|
||||||
public function getConsumerKey() |
|
||||||
{ |
|
||||||
return $this->consumerKey; |
|
||||||
} |
|
||||||
|
|
||||||
public function getSharedSecret() |
|
||||||
{ |
|
||||||
return $this->sharedSecret; |
|
||||||
} |
|
||||||
|
|
||||||
public function getCustomParams() |
|
||||||
{ |
|
||||||
return $this->customParams; |
|
||||||
} |
|
||||||
|
|
||||||
public function setId($id) |
|
||||||
{ |
|
||||||
$this->id = $id; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setName($name) |
|
||||||
{ |
|
||||||
$this->name = $name; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setDescription($description) |
|
||||||
{ |
|
||||||
$this->description = $description; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setLaunchUrl($launchUrl) |
|
||||||
{ |
|
||||||
$this->launchUrl = $launchUrl; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setConsumerKey($consumerKey) |
|
||||||
{ |
|
||||||
$this->consumerKey = $consumerKey; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setSharedSecret($sharedSecret) |
|
||||||
{ |
|
||||||
$this->sharedSecret = $sharedSecret; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function setCustomParams($customParams) |
|
||||||
{ |
|
||||||
$this->customParams = $customParams; |
|
||||||
|
|
||||||
return $this; |
|
||||||
} |
|
||||||
|
|
||||||
public function save() |
|
||||||
{ |
|
||||||
$parameters = [ |
|
||||||
'name' => $this->name, |
|
||||||
'description' => $this->description, |
|
||||||
'launch_url' => $this->launchUrl, |
|
||||||
'consumer_key' => $this->consumerKey, |
|
||||||
'shared_secret' => $this->sharedSecret, |
|
||||||
'custom_params' => $this->customParams, |
|
||||||
'is_global' => $this->isGlobal |
|
||||||
]; |
|
||||||
|
|
||||||
if (!empty($this->id)) { |
|
||||||
Database::update( |
|
||||||
ImsLtiPlugin::TABLE_TOOL, |
|
||||||
$parameters, |
|
||||||
['id' => $this->id] |
|
||||||
); |
|
||||||
|
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
$this->id = Database::insert(ImsLtiPlugin::TABLE_TOOL, $parameters); |
|
||||||
} |
|
||||||
|
|
||||||
public static function fetch($id) |
|
||||||
{ |
|
||||||
$result = Database::select( |
|
||||||
'*', |
|
||||||
ImsLtiPlugin::TABLE_TOOL, |
|
||||||
['where' => [ |
|
||||||
'id = ?' => intval($id) |
|
||||||
]], |
|
||||||
'first' |
|
||||||
); |
|
||||||
|
|
||||||
if (empty($result)) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
$tool = new self(); |
|
||||||
$tool->id = $result['id']; |
|
||||||
$tool->name = $result['name']; |
|
||||||
$tool->description = $result['description']; |
|
||||||
$tool->launchUrl = $result['launch_url']; |
|
||||||
$tool->consumerKey = $result['consumer_key']; |
|
||||||
$tool->sharedSecret = $result['shared_secret']; |
|
||||||
$tool->customParams = $result['custom_params']; |
|
||||||
$tool->isGlobal = (boolean) $result['is_global']; |
|
||||||
|
|
||||||
return $tool; |
|
||||||
} |
|
||||||
|
|
||||||
public static function fetchAll() |
|
||||||
{ |
|
||||||
return Database::select( |
|
||||||
'*', |
|
||||||
ImsLtiPlugin::TABLE_TOOL |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
public function parseCustomParams() |
|
||||||
{ |
|
||||||
$strings = $this->customParams; |
|
||||||
|
|
||||||
$foo = explode('=', $strings); |
|
||||||
|
|
||||||
return [ |
|
||||||
'key' => 'custom_'.$foo[0], |
|
||||||
'value' => $foo[1] |
|
||||||
]; |
|
||||||
} |
|
||||||
|
|
||||||
public function setIsGlobal($isGlobal = true) |
|
||||||
{ |
|
||||||
$this->isGlobal = $isGlobal; |
|
||||||
} |
|
||||||
|
|
||||||
public function isGlobal() |
|
||||||
{ |
|
||||||
return $this->isGlobal; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,6 +1,29 @@ |
|||||||
<?php |
<?php |
||||||
/* For license terms, see /license.txt */ |
/* For license terms, see /license.txt */ |
||||||
|
|
||||||
|
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||||
|
|
||||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||||
|
|
||||||
$plugin = ImsLtiPlugin::create(); |
$plugin = ImsLtiPlugin::create(); |
||||||
|
|
||||||
|
api_protect_admin_script(); |
||||||
|
|
||||||
|
$em = Database::getManager(); |
||||||
|
|
||||||
|
/** @var ImsLtiTool $tool */ |
||||||
|
$tool = isset($_GET['id']) ? $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', intval($_GET['id'])) : 0; |
||||||
|
|
||||||
|
if (!$tool) { |
||||||
|
api_not_allowed(true); |
||||||
|
} |
||||||
|
|
||||||
|
$em->remove($tool); |
||||||
|
$em->flush(); |
||||||
|
|
||||||
|
Display::addFlash( |
||||||
|
Display::return_message($plugin->get_lang('ToolDeleted'), 'success') |
||||||
|
); |
||||||
|
|
||||||
|
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); |
||||||
|
exit; |
||||||
|
|||||||
@ -1,3 +1,6 @@ |
|||||||
|
{% if tool.description %} |
||||||
|
<p class="lead">{{ tool.description }}</p> |
||||||
|
{% endif %} |
||||||
<div class="embed-responsive embed-responsive-16by9"> |
<div class="embed-responsive embed-responsive-16by9"> |
||||||
<iframe src="{{ launch_url }}" class="plugin-ims-lti-iframe"></iframe> |
<iframe src="{{ launch_url }}" class="plugin-ims-lti-iframe"></iframe> |
||||||
</div> |
</div> |
||||||
|
|||||||
Loading…
Reference in new issue