Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
*.swo
vendor
.idea/
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
}
],
"autoload" : {
"psr-4" : { "CaT\\Ente\\" : "src" }
"psr-4" : { "CaT\\Ente\\" : ["src", "tests"] }
},
"require": {},
"require-dev" : {
"phpunit/phpunit" : "^5.6"
}
"require-dev" : {
"phpunit/phpunit" : "^5.6"
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<?php
include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
require_once(__DIR__."/../vendor/autoload.php");

/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> */

declare(strict_types=1);

require_once "./Services/Repository/classes/class.ilRepositoryObjectPlugin.php";
require_once __DIR__ . "/../vendor/autoload.php";

/**
* Plugin base class. Keeps all information the plugin needs
*/
class ilComponentHandlerExamplePlugin extends ilRepositoryObjectPlugin {
class ilComponentHandlerExamplePlugin extends ilRepositoryObjectPlugin
{
/**
* @var \ilDBInterface
* Get the name of the Plugin
*
* @return string
*/
protected $ilDB;

/**
* Get the name of the Plugin
*
* @return string
*/
function getPluginName() {
return "ComponentHandlerExample";
}
function getPluginName()
{
return "ComponentHandlerExample";
}

/**
* Defines custom uninstall action like delete table or something else
*/
protected function uninstallCustom() {
/**
* Defines custom uninstall action like delete table or something else
*/
protected function uninstallCustom()
{
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
<?php
include_once("Services/Repository/classes/class.ilObjectPlugin.php");

/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> */

declare(strict_types=1);

use CaT\Ente\Simple;
use CaT\Ente\ILIAS;

require_once "Services/Repository/classes/class.ilObjectPlugin.php";

/**
* Object of the plugin
*/
class ilObjComponentHandlerExample extends ilObjectPlugin {
use ILIAS\ilHandlerObjectHelper;
class ilObjComponentHandlerExample extends ilObjectPlugin
{
use ILIAS\ilHandlerObjectHelper;

protected function getDIC() {
return $GLOBALS["DIC"];
}
protected function getDIC()
{
return $GLOBALS["DIC"];
}

/**
* Init the type of the plugin. Same value as choosen in plugin.php
*/
public function initType() {
$this->setType("xleh");
}
/**
* Init the type of the plugin. Same value as choosen in plugin.php
*/
public function initType()
{
$this->setType("xleh");
}

/**
* Returns an array with title => string[] entries containing the strings
* provided for the object this plugin object is contained in.
*
* @return array<string,string[]>
*/
public function getProvidedStrings() {
$components = $this->getComponentsOfType(\CaT\Ente\Simple\AttachString::class);
public function getProvidedStrings() : array
{
$components = $this->getComponentsOfType(Simple\AttachString::class);

$provided_strings = [];
foreach ($components as $component) {
foreach ($components as $component) {
$provided_strings[] = $component->attachedString();
}

return $provided_strings;
}

/**
* Get the ref_id of the object this object handles components for.
*
* @return int
*/
protected function getEntityRefId() {
global $DIC;
return $DIC->repositoryTree()->getParentId($this->getRefId());
protected function getEntityRefId() : int
{
return (int)$$this->getDIC()["tree"]->getParentId($this->getRefId());
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
<?php

/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> */

declare(strict_types=1);

require_once 'Services/Repository/classes/class.ilObjectPluginAccess.php';

/**
* Access checker for each plugin object.
*/
class ilObjComponentHandlerExampleAccess extends ilObjectPluginAccess {
/**
* Checks wether a user may invoke a command or not
* (this method is called by ilAccessHandler::checkAccess)
*
* Please do not check any preconditions handled by
* ilConditionHandler here. Also don't do usual RBAC checks.
*
* @param string $a_cmd command (not permission!)
* @param string $a_permission permission
* @param int $a_ref_id reference id
* @param int $a_obj_id object id
* @param int $a_user_id user id (default is current user)
*
* @return boolean true, if everything is ok
*/
public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "") {
global $ilUser, $ilAccess;

/*
* This Routine is called within ilAccess::checkAccessOfUser::doStatusCheck.
* We rely on standart ilAccess::checkAccessOfUser procedure, i.e. return true here, except when the object is offline,
* then redirect to read-permission check.
*/
if ($a_user_id == "") {
$a_user_id = $ilUser->getId();
}

switch ($a_permission) {
case "read":
if (!self::checkOnline($a_obj_id)
&& !$ilAccess->checkAccessOfUser($a_user_id, "write", "", $a_ref_id))
{
return false;
}
}

return true;
}

/**
* Check online status of object
*/
static public function checkOnline($a_id) {
return true;
}
class ilObjComponentHandlerExampleAccess extends ilObjectPluginAccess
{
/**
* Checks wether a user may invoke a command or not
* (this method is called by ilAccessHandler::checkAccess)
*
* Please do not check any preconditions handled by
* ilConditionHandler here. Also don't do usual RBAC checks.
*
* @param string $a_cmd command (not permission!)
* @param string $a_permission permission
* @param int $a_ref_id reference id
* @param int $a_obj_id object id
* @param int $a_user_id user id (default is current user)
*
* @return boolean true, if everything is ok
*/
public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
{
global $ilUser, $ilAccess;

/*
* This Routine is called within ilAccess::checkAccessOfUser::doStatusCheck.
* We rely on standart ilAccess::checkAccessOfUser procedure, i.e. return true here, except when the object is offline,
* then redirect to read-permission check.
*/
if ($a_user_id == "") {
$a_user_id = $ilUser->getId();
}

switch ($a_permission) {
case "read":
if (self::_isOffline($a_obj_id)
&& !$ilAccess->checkAccessOfUser($a_user_id, "write", "", $a_ref_id)) {
return false;
}
}

return true;
}

/**
* Check online status of object
*/
static public function _isOffline($a_obj_id)
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<?php

require_once("./Services/Repository/classes/class.ilObjectPluginGUI.php");
require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
require_once("./Services/Form/classes/class.ilTextInputGUI.php");
/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> */

declare(strict_types=1);

require_once("./Services/Repository/classes/class.ilObjectPluginGUI.php");

/**
* Plugin object GUI class. Baseclass for all GUI action in ILIAS
*
* @ilCtrl_isCalledBy ilObjComponentHandlerExampleGUI: ilRepositoryGUI, ilAdministrationGUI, ilObjPluginDispatchGUI
* @ilCtrl_Calls ilObjComponentHandlerExampleGUI: ilPermissionGUI, ilInfoScreenGUI, ilObjectCopyGUI, ilCommonActionDispatcherGUI
*/
class ilObjComponentHandlerExampleGUI extends ilObjectPluginGUI {
class ilObjComponentHandlerExampleGUI extends ilObjectPluginGUI
{
const CMD_SHOW_CONTENT = "showContent";

/**
* @var \ilTemplate
*/
protected $ilTemplate;
protected $tpl;

/**
* @var \ILIAS\UI\Factory
Expand All @@ -27,58 +31,61 @@ class ilObjComponentHandlerExampleGUI extends ilObjectPluginGUI {
*/
protected $ui_renderer;

/**
* Called after parent constructor. It's possible to define some plugin special values
*/
protected function afterConstructor() {
/**
* Called after parent constructor. It's possible to define some plugin special values
*/
protected function afterConstructor()
{
global $DIC;
$this->ilTemplate = $DIC->ui()->mainTemplate();
$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer= $DIC->ui()->renderer();
}
$this->tpl = $DIC["tpl"];
$this->ui_factory = $DIC["ui.factory"];
$this->ui_renderer = $DIC["ui.renderer"];
}

/**
* Get type. Same value as choosen in plugin.php
*/
final function getType() {
return "xleh";
}
/**
* Get type. Same value as choosen in plugin.php
*/
final function getType()
{
return "xleh";
}

/**
* Handles all commmands of this class, centralizes permission checks
*/
function performCommand($cmd) {
switch ($cmd) {
case "showContent":
$this->ilTemplate->setContent($this->showContent());
/**
* Handles all commmands of this class, centralizes permission checks
*/
function performCommand($cmd)
{
switch ($cmd) {
case self::CMD_SHOW_CONTENT:
$this->showContent();
break;
default:
default:
throw new \InvalidArgumentException("Unknown Command: '$cmd'");
}
}
}
}

/**
* Show the edit form.
*
* @return string
*/
public function showContent() {
public function showContent()
{
$items = $this->object->getProvidedStrings();
$listing = $this->ui_factory->listing()->ordered($items);
return $this->ui_renderer->render($listing);
$this->tpl->setContent(
$this->ui_renderer->render($listing)
);
}

/**
* After object has been created -> jump to this command
*/
function getAfterCreationCmd() {
return "showContent";
}
/**
* After object has been created -> jump to this command
*/
public function getAfterCreationCmd()
{
return self::CMD_SHOW_CONTENT;
}

/**
* Get standard command
*/
function getStandardCmd() {
return "showContent";
}
/**
* Get standard command
*/
public function getStandardCmd()
{
return self::CMD_SHOW_CONTENT;
}
}
Loading