Skip to content

Commit

Permalink
Merge pull request #4 from studer-raimann/5_2_members
Browse files Browse the repository at this point in the history
implemented flat table for orgu_pathes
  • Loading branch information
smeyer-ilias authored Aug 25, 2016
2 parents 8a2c765 + 8e23232 commit 60266f4
Show file tree
Hide file tree
Showing 18 changed files with 645 additions and 127 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ libs/.gitignore
# Generated Files
/ilias.ini.php
/ilias.log
db_template_writer.php
/db_template_writer.php
/setup/sql/dbupdate_custom.php

# Directories
/data
Expand All @@ -31,5 +32,3 @@ virtual-data
/dicto/results/*
!/dicto/results/README.md
override.php

.svn
234 changes: 234 additions & 0 deletions Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<?php
require_once('./Services/ActiveRecord/class.ActiveRecord.php');

/**
* Class ilOrgUnitPathStorage
*
* @author Fabian Schmid <[email protected]>
*/
class ilOrgUnitPathStorage extends ActiveRecord {

const GLUE = ' > ';
const GLUE_SIMPLE = ' - ';
/**
* @var int
*
* @con_is_primary true
* @con_is_unique true
* @con_has_field true
* @con_fieldtype integer
* @con_length 8
*/
protected $ref_id = 0;
/**
* @var int
*
* @con_has_field true
* @con_fieldtype integer
* @con_length 8
*/
protected $obj_id = 0;
/**
* @var string
*
* @con_has_field true
* @con_fieldtype clob
*/
protected $path = '';
/**
* @var array
*/
protected static $orgu_names = array();


/**
* @return array
*/
public static function getAllOrguRefIds() {
$names = self::getAllOrguNames();

return array_keys($names);
}


public function store() {
if (self::where(array( 'ref_id' => $this->getRefId() ))->hasSets()) {
$this->update();
} else {
$this->create();
}
}


/**
* Format comma seperated ref_ids into comma seperated string representation (also filters out deleted orgunits).
* Return "-" if $string is empty
*
* @param int $user_id
*
* @return string comma seperated string representations of format: [OrgUnit Title] - [OrgUnits corresponding Level 1 Title]
*/
public static function getTextRepresentationOfUsersOrgUnits($user_id) {
$array_of_org_ids = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id);

if (!$array_of_org_ids) {
return '-';
}
require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
$paths = ilOrgUnitPathStorage::where(array( 'ref_id' => $array_of_org_ids ))->getArray(null, 'path');

return implode(", ", $paths);
}


/**
* @param $ref_id
* @return bool
*/
public static function writePathByRefId($ref_id) {
require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
$original_ref_id = $ref_id;
$names = self::getAllOrguNames();
$root_ref_id = ilObjOrgUnit::getRootOrgRefId();
$tree = ilObjOrgUnitTree::_getInstance();
$path = array( $names[$ref_id] );
if ($ref_id == $root_ref_id || !$ref_id) {
return false;
}
while ($ref_id != $root_ref_id && $ref_id) {
$ref_id = $tree->getParent($ref_id);
if ($ref_id != $root_ref_id && $names[$ref_id]) {
$path[] = $names[$ref_id];
}
}

$expression = reset($path) . self::GLUE_SIMPLE . end($path);
/**
* @var $ilOrgUnitPathStorage ilOrgUnitPathStorage
*/
$ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
$ilOrgUnitPathStorage->setRefId($original_ref_id);
$ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
$ilOrgUnitPathStorage->setPath($expression);
$ilOrgUnitPathStorage->store();

return true;
}

/**
* @param $ref_id
* @return bool
* @currently_unused
*/
protected static function writeFullPathByRefId($ref_id) {
require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
$original_ref_id = $ref_id;
$names = self::getAllOrguNames();
$root_ref_id = ilObjOrgUnit::getRootOrgRefId();
$tree = ilObjOrgUnitTree::_getInstance();
$path = array( $names[$ref_id] );
if ($ref_id == $root_ref_id || !$ref_id) {
return false;
}
while ($ref_id != $root_ref_id && $ref_id) {
$ref_id = $tree->getParent($ref_id);
if ($ref_id != $root_ref_id && $names[$ref_id]) {
$path[] = $names[$ref_id];
}
}

$path = array_reverse($path);

$expression = implode(self::GLUE, $path);
/**
* @var $ilOrgUnitPathStorage ilOrgUnitPathStorage
*/
$ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
$ilOrgUnitPathStorage->setRefId($original_ref_id);
$ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
$ilOrgUnitPathStorage->setPath($expression);
$ilOrgUnitPathStorage->store();

return true;
}



/**
* @param null $lng_key
* @return array
*/
public static function getAllOrguNames($lng_key = null) {
if (count(self::$orgu_names) == 0) {
global $DIC;
/**
* @var ilDBInterface $ilDB
*/
$ilDB = $DIC['ilDB'];
$res = $ilDB->queryF('SELECT * FROM object_reference
JOIN object_data ON object_reference.obj_id = object_data.obj_id
WHERE object_data.type = %s', array( 'text' ), array( 'orgu' ));
while ($data = $ilDB->fetchObject($res)) {
self::$orgu_names[$data->ref_id] = $data->title;
}
}

return self::$orgu_names;
}


/**
* @return string
*/
public function getConnectorContainerName() {
return 'orgu_path_storage';
}


/**
* @return int
*/
public function getRefId() {
return $this->ref_id;
}


/**
* @param int $ref_id
*/
public function setRefId($ref_id) {
$this->ref_id = $ref_id;
}


/**
* @return string
*/
public function getPath() {
return $this->path;
}


/**
* @param string $path
*/
public function setPath($path) {
$this->path = $path;
}


/**
* @return int
*/
public function getObjId() {
return $this->obj_id;
}


/**
* @param int $obj_id
*/
public function setObjId($obj_id) {
$this->obj_id = $obj_id;
}
}
11 changes: 10 additions & 1 deletion Modules/OrgUnit/classes/Staff/class.ilOrgUnitStaffGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ public function addStaff() {
} else {
throw new Exception("The post request didn't specify wether the user_ids should be assigned to the employee or the superior role.");
}

ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
$this->ctrl->redirect($this,"showStaff");
}


public function addOtherRoles() {
if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
Expand Down Expand Up @@ -377,11 +377,16 @@ function confirmRemoveUser($cmd) {
}

public function removeFromSuperiors() {

if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
$this->ctrl->redirect($this->parent_gui, "");
}
$this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
//if user is neither employee nor superior, remove orgunit from user->org_units
if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getEmployeeRole())) {
ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
}
ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
$this->ctrl->redirect($this, "showStaff");
}
Expand All @@ -393,6 +398,10 @@ public function removeFromEmployees() {
$this->ctrl->redirect($this->parent_gui, "");
}
$this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
//if user is neither employee nor superior, remove orgunit from user->org_units
if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getSuperiorRole())) {
ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
}
ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
$this->ctrl->redirect($this, "showStaff");
}
Expand Down
Loading

0 comments on commit 60266f4

Please sign in to comment.