Skip to content

Commit

Permalink
latest changes to Modules/CmiXapi and Modules/LTIConsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
bheyser committed Nov 17, 2019
1 parent 77ff17d commit 797013e
Show file tree
Hide file tree
Showing 50 changed files with 3,010 additions and 356 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */

/**
* List all completed course for current user
*
* @author Uwe Kohnle <[email protected]>
* @author Björn Heyser <[email protected]>
* @author Stefan Schneider <[email protected]>
*
* @package Module/CmiXapi
*/
class ilCmiXapiVerificationTableGUI extends ilTable2GUI
{
/**
* Constructor
*
* @param ilObject $a_parent_obj
* @param string $a_parent_cmd
*/
public function __construct($a_parent_obj, $a_parent_cmd = "")
{
global $ilCtrl;

parent::__construct($a_parent_obj, $a_parent_cmd);

$this->addColumn($this->lng->txt("title"), "title");
$this->addColumn($this->lng->txt("passed"), "passed");
$this->addColumn($this->lng->txt("action"), "");

$this->setTitle($this->lng->txt("cmxv_create"));
$this->setDescription($this->lng->txt("cmxv_create_info"));

$this->setRowTemplate("tpl.cmix_verification_row.html", "Modules/CmiXapi");
$this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));

$this->getItems();
}

/**
* Get all completed tests
*/
protected function getItems()
{
global $DIC; /* @var \ILIAS\DI\Container $DIC */

$data = array();

$obj_ids = ilCmiXapiUser::lookupObjectIds($DIC->user()->getId(), 'cmix');

if($obj_ids)
{
foreach($obj_ids as $obj_id)
{
if(ilCmiXapiCertificateAdapater::hasCurrentUserCertificate($obj_id))
{
/* @var ilObjCmiXapi $object */
$object = ilObjectFactory::getInstanceByObjId($obj_id);

$adapter = new ilCmiXapiCertificateAdapater($object);
if(ilCertificate::_isComplete($adapter))
{
$data[] = array("id" => $obj_id,
"title" => ilObject::_lookupTitle($obj_id),
"passed" => true);
}
}
}
}

$this->setData($data);
}

/**
* Fill template row
*
* @param array $a_set
*/
protected function fillRow($a_set)
{
global $ilCtrl;

$this->tpl->setVariable("TITLE", $a_set["title"]);
$this->tpl->setVariable("PASSED", ($a_set["passed"]) ? $this->lng->txt("yes") :
$this->lng->txt("no"));

if($a_set["passed"])
{
$ilCtrl->setParameter($this->parent_obj, "cmix_id", $a_set["id"]);
$action = $ilCtrl->getLinkTarget($this->parent_obj, "save");
$this->tpl->setVariable("URL_SELECT", $action);
$this->tpl->setVariable("TXT_SELECT", $this->lng->txt("select"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */


/**
* Class ilObjCmiXapiVerfication
*
* @author Uwe Kohnle <[email protected]>
* @author Björn Heyser <[email protected]>
* @author Stefan Schneider <[email protected]>
*
* @package Module/CmiXapi
*/
class ilObjCmiXapiVerification extends ilVerificationObject
{
protected function initType()
{
$this->type = "cmxv";
}

protected function getPropertyMap()
{
return array("issued_on" => self::TYPE_DATE,
"file" => self::TYPE_STRING
);
}

/**
* Import relevant properties from given course
*
* @param ilObjCourse $a_course
* @return object
*/
public static function createFromObject(ilObjCmiXapi $object, $a_user_id)
{
global $lng;

$lng->loadLanguageModule("cmix");

$newObj = new self();
$newObj->setTitle($object->getTitle());
$newObj->setDescription($object->getDescription());

// create certificate
include_once "Services/Certificate/classes/class.ilCertificate.php";
include_once "Modules/Course/classes/class.ilCourseCertificateAdapter.php";
$certificate = new ilCertificate(new ilCmiXapiCertificateAdapater($object));
$certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false);

// save pdf file
if($certificate)
{
// we need the object id for storing the certificate file
$newObj->create();

$path = self::initStorage($newObj->getId(), "certificate");

$file_name = "cmix_".$object->getId()."_".$a_user_id.".pdf";
if(file_put_contents($path.$file_name, $certificate))
{
$newObj->setProperty("file", $file_name);
$newObj->update();

return $newObj;
}

// file creation failed, so remove to object, too
$newObj->delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */


/**
* Class ilObjCmiXapiVerficationAccess
*
* @author Uwe Kohnle <[email protected]>
* @author Björn Heyser <[email protected]>
* @author Stefan Schneider <[email protected]>
*
* @package Module/CmiXapi
*/
class ilObjCmiXapiVerificationAccess extends ilObjectAccess
{
static function _getCommands()
{
$commands = array();
$commands[] = array("permission" => "read", "cmd" => "view", "lang_var" => "show", "default" => true);
return $commands;
}

static function _checkGoto($a_target)
{
global $ilAccess;

$t_arr = explode("_", $a_target);

// #11021
// personal workspace context: do not force normal login
if(isset($t_arr[2]) && $t_arr[2] == "wsp")
{
include_once "Services/PersonalWorkspace/classes/class.ilSharedResourceGUI.php";
return ilSharedResourceGUI::hasAccess($t_arr[1]);
}

if ($ilAccess->checkAccess("read", "", $t_arr[1]))
{
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */


/**
* Class ilObjCmiXapiVerficationGUI
*
* @author Uwe Kohnle <[email protected]>
* @author Björn Heyser <[email protected]>
* @author Stefan Schneider <[email protected]>
*
* @package Module/CmiXapi
*/
class ilObjCmiXapiVerificationGUI extends ilObject2GUI
{
public function getType()
{
return "cmxv";
}

/**
* List all tests in which current user participated
*/
public function create()
{
global $ilTabs;

if($this->id_type == self::WORKSPACE_NODE_ID)
{
include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
if(!ilDiskQuotaHandler::isUploadPossible())
{
$this->lng->loadLanguageModule("file");
ilUtil::sendFailure($this->lng->txt("personal_workspace_quota_exceeded_warning"), true);
$this->ctrl->redirect($this, "cancel");
}
}

$this->lng->loadLanguageModule("cmxv");

$ilTabs->setBackTarget($this->lng->txt("back"),
$this->ctrl->getLinkTarget($this, "cancel"));

include_once "Modules/Course/classes/Verification/class.ilCourseVerificationTableGUI.php";
$table = new ilCmiXapiVerificationTableGUI($this, "create");
$this->tpl->setContent($table->getHTML());
}

/**
* create new instance and save it
*/
public function save()
{
global $ilUser;

$objId = $_REQUEST["cmix_id"];
if($objId)
{
$object = new ilObjCmiXapi($objId, false);

$newObj = ilObjCmiXapiVerification::createFromObject($object, $ilUser->getId());

if($newObj)
{
$parent_id = $this->node_id;
$this->node_id = null;
$this->putObjectInTree($newObj, $parent_id);

$this->afterSave($newObj);
}
else
{
ilUtil::sendFailure($this->lng->txt("msg_failed"));
}
}
else
{
ilUtil::sendFailure($this->lng->txt("select_one"));
}

$this->create();
}

public function deliver()
{
$file = $this->object->getFilePath();

if($file)
{
ilUtil::deliverFile($file, $this->object->getTitle().".pdf");
}
}

/**
* Render content
*
* @param bool $a_return
* @param string $a_url
*/
public function render($a_return = false, $a_url = false)
{
global $ilUser, $lng;

if(!$a_return)
{
$this->deliver();
}
else
{
$tree = new ilWorkspaceTree($ilUser->getId());
$wsp_id = $tree->lookupNodeId($this->object->getId());

$caption = $lng->txt("wsp_type_cmxv").' "'.$this->object->getTitle().'"';

$valid = true;
if(!file_exists($this->object->getFilePath()))
{
$valid = false;
$message = $lng->txt("url_not_found");
}
else if(!$a_url)
{
include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
$access_handler = new ilWorkspaceAccessHandler($tree);
if(!$access_handler->checkAccess("read", "", $wsp_id))
{
$valid = false;
$message = $lng->txt("permission_denied");
}
}

if($valid)
{
if(!$a_url)
{
$a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId());
}
return '<div><a href="'.$a_url.'">'.$caption.'</a></div>';
}
else
{
return '<div>'.$caption.' ('.$message.')</div>';
}
}
}

function downloadFromPortfolioPage(ilPortfolioPage $a_page)
{
global $ilErr;

include_once "Services/COPage/classes/class.ilPCVerification.php";
if(ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId()))
{
$this->deliver();
}

$ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
}

public static function _goto($a_target)
{
$id = explode("_", $a_target);

$_GET["baseClass"] = "ilsharedresourceGUI";
$_GET["wsp_id"] = $id[0];
include("ilias.php");
exit;
}
}
Loading

0 comments on commit 797013e

Please sign in to comment.