Skip to content

Commit

Permalink
Merge pull request #19 from klees/4_4_reporting
Browse files Browse the repository at this point in the history
functions to discover reports in the system
  • Loading branch information
dkloepfer committed Oct 30, 2015
2 parents a4b870a + 2c9e8fa commit a4a8569
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions Services/ReportsRepository/classes/class.ilObjReportBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,83 @@ public function setFilterAction($link) {
public function getRelevantaParameters() {
return $this->relevant_parameters;
}

// Report discovery

/**
* Get a list with object data (obj_id, title, type, description, icon_small) of all
* Report Objects in the system that are not in the trash. The id is
* the obj_id, not the ref_id.
*
* @return array
*/
static public function getReportsObjectData() {
require_once("Services/Repository/classes/class.ilRepositoryObjectPlugin.php");

global $ilPluginAdmin;

$c_type = ilRepositoryObjectPlugin::getComponentType();
$c_name = ilRepositoryObjectPlugin::getComponentName();
$slot_id = ilRepositoryObjectPlugin::getSlotId();
$plugin_names = $ilPluginAdmin->getActivePluginsForSlot($c_type, $c_name, $slot_id);

$obj_data = array();

foreach ($plugin_names as $plugin_name) {
$plugin = $ilPluginAdmin->getPluginObject($c_type, $c_name, $slot_id, $plugin_name);
assert($plugin instanceof ilRepositoryObjectPlugin);

if (!($plugin instanceof ilReportBasePlugin)) {
continue;
}

// this actually is the object type
$type = $plugin->getId();

$icon = ilRepositoryObjectPlugin::_getIcon($type, "small");

$obj_data[] = array_map(function(&$data) use (&$icon) {
// adjust data to fit the documentation.
$data["obj_id"] = $data["id"];
unset($data["id"]);
$data["icon"] = $icon;
return $data;
// second parameter is $a_omit_trash
}, ilObject::_getObjectsDataForType($type, true));
}

return call_user_func_array("array_merge", $obj_data);
}

/**
* Get a list of all reports visible to the given user. Returns a list with entries
* title.obj_id => (obj_id, title, type, description, icon). If a report is visible
* via two different ref_ids only one of those will appear in the result.
*
* @param ilObjUser $user
* @return array
*/
static public function getVisibleReportsObjectData(ilObjUser $user) {
require_once("Services/Object/classes/class.ilObject.php");

global $ilAccess;

$reports = self::getReportsObjectData();

$visible_reports = array();

foreach ($reports as $key => &$report) {
$obj_id = $report["obj_id"];
$type = $report["type"];
foreach (ilObject::_getAllReferences($report["obj_id"]) as $ref_id) {
if ($ilAccess->checkAccessOfUser($user->getId(), "read", null, $ref_id)) {//, $type, $obj_id)) {
$report["ref_id"] = $ref_id;
$visible_reports[$key] = $report;
break;
}
}
}

return $visible_reports;
}
}

0 comments on commit a4a8569

Please sign in to comment.