public function __construct($sClass, $sAttCode, $sInputId, $sNameSuffix = '') { $this->sClass = $sClass; $this->sAttCode = $sAttCode; $this->sInputid = $sInputId; $this->sNameSuffix = $sNameSuffix; $this->aZlist = array(); $this->sLinkedClass = ''; // Compute the list of attributes visible from the given objet: // All the attributes from the "list" Zlist of the Link class except // the ExternalKey that points to the current object and its related external fields $oLinksetDef = MetaModel::GetAttributeDef($sClass, $sAttCode); $this->sLinkedClass = $oLinksetDef->GetLinkedClass(); $sExtKeyToMe = $oLinksetDef->GetExtKeyToMe(); switch ($oLinksetDef->GetEditMode()) { case LINKSET_EDITMODE_INPLACE: // The whole linkset can be edited 'in-place' $aZList = MetaModel::FlattenZList(MetaModel::GetZListItems($this->sLinkedClass, 'details')); break; default: $aZList = MetaModel::FlattenZList(MetaModel::GetZListItems($this->sLinkedClass, 'list')); array_unshift($aZList, 'friendlyname'); } foreach ($aZList as $sLinkedAttCode) { if ($sLinkedAttCode != $sExtKeyToMe) { $oAttDef = MetaModel::GetAttributeDef($this->sLinkedClass, $sLinkedAttCode); if ((!$oAttDef->IsExternalField() || $oAttDef->GetKeyAttCode() != $sExtKeyToMe) && !$oAttDef->IsLinkSet()) { $this->aZlist[] = $sLinkedAttCode; } } } }
/** * Fills the given XML node with te details of the specified object */ function AddNodeDetails(&$oNode, $oObj) { $aZlist = MetaModel::GetZListItems(get_class($oObj), 'list'); $aLabels = array(); $index = 0; foreach ($aZlist as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode); $aLabels[] = $oAttDef->GetLabel(); if (!$oAttDef->IsLinkSet()) { $oNode->SetAttribute('att_' . $index, $oObj->GetAsHTML($sAttCode)); } $index++; } $oNode->SetAttribute('zlist', implode(',', $aLabels)); }
/** * Updates the object from a flat array of values * @param $aAttList array $aAttList array of attcode * @param $aErrors array Returns information about slave attributes * @param $sTargetState string Target state for which to evaluate the writeable attributes (=current state is empty) * @return array of attcodes that can be used for writing on the current object */ public function GetWriteableAttList($aAttList, &$aErrors, $sTargetState = '') { if (!is_array($aAttList)) { $aAttList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details')); // Special case to process the case log, if any... // WARNING: if you change this also check the functions DisplayModifyForm and DisplayCaseLog foreach (MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) { if ($this->IsNew()) { $iFlags = $this->GetInitialStateAttributeFlags($sAttCode); } else { $aVoid = array(); $iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState); } if ($oAttDef instanceof AttributeCaseLog) { if (!($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_SLAVE | OPT_ATT_READONLY))) { // The case log is editable, append it to the list of fields to retrieve $aAttList[] = $sAttCode; } } } } $aWriteableAttList = array(); foreach ($aAttList as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); if ($this->IsNew()) { $iFlags = $this->GetInitialStateAttributeFlags($sAttCode); } else { $aVoid = array(); $iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState); } if ($oAttDef->IsWritable()) { if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY)) { // Non-visible, or read-only attribute, do nothing } elseif ($iFlags & OPT_ATT_SLAVE) { $aErrors[$sAttCode] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel()); } else { $aWriteableAttList[$sAttCode] = $oAttDef; } } } return $aWriteableAttList; }
public static function GetDataModelSettings($aClassAliases, $bViewLink, $aDefaultLists) { $oSettings = new DataTableSettings($aClassAliases); // Retrieve the class specific settings for each class/alias based on the 'list' ZList //TODO let the caller pass some other default settings (another Zlist, extre fields...) $aColumns = array(); foreach ($aClassAliases as $sAlias => $sClass) { if ($aDefaultLists == null) { $aList = cmdbAbstract::FlattenZList(MetaModel::GetZListItems($sClass, 'list')); } else { $aList = $aDefaultLists[$sAlias]; } $aSortOrder = MetaModel::GetOrderByDefault($sClass); if ($bViewLink) { $sSort = 'none'; if (array_key_exists('friendlyname', $aSortOrder)) { $sSort = $aSortOrder['friendlyname'] ? 'asc' : 'desc'; } $aColumns[$sAlias]['_key_'] = $oSettings->GetFieldData($sAlias, '_key_', null, true, $sSort); } foreach ($aList as $sAttCode) { $sSort = 'none'; if (array_key_exists($sAttCode, $aSortOrder)) { $sSort = $aSortOrder[$sAttCode] ? 'asc' : 'desc'; } $oAttDef = Metamodel::GetAttributeDef($sClass, $sAttCode); $aFieldData = $oSettings->GetFieldData($sAlias, $sAttCode, $oAttDef, true, $sSort); if ($aFieldData) { $aColumns[$sAlias][$sAttCode] = $aFieldData; } } } $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); $oSettings->Init($iDefaultPageSize, $aSortOrder, $aColumns); return $oSettings; }
/** * Compute the order of the fields & pages in the wizard * @param $oPage iTopWebPage The current page (used to display error messages) * @param $sClass string Name of the class * @param $sStateCode string Code of the target state of the object * @return hash Two dimensional array: each element represents the list of fields for a given page */ protected function ComputeWizardStructure() { $aWizardSteps = array('mandatory' => array(), 'optional' => array()); $aFieldsDone = array(); // Store all the fields that are already covered by a previous step of the wizard $aStates = MetaModel::EnumStates($this->m_sClass); $sStateAttCode = MetaModel::GetStateAttributeCode($this->m_sClass); $aMandatoryAttributes = array(); // Some attributes are always mandatory independently of the state machine (if any) foreach (MetaModel::GetAttributesList($this->m_sClass) as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); if (!$oAttDef->IsExternalField() && !$oAttDef->IsNullAllowed() && $oAttDef->IsWritable() && $sAttCode != $sStateAttCode) { $aMandatoryAttributes[$sAttCode] = OPT_ATT_MANDATORY; } } // Now check the attributes that are mandatory in the specified state if (!empty($this->m_sTargetState) && count($aStates[$this->m_sTargetState]['attribute_list']) > 0) { // Check all the fields that *must* be included in the wizard for this // particular target state $aFields = array(); foreach ($aStates[$this->m_sTargetState]['attribute_list'] as $sAttCode => $iOptions) { if (isset($aMandatoryAttributes[$sAttCode]) && $aMandatoryAttributes[$sAttCode] & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) { $aMandatoryAttributes[$sAttCode] |= $iOptions; } else { $aMandatoryAttributes[$sAttCode] = $iOptions; } } } // Check all the fields that *must* be included in the wizard // i.e. all mandatory, must-change or must-prompt fields that are // not also read-only or hidden. // Some fields may be required (null not allowed) from the database // perspective, but hidden or read-only from the user interface perspective $aFields = array(); foreach ($aMandatoryAttributes as $sAttCode => $iOptions) { if ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT) && !($iOptions & (OPT_ATT_READONLY | OPT_ATT_HIDDEN))) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); $aPrerequisites = $oAttDef->GetPrerequisiteAttributes(); $aFields[$sAttCode] = array(); foreach ($aPrerequisites as $sCode) { $aFields[$sAttCode][$sCode] = ''; } } } // Now use the dependencies between the fields to order them // Start from the order of the 'details' $aList = MetaModel::FlattenZlist(MetaModel::GetZListItems($this->m_sClass, 'details')); $index = 0; $aOrder = array(); foreach ($aFields as $sAttCode => $void) { $aOrder[$sAttCode] = 999; // At the end of the list... } foreach ($aList as $sAttCode) { if (array_key_exists($sAttCode, $aFields)) { $aOrder[$sAttCode] = $index; } $index++; } foreach ($aFields as $sAttCode => $aDependencies) { // All fields with no remaining dependencies can be entered at this // step of the wizard if (count($aDependencies) > 0) { $iMaxPos = 0; // Remove this field from the dependencies of the other fields foreach ($aDependencies as $sDependentAttCode => $void) { // position the current field after the ones it depends on $iMaxPos = max($iMaxPos, 1 + $aOrder[$sDependentAttCode]); } } } asort($aOrder); $aCurrentStep = array(); foreach ($aOrder as $sAttCode => $rank) { $aCurrentStep[] = $sAttCode; $aFieldsDone[$sAttCode] = ''; } $aWizardSteps['mandatory'][] = $aCurrentStep; // Now computes the steps to fill the optional fields $aFields = array(); // reset foreach (MetaModel::ListAttributeDefs($this->m_sClass) as $sAttCode => $oAttDef) { $iOptions = isset($aStates[$this->m_sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$this->m_sTargetState]['attribute_list'][$sAttCode] : 0; if ($sStateAttCode != $sAttCode && !$oAttDef->IsExternalField() && ($iOptions & (OPT_ATT_HIDDEN | OPT_ATT_READONLY)) == 0 && !isset($aFieldsDone[$sAttCode])) { // 'State', external fields, read-only and hidden fields // and fields that are already listed in the wizard // are removed from the 'optional' part of the wizard $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); $aPrerequisites = $oAttDef->GetPrerequisiteAttributes(); $aFields[$sAttCode] = array(); foreach ($aPrerequisites as $sCode) { if (!isset($aFieldsDone[$sCode])) { // retain only the dependencies that were not covered // in the 'mandatory' part of the wizard $aFields[$sAttCode][$sCode] = ''; } } } } // Now use the dependencies between the fields to order them while (count($aFields) > 0) { $aCurrentStep = array(); foreach ($aFields as $sAttCode => $aDependencies) { // All fields with no remaining dependencies can be entered at this // step of the wizard if (count($aDependencies) == 0) { $aCurrentStep[] = $sAttCode; $aFieldsDone[$sAttCode] = ''; unset($aFields[$sAttCode]); // Remove this field from the dependencies of the other fields foreach ($aFields as $sUpdatedCode => $aDummy) { // remove the dependency unset($aFields[$sUpdatedCode][$sAttCode]); } } } if (count($aCurrentStep) == 0) { // This step of the wizard would contain NO field ! $this->m_oPage->add(Dict::S('UI:Error:WizardCircularReferenceInDependencies')); print_r($aFields); break; } $aWizardSteps['optional'][] = $aCurrentStep; } return $aWizardSteps; }
function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array()) { if ($bEditMode) { return; } // Not editable $oPage->add('<table style="vertical-align:top"><tr style="vertical-align:top"><td>'); $aDetails = array(); $sClass = get_class($this); $oPage->add('<fieldset>'); $oPage->add('<legend>' . Dict::S('Core:SynchroReplica:PrivateDetails') . '</legend>'); $aZList = MetaModel::FlattenZlist(MetaModel::GetZListItems($sClass, 'details')); foreach ($aZList as $sAttCode) { $sDisplayValue = $this->GetAsHTML($sAttCode); $aDetails[] = array('label' => '<span title="' . MetaModel::GetDescription($sClass, $sAttCode) . '">' . MetaModel::GetLabel($sClass, $sAttCode) . '</span>', 'value' => $sDisplayValue); } $oPage->Details($aDetails); $oPage->add('</fieldset>'); if (strlen($this->Get('dest_class')) > 0) { $oDestObj = MetaModel::GetObject($this->Get('dest_class'), $this->Get('dest_id'), false); if (is_object($oDestObj)) { $oPage->add('<fieldset>'); $oPage->add('<legend>' . Dict::Format('Core:SynchroReplica:TargetObject', $oDestObj->GetHyperlink()) . '</legend>'); $oDestObj->DisplayBareProperties($oPage, false, $sPrefix, $aExtraParams); $oPage->add('<fieldset>'); } } $oPage->add('</td><td>'); $oPage->add('<fieldset>'); $oPage->add('<legend>' . Dict::S('Core:SynchroReplica:PublicData') . '</legend>'); $oSource = MetaModel::GetObject('SynchroDataSource', $this->Get('sync_source_id')); $sSQLTable = $oSource->GetDataTable(); $aData = $this->LoadExtendedDataFromTable($sSQLTable); $aHeaders = array('attcode' => array('label' => 'Attribute Code', 'description' => ''), 'data' => array('label' => 'Value', 'description' => '')); $aRows = array(); foreach ($aData as $sKey => $value) { $aRows[] = array('attcode' => $sKey, 'data' => $value); } $oPage->Table($aHeaders, $aRows); $oPage->add('</fieldset>'); $oPage->add('</td></tr></table>'); }
public function DisplayDetails(WebPage $oPage, $bEditMode = false) { $oPage->add('<h1>' . MetaModel::GetName(get_class($this)) . ': ' . $this->GetName() . '</h1>'); $aValues = array(); $aList = MetaModel::FlattenZList(MetaModel::GetZListItems(get_class($this), 'details')); if (empty($aList)) { $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this))); } foreach ($aList as $sAttCode) { $aValues[$sAttCode] = array('label' => MetaModel::GetLabel(get_class($this), $sAttCode), 'value' => $this->GetAsHTML($sAttCode)); } $oPage->details($aValues); }
public function GetTooltip($aContextDefs) { $sHtml = ''; $oCurrObj = $this->GetProperty('object'); $sSubClass = get_class($oCurrObj); $sHtml .= $oCurrObj->GetHyperlink() . "<hr/>"; $aContextRootCauses = $this->GetProperty('context_root_causes'); if (!is_null($aContextRootCauses)) { foreach ($aContextRootCauses as $key => $aObjects) { $aContext = $aContextDefs[$key]; $aRootCauses = array(); foreach ($aObjects as $oRootCause) { $aRootCauses[] = $oRootCause->GetHyperlink(); } $sHtml .= '<p><img style="max-height: 24px; vertical-align:bottom;" src="' . utils::GetAbsoluteUrlModulesRoot() . $aContext['icon'] . '" title="' . htmlentities(Dict::S($aContext['dict'])) . '"> ' . implode(', ', $aRootCauses) . '</p>'; } $sHtml .= '<hr/>'; } $sHtml .= '<table><tbody>'; foreach (MetaModel::GetZListItems($sSubClass, 'list') as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef($sSubClass, $sAttCode); $sHtml .= '<tr><td>' . $oAttDef->GetLabel() . ': </td><td>' . $oCurrObj->GetAsHtml($sAttCode) . '</td></tr>'; } $sHtml .= '</tbody></table>'; return $sHtml; }
/** * A one-row form for editing a link record * @param WebPage $oP Web page used for the ouput * @param DBObject $oLinkedObj The object to which all the elements of the linked set refer to * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add * @param Hash $aArgs Extra context arguments * @return string The HTML fragment of the one-row form */ protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array(), $oCurrentObj) { $sPrefix = "{$this->m_sAttCode}{$this->m_sNameSuffix}"; $aRow = array(); $aFieldsMap = array(); if (is_object($linkObjOrId) && !$linkObjOrId->IsNew()) { $key = $linkObjOrId->GetKey(); $iRemoteObjKey = $linkObjOrId->Get($this->m_sExtKeyToRemote); $sPrefix .= "[{$key}]["; $sNameSuffix = "]"; // To make a tabular form $aArgs['prefix'] = $sPrefix; $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}{$key}"; $aArgs['this'] = $linkObjOrId; $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget" . $this->m_iInputId . ".OnSelectChange();\" value=\"{$key}\">"; $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"{$key}\">"; foreach ($this->m_aEditableFields as $sFieldCode) { $sFieldId = $this->m_iInputId . '_' . $sFieldCode . '[' . $linkObjOrId->GetKey() . ']'; $sSafeId = utils::GetSafeId($sFieldId); $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode); $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $linkObjOrId->Get($sFieldCode), '', $sSafeId, $sNameSuffix, 0, $aArgs); $aFieldsMap[$sFieldCode] = $sSafeId; } $sState = $linkObjOrId->GetState(); } else { // form for creating a new record if (is_object($linkObjOrId)) { // New link existing only in memory $oNewLinkObj = $linkObjOrId; $iRemoteObjKey = $oNewLinkObj->Get($this->m_sExtKeyToRemote); $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, $iRemoteObjKey); $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj); // Setting the extkey with the object also fills the related external fields $linkObjOrId = -$iRemoteObjKey; } else { $iRemoteObjKey = -$linkObjOrId; $oNewLinkObj = MetaModel::NewObject($this->m_sLinkedClass); $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, -$linkObjOrId); $oNewLinkObj->Set($this->m_sExtKeyToRemote, $oRemoteObj); // Setting the extkey with the object alsoo fills the related external fields $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj); // Setting the extkey with the object also fills the related external fields } $sPrefix .= "[{$linkObjOrId}]["; $sNameSuffix = "]"; // To make a tabular form $aArgs['prefix'] = $sPrefix; $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}_" . -$linkObjOrId; $aArgs['this'] = $oNewLinkObj; $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget" . $this->m_iInputId . ".OnSelectChange();\" value=\"{$linkObjOrId}\">"; $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"\">"; foreach ($this->m_aEditableFields as $sFieldCode) { $sFieldId = $this->m_iInputId . '_' . $sFieldCode . '[' . $linkObjOrId . ']'; $sSafeId = utils::GetSafeId($sFieldId); $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode); $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $oNewLinkObj->Get($sFieldCode), '', $sSafeId, $sNameSuffix, 0, $aArgs); $aFieldsMap[$sFieldCode] = $sSafeId; } $sState = ''; $oP->add_script(<<<EOF \$(".date-pick").datepicker({ \t\tshowOn: 'button', \t\tbuttonImage: '../images/calendar.png', \t\tbuttonImageOnly: true, \t\tdateFormat: 'yy-mm-dd', \t\tconstrainInput: false, \t\tchangeMonth: true, \t\tchangeYear: true \t}); \$(".datetime-pick").datepicker({ \t\tshowOn: 'button', \t\tbuttonImage: '../images/calendar.png', \t\tbuttonImageOnly: true, \t\tdateFormat: 'yy-mm-dd 00:00:00', \t\tconstrainInput: false, \t\tchangeMonth: true, \t\tchangeYear: true }); EOF ); } $sExtKeyToMeId = utils::GetSafeId($sPrefix . $this->m_sExtKeyToMe); $aFieldsMap[$this->m_sExtKeyToMe] = $sExtKeyToMeId; $aRow['form::checkbox'] .= "<input type=\"hidden\" id=\"{$sExtKeyToMeId}\" value=\"" . $oCurrentObj->GetKey() . "\">"; $sExtKeyToRemoteId = utils::GetSafeId($sPrefix . $this->m_sExtKeyToRemote); $aFieldsMap[$this->m_sExtKeyToRemote] = $sExtKeyToRemoteId; $aRow['form::checkbox'] .= "<input type=\"hidden\" id=\"{$sExtKeyToRemoteId}\" value=\"{$iRemoteObjKey}\">"; $iFieldsCount = count($aFieldsMap); $sJsonFieldsMap = json_encode($aFieldsMap); $oP->add_script(<<<EOF var {$aArgs['wizHelper']} = new WizardHelper('{$this->m_sLinkedClass}', '', '{$sState}'); {$aArgs['wizHelper']}.SetFieldsMap({$sJsonFieldsMap}); {$aArgs['wizHelper']}.SetFieldsCount({$iFieldsCount}); EOF ); $aRow['static::key'] = $oLinkedObj->GetHyperLink(); foreach (MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode) { $aRow['static::' . $sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode); } return $aRow; }
function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array()) { if ($bEditMode) { return array(); } // Not editable $aDetails = array(); $sClass = get_class($this); $aZList = MetaModel::FlattenZlist(MetaModel::GetZListItems($sClass, 'details')); foreach ($aZList as $sAttCode) { $sDisplayValue = $this->GetAsHTML($sAttCode); $aDetails[] = array('label' => '<span title="' . MetaModel::GetDescription($sClass, $sAttCode) . '">' . MetaModel::GetLabel($sClass, $sAttCode) . '</span>', 'value' => $sDisplayValue); } $oPage->Details($aDetails); return array(); }
function test_zlist() { echo "<h4>Test ZLists</h4>"; $aZLists = MetaModel::EnumZLists(); foreach ($aZLists as $sListCode) { $aListInfos = MetaModel::GetZListInfo($sListCode); echo "<h4>List '" . $sListCode . "' (" . $aListInfos["description"] . ") of type '" . $aListInfos["type"] . "'</h5>\n"; foreach (MetaModel::GetSubclasses("cmdbObjectHomeMade") as $sKlass) { $aItems = MetaModel::FlattenZlist(MetaModel::GetZListItems($sKlass, $sListCode)); if (count($aItems) == 0) { continue; } echo "{$sKlass} - {$sListCode} : {" . implode(", ", $aItems) . "}</br>\n"; } } echo "<h4>IsAttributeInZList()... </h4>"; echo "Liens_entre_contacts_et_workshop::ws_info in list1 ? " . (MetaModel::IsAttributeInZList("Liens_entre_contacts_et_workshop", "list1", "ws_info") ? "yes" : "no") . "</br>\n"; echo "Liens_entre_contacts_et_workshop::toworkshop in list1 ? " . (MetaModel::IsAttributeInZList("Liens_entre_contacts_et_workshop", "list1", "toworkshop") ? "yes" : "no") . "</br>\n"; }
protected function GetFormRow($oP, $oLinkedObj, $currentLink = null) { $aRow = array(); if (is_object($currentLink)) { $key = $currentLink->GetKey(); $sNameSuffix = "[{$key}]"; // To make a tabular form $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"OnSelectChange();\" value=\"{$key}\">"; $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"linkId[{$key}]\" value=\"{$key}\">"; foreach ($this->m_aEditableFields as $sFieldCode) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sFieldCode); $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sClass, $sFieldCode, $oAttDef, $currentLink->Get($sFieldCode), '', $key, $sNameSuffix); } } else { // form for creating a new record $sNameSuffix = "[{$currentLink}]"; // To make a tabular form $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"OnSelectChange();\" value=\"{$currentLink}\">"; $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"linkId[{$currentLink}]\" value=\"{$currentLink}\">"; foreach ($this->m_aEditableFields as $sFieldCode) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sFieldCode); $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sClass, $sFieldCode, $oAttDef, '', '', '', $sNameSuffix); } } foreach (MetaModel::GetZListItems($this->m_sLinkedClass, 'list') as $sFieldCode) { $aRow['static::' . $sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode); } return $aRow; }
public function GetNextChunk(&$aStatus) { $sRetCode = 'run'; $iPercentage = 0; $iCount = 0; $sData = ''; $oSet = new DBObjectSet($this->oSearch); $oSet->SetLimit($this->iChunkSize, $this->aStatusInfo['position']); $bLocalize = $this->aStatusInfo['localize']; $aClasses = $this->oSearch->GetSelectedClasses(); $aAuthorizedClasses = array(); foreach ($aClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_BULK_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) { $aAuthorizedClasses[$sAlias] = $sClassName; } } $aAttribs = array(); $aList = array(); $aList[$sAlias] = MetaModel::GetZListItems($sClassName, 'details'); $iPreviousTimeLimit = ini_get('max_execution_time'); $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop'); while ($aObjects = $oSet->FetchAssoc()) { set_time_limit($iLoopTimeLimit); if (count($aAuthorizedClasses) > 1) { $sData .= "<Row>\n"; } foreach ($aAuthorizedClasses as $sAlias => $sClassName) { $oObj = $aObjects[$sAlias]; if (is_null($oObj)) { $sData .= "<{$sClassName} alias=\"{$sAlias}\" id=\"null\">\n"; } else { $sClassName = get_class($oObj); $sData .= "<{$sClassName} alias=\"{$sAlias}\" id=\"" . $oObj->GetKey() . "\">\n"; } foreach (MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef) { if (is_null($oObj)) { $sData .= "<{$sAttCode}>null</{$sAttCode}>\n"; } else { if ($oAttDef->IsWritable()) { $sValue = $oObj->GetAsXML($sAttCode, $bLocalize); $sData .= "<{$sAttCode}>{$sValue}</{$sAttCode}>\n"; } } } $sData .= "</{$sClassName}>\n"; } if (count($aAuthorizedClasses) > 1) { $sData .= "</Row>\n"; } $iCount++; } set_time_limit($iPreviousTimeLimit); $this->aStatusInfo['position'] += $this->iChunkSize; if ($this->aStatusInfo['total'] == 0) { $iPercentage = 100; } else { $iPercentage = floor(min(100.0, 100.0 * $this->aStatusInfo['position'] / $this->aStatusInfo['total'])); } if ($iCount < $this->iChunkSize) { $sRetCode = 'done'; } $aStatus = array('code' => $sRetCode, 'message' => Dict::S('Core:BulkExport:RetrievingData'), 'percentage' => $iPercentage); return $sData; }