From c01e6c242e9874d552ce28f1b975adf06516b94f Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 22 Apr 2017 10:52:31 +0200 Subject: [PATCH] added accountContainer when getting PDF fields --- lam/lib/baseModule.inc | 43 +----------------------------------------- lam/lib/modules.inc | 37 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 55 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 0aa59b86..b84dab78 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -762,49 +762,8 @@ abstract class baseModule { /** * Returns a hashtable with all entries that may be printed out in the PDF. * - * Calling this method does not require the existence of an enclosing {@link accountContainer}.
- *
- * This method must be overwritten in case that there are non static values - * to be returned. The $this->meta['PDF_fields'] array may be used for static content.
- *
- * Format of returned hashtable:
- *
- * This function uses XML formatted commands to define the PDF output. Each part in the PDF - * document is surrounded by "" and "".
- * Inside the tags there are different ways to format the output: - * - * Special commands: - * - *
- * Examples:
- *
- * Simple name+value lines:

- * In most cases you will just want to display a single line per attribute with its name and value.
- *
- * 'myAttribute' => 'AttrName12345'
- *
- * This will give the following PDF output:
- *
- * Attribute name: 12345
- *
- *
- * Multiline values:

- * Sometimes you have multivalued attributes where it is not applicable to write all values in one line but - * where you want to list your values one below the other or show a table. This can be done by using the tag.
- *
- * This example only uses one column but you can just use more tags per tag to display more columns.
- *
- * 'myAttribute' => 'AttrName123456789' - * * @param string $typeId type id (user, group, host) - * @return array PDF entries + * @return array PDF entries as key => label * * @see baseModule::get_metaData() */ diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 0def3e64..a24350fa 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -409,25 +409,29 @@ function getHelp($module,$helpID,$scope='') { * @return array PDF entries (field ID => field label) */ function getAvailablePDFFields($typeId) { - $mods = $_SESSION['config']->get_AccountModules($typeId); + $typeManager = new TypeManager(); + $_SESSION['pdfContainer'] = new accountContainer($typeManager->getConfiguredType($typeId), 'pdfContainer'); + $_SESSION['pdfContainer']->initModules(); + $mods = $_SESSION['pdfContainer']->getAccountModules(); $return = array(); - for ($i = 0; $i < sizeof($mods); $i++) { - $module = moduleCache::getModule($mods[$i], \LAM\TYPES\getScopeFromTypeId($typeId)); + foreach ($mods as $module) { $fields = $module->get_pdfFields($typeId); - $return[$mods[$i]] = array(); + $moduleName = get_class($module); + $return[$moduleName] = array(); if (is_array($fields)) { foreach ($fields as $fieldID => $fieldLabel) { if (is_integer($fieldID)) { // support old PDF field list which did not contain a label - $return[$mods[$i]][$fieldLabel] = $fieldLabel; + $return[$moduleName][$fieldLabel] = $fieldLabel; } else { - $return[$mods[$i]][$fieldID] = $fieldLabel; + $return[$moduleName][$fieldID] = $fieldLabel; } } } } $return['main'] = array('dn' => _('DN')); + unset($_SESSION['pdfContainer']); return $return; } @@ -803,7 +807,7 @@ class accountContainer { /** * Returns the included account modules. * - * @return array modules + * @return baseModule[] modules */ function getAccountModules() { return $this->module; @@ -1699,15 +1703,11 @@ class accountContainer { /** * This function will prepare the object for a new account. */ - function new_account() { + public function new_account() { logNewMessage(LOG_DEBUG, "New account with type " . $this->type->getId()); $this->isNewAccount = true; $this->lastLoadedProfile = 'default'; - $modules = $_SESSION['config']->get_AccountModules($this->type->getId()); - foreach ($modules as $module) { - $this->module[$module] = new $module($this->type->getScope()); - $this->module[$module]->init($this->base); - } + $this->initModules(); // sort module buttons $this->sortModules(); $profile = \LAM\PROFILES\loadAccountProfile('default', $this->type->getId()); @@ -1729,6 +1729,17 @@ class accountContainer { return 0; } + /** + * Creates the account modules and initializes them. + */ + public function initModules() { + $modules = $_SESSION['config']->get_AccountModules($this->type->getId()); + foreach ($modules as $module) { + $this->module[$module] = new $module($this->type->getScope()); + $this->module[$module]->init($this->base); + } + } + /** * This function will save an account to the LDAP database. *