PHPDoc and cosmetics

This commit is contained in:
Roland Gruber 2012-03-04 17:53:40 +00:00
parent 84dfcb203f
commit b059cc54f3
2 changed files with 88 additions and 42 deletions

View File

@ -186,7 +186,7 @@ class asteriskExtensionNewUI extends baseModule {
$this->messages['AstApplication'][0] = array('ERROR', _('Please enter the application.')); $this->messages['AstApplication'][0] = array('ERROR', _('Please enter the application.'));
$this->messages['AstApplication'][1] = array('ERROR', _('Number of applications and application data in bulk upload is not the same.')); $this->messages['AstApplication'][1] = array('ERROR', _('Number of applications and application data in bulk upload is not the same.'));
$this->messages['AstApplicationData'][0] = array('ERROR', _('Please enter the application data.')); $this->messages['AstApplicationData'][0] = array('ERROR', _('Please enter the application data.'));
$this->messages['AstContext'][0] = array('ERROR', _('Please enter the extension context.')); $this->messages['AstContext'][0] = array('ERROR', _('Please enter the account context.'));
$this->messages['AstExtension'][0] = array('ERROR', _('Please enter the extension name.')); $this->messages['AstExtension'][0] = array('ERROR', _('Please enter the extension name.'));
$this->messages['AstExtension'][1] = array('ERROR', _('Extension with this name is already exists.')); $this->messages['AstExtension'][1] = array('ERROR', _('Extension with this name is already exists.'));
$this->messages['AstPriority'][0] = array('ERROR', _('Please enter the priority.')); $this->messages['AstPriority'][0] = array('ERROR', _('Please enter the priority.'));
@ -201,8 +201,6 @@ class asteriskExtensionNewUI extends baseModule {
* @return htmlElement HTML meta data * @return htmlElement HTML meta data
*/ */
function display_html_attributes() { function display_html_attributes() {
$return = new htmlTable(); $return = new htmlTable();
$extName = ''; $extName = '';
@ -226,10 +224,11 @@ class asteriskExtensionNewUI extends baseModule {
return $return; return $return;
} }
/* /**
* if necessary this function prints managment elements to manipulate owners of an extension. * This function prints management elements to manipulate owners of an extension.
*
* @param htmlTable container
*/ */
function render_exten_owners_set_controls($renderContainer) { function render_exten_owners_set_controls($renderContainer) {
$renderContainer->addElement(new htmlOutputText(_("Extension owners") . '*')); $renderContainer->addElement(new htmlOutputText(_("Extension owners") . '*'));
$renderContainer->addElement(new htmlAccountPageButton(get_class($this), 'user', 'open', _('Change'))); $renderContainer->addElement(new htmlAccountPageButton(get_class($this), 'user', 'open', _('Change')));
@ -248,10 +247,13 @@ class asteriskExtensionNewUI extends baseModule {
$renderContainer->addElement($ownerList); $renderContainer->addElement($ownerList);
} }
/**
* Loads all related extension entries.
*
* @param String $extension extension name
*/
function load_extension_parts($extension) { function load_extension_parts($extension) {
if (!isset($this->extensionRows[0]['astcontext'][0])) { if (!isset($this->extensionRows[0]['astcontext'][0])) {
//$entries = searchLDAPByAttribute("AstExtension", $extension, $searchClass, array('cn', 'AstContext', 'AstPriority',
// 'AstApplication', 'AstApplicationData', 'AstExtension', 'member', 'ObjectClass'), array($searchScope));
$entries = searchLDAP($this->getAccountContainer()->dnSuffix, '(&(objectClass=AsteriskExtension)(AstExtension=' . $extension . '))', array('cn', 'AstContext', 'AstPriority', $entries = searchLDAP($this->getAccountContainer()->dnSuffix, '(&(objectClass=AsteriskExtension)(AstExtension=' . $extension . '))', array('cn', 'AstContext', 'AstPriority',
'AstApplication', 'AstApplicationData', 'AstExtension', 'member', 'ObjectClass')); 'AstApplication', 'AstApplicationData', 'AstExtension', 'member', 'ObjectClass'));
@ -267,19 +269,17 @@ class asteriskExtensionNewUI extends baseModule {
return $entries; return $entries;
} }
/* /**
* Get array of arrays of such form * Generates the meta HTML for the rules.
* [0: ['AstContext': "default", 'AstPriority': 1, 'AstApplicationData': 'Sip'] *
* 1:... * @param String $extension extension name
* ] * @param htmlTable $renderContainer container
*/ */
function render_extensions_by_priority($extension, $renderContainer) { function render_extensions_by_priority($extension, $renderContainer) {
if (!isset($extension) || $extension == "") { if (!isset($extension) || $extension == "") {
$extension = ""; $extension = "";
} }
$entries = $this->load_extension_parts($extension); $entries = $this->load_extension_parts($extension);
if ($this->getAccountContainer()->isNewAccount) { if ($this->getAccountContainer()->isNewAccount) {
@ -301,7 +301,7 @@ class asteriskExtensionNewUI extends baseModule {
//LOAD context from attributes, this is treak to deal with profile //LOAD context from attributes, this is treak to deal with profile
$accountContext = $this->attributes['AstContext'][0]; $accountContext = $this->attributes['AstContext'][0];
} }
$accountContextInput = new htmlTableExtendedInputField(_("Extension context"), 'AstContext', $accountContext, 'AstContext'); $accountContextInput = new htmlTableExtendedInputField(_("Account context"), 'AstContext', $accountContext, 'AstContext');
$accountContextInput->setRequired(true); $accountContextInput->setRequired(true);
$renderContainer->addElement($accountContextInput, true); $renderContainer->addElement($accountContextInput, true);
@ -349,8 +349,14 @@ class asteriskExtensionNewUI extends baseModule {
$renderContainer->addElement(new htmlButton("add_rule", _('Add another rule')), true); $renderContainer->addElement(new htmlButton("add_rule", _('Add another rule')), true);
} }
/**
* Generates the meta HTML for a single rule.
*
* @param array $extensLine attributes of rule
* @param int $placeInList rule position
* @param htmlTable $renderContainer container
*/
function render_extension($extensLine, $placeInList, $renderContainer) { function render_extension($extensLine, $placeInList, $renderContainer) {
// application // application
$application = ''; $application = '';
if (isset($extensLine['astapplication'][0])) { if (isset($extensLine['astapplication'][0])) {
@ -507,7 +513,11 @@ class asteriskExtensionNewUI extends baseModule {
return array(); return array();
} }
/**
* Returns if the extension was moved to another OU.
*
* @return boolean true if moved
*/
function isMoveToNewSuffix(){ function isMoveToNewSuffix(){
$orig_suffix = extractDNSuffix($this->getAccountContainer()->dn_orig); $orig_suffix = extractDNSuffix($this->getAccountContainer()->dn_orig);
if (strcmp($orig_suffix, $this->getAccountContainer()->dnSuffix) != 0 && !$this->getAccountContainer()->isNewAccount){ if (strcmp($orig_suffix, $this->getAccountContainer()->dnSuffix) != 0 && !$this->getAccountContainer()->isNewAccount){
@ -519,7 +529,9 @@ class asteriskExtensionNewUI extends baseModule {
/** /**
* Return true if even one owner is set and false otherwise * Returns true if at least one owner is set and false otherwise
*
* @return boolean true if one or more owners
*/ */
function isExtensionOwnerSet(){ function isExtensionOwnerSet(){
if ( sizeof($this->extensionOwners) > 0 ) { if ( sizeof($this->extensionOwners) > 0 ) {
@ -529,9 +541,9 @@ class asteriskExtensionNewUI extends baseModule {
} }
/** /**
* Write variables into object and do some regex checks * Writes variables into object and does some regex checks.
* *
* @param array $_POST HTTP-POST values * @return array error messages
*/ */
function process_attributes() { function process_attributes() {
$errors = array(); $errors = array();
@ -573,13 +585,20 @@ class asteriskExtensionNewUI extends baseModule {
$errors = array_merge($errors, $extrow_errors); $errors = array_merge($errors, $extrow_errors);
} }
} else { } else {
//find new not taken extension name //find new free extension name
$this->extensionRows[0]['astextension'][0] = $this->generateNextExtensionName(); $this->extensionRows[0]['astextension'][0] = $this->generateNextExtensionName();
} }
return $errors; return $errors;
} }
/**
* Processes the rule data.
*
* @param String $extensionName extension name
* @param String $extensionContext extension context
* @return array error messages
*/
function processExtensionRows($extensionName, $extensionContext) { function processExtensionRows($extensionName, $extensionContext) {
$errors = array(); $errors = array();
if (isset($_POST['extension_rows']) && get_preg($_POST['extension_rows'], 'digit')) { if (isset($_POST['extension_rows']) && get_preg($_POST['extension_rows'], 'digit')) {
@ -618,7 +637,7 @@ class asteriskExtensionNewUI extends baseModule {
return $errors; return $errors;
} }
/* /**
* Set extension owner as current logged in user. * Set extension owner as current logged in user.
*/ */
function setDefaultExtensionOwner(){ function setDefaultExtensionOwner(){
@ -627,21 +646,28 @@ class asteriskExtensionNewUI extends baseModule {
$this->attributes['member'] = array($login); $this->attributes['member'] = array($login);
} }
/**
* Returns the default extension owner.
*
* @return String owner
*/
function getDefaultExtensionOwner(){ function getDefaultExtensionOwner(){
$credentials = $_SESSION['ldap']->decrypt_login(); $credentials = $_SESSION['ldap']->decrypt_login();
$login = $credentials[0]; $login = $credentials[0];
return $login; return $login;
} }
/* /**
* Fill fileds of single extension row * Fills the fileds of a single extension row.
* In Asterisk it would only be an extension name,a priority,an application, but LDAP spicific * In Asterisk it would only be an extension name,a priority,an application, but LDAP spicific
* add to processing context filed. * add to processing context field.
* @param $extRow - hash array to store single extension properties; *
* @param $entryCounter - counter to distinguish single extensuion properties from $_POST * @param array $extRow - hash array to store single extension properties;
* @param $extensionPriorityCntr - it is the variable where actual number of extension rules wuld be aggregated * @param String $extensionName extension name
* @param String $extensionContext extension context
* @param int $entryCounter - counter to distinguish single extensuion properties from $_POST
* @param int $extensionPriorityCntr - it is the variable where actual number of extension rules wuld be aggregated
*/ */
function processSingleExtension(&$extRow,$extensionName, $extensionContext ,$entryCounter,$extensionPriorityCntr) { function processSingleExtension(&$extRow,$extensionName, $extensionContext ,$entryCounter,$extensionPriorityCntr) {
$errors = array(); $errors = array();
if (isset($extensionContext[0])) { if (isset($extensionContext[0])) {
@ -680,6 +706,9 @@ class asteriskExtensionNewUI extends baseModule {
return $errors; return $errors;
} }
/**
* Reorders the rules if the user clicked on a move button.
*/
function processPriorityChange() { function processPriorityChange() {
for ($entryCounter = 0; $entryCounter < sizeof($this->extensionRows); $entryCounter++) { for ($entryCounter = 0; $entryCounter < sizeof($this->extensionRows); $entryCounter++) {
if (isset($_POST["rule_up_button_" . $entryCounter])) { if (isset($_POST["rule_up_button_" . $entryCounter])) {
@ -694,8 +723,10 @@ class asteriskExtensionNewUI extends baseModule {
} }
/** /**
* Search by extension name and retun true if fields wtith this extension name is presented * Search by extension name and retun true if fields with this extension name is presented
* and false otherwise. * and false otherwise.
*
* @return boolean true if there are entries with this extension name.
*/ */
function isThisExtensionPresented($extension) { function isThisExtensionPresented($extension) {
$searchClass = "AsteriskExtension"; $searchClass = "AsteriskExtension";
@ -715,6 +746,8 @@ class asteriskExtensionNewUI extends baseModule {
* This function searches in the base subtree and finds all extensions names within. * This function searches in the base subtree and finds all extensions names within.
* The generation algorithm is the naive one, so only work when extension is numbers. * The generation algorithm is the naive one, so only work when extension is numbers.
* All extension name is sorted and new extension name will be greates on + 1. * All extension name is sorted and new extension name will be greates on + 1.
*
* @return String suggested extension name
*/ */
function generateNextExtensionName() { function generateNextExtensionName() {
$searchClass = "AsteriskExtension"; $searchClass = "AsteriskExtension";
@ -948,8 +981,9 @@ class asteriskExtensionNewUI extends baseModule {
/** /**
* Runs ufter main deltete procedure was done and do postmorten for other parts of extension * Runs ufter main deltete procedure was done and do postmorten for other parts of extension
* wtith priority > 1 * wtith priority > 1.
* @return type *
* @return array error messages
*/ */
function postDeleteActions() { function postDeleteActions() {
@ -966,7 +1000,6 @@ class asteriskExtensionNewUI extends baseModule {
ldap_delete($_SESSION['ldap']->server(), $rowOrig['dn']); ldap_delete($_SESSION['ldap']->server(), $rowOrig['dn']);
} }
} }
$message = array(0 => array("ERROR"));
return array(); return array();
} }

View File

@ -4,7 +4,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2009 Pozdnyak Pavel Copyright (C) 2009 - 2012 Pozdnyak Pavel
2010 - 2012 Roland Gruber 2010 - 2012 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@ -92,8 +92,8 @@ class asteriskExtNewUI extends baseType {
function getListAttributeDescriptions() { function getListAttributeDescriptions() {
return array( return array(
"astextension" => _("Extension name"), "astextension" => _("Extension name"),
"astcontext" => _("Context"), "astcontext" => _("Account context"),
"member" => _("Extension owner DN"), "member" => _("Owner"),
); );
} }
@ -108,8 +108,8 @@ class asteriskExtNewUI extends baseType {
return _("New extension"); return _("New extension");
} }
// check if a common name is set // check if a common name is set
if (isset($attributes['astextension'][0])) { if (isset($attributes['AstExtension'][0])) {
return htmlspecialchars($attributes['astextension'][0]); return htmlspecialchars($attributes['AstExtension'][0]);
} }
// fall back to default // fall back to default
return parent::getTitleBarTitle($attributes); return parent::getTitleBarTitle($attributes);
@ -141,12 +141,23 @@ class lamAsteriskExtNewUIList extends lamList {
'deleteEntry' => _("Delete selected extensions")); 'deleteEntry' => _("Delete selected extensions"));
} }
/**
* Forces the list view to show only specific attributes.
*
* @see lamList::listGetParams()
*/
protected function listGetParams() { protected function listGetParams() {
// check if only PDF should be shown // check if only PDF should be shown
parent::listGetParams(); parent::listGetParams();
$this->attrArray = array("astextension", "astcontext", "member"); $this->attrArray = array("astextension", "astcontext", "member");
} }
/**
* Groups the extensions.
*
* (non-PHPdoc)
* @see lamList::listRefreshData()
*/
protected function listRefreshData() { protected function listRefreshData() {
parent::listRefreshData(); parent::listRefreshData();
// configure search filter // configure search filter
@ -167,6 +178,11 @@ class lamAsteriskExtNewUIList extends lamList {
$this->possibleSuffixes = $typeObj->getSuffixList(); $this->possibleSuffixes = $typeObj->getSuffixList();
} }
/**
* Groups the extensions.
*
* @param array $entries extension entries
*/
private function normalizeLdapOutput($entries){ private function normalizeLdapOutput($entries){
$entries = array_map("unserialize", array_unique(array_map("serialize", $entries))); $entries = array_map("unserialize", array_unique(array_map("serialize", $entries)));
foreach($entries as $key=> $value){ foreach($entries as $key=> $value){
@ -177,9 +193,6 @@ class lamAsteriskExtNewUIList extends lamList {
return $entries; return $entries;
} }
} }
?> ?>