documentfieldsv2.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 446 行 · 第 1/2 页
SVN-BASE
446 行
function getTypesForFieldset($oFieldset) { global $default; if ($oFieldset->getIsGeneric()) { return _kt('All types use this generic fieldset.'); } $types = $oFieldset->getAssociatedTypes(); if (PEAR::isError($types)) { $default->log->debug('Fieldsets admin: Error retrieving list of associated document types.'); return _kt('Error retrieving list of types.'); } if (empty($types)) { return _kt('None'); } $aNames = array(); foreach ($types as $oType) { if (!PEAR::isError($oType)) { $aNames[] = $oType->getName(); }else{ $default->log->debug('Fieldsets admin: Document type gives error: '.$oType->getMessage()); } } $list = implode(', ', $aNames); $length = mb_strlen($list); if($length < 50){ return $list; } $default->log->debug('Fieldsets admin: wrapping the list of doc types from length '.$length); // Wrap the list to 50 characters per line $wrapList = ''; $cut = 0; while ($length > 50 && $cut !== false){ $cut = strpos($list, ' ', 50); $wrapList .= mb_strcut($list, 0, $cut); $wrapList .= '<br />'; $list = mb_strcut($list, $cut); $length = mb_strlen($list); } $wrapList .= $list; return $wrapList; } function do_edit() { // here we engage in some major evil. // we check for the subevent var // and subdispatch if appropriate. // // saves a little code-duplication (actually, a lot of code-duplication) // FIXME this is essentially a stub for the fieldset-delegation code. if ($this->oFieldset->getIsConditional()) { require_once('fieldsets/conditional.inc.php'); $oSubDispatcher = new ConditionalFieldsetManagementDispatcher; } else { require_once('fieldsets/basic.inc.php'); $oSubDispatcher = new BasicFieldsetManagementDispatcher; } $subevent_var = 'fieldset_action'; $subevent = KTUtil::arrayGet($_REQUEST, $subevent_var); if (!empty($subevent)) { // do nothing, since this will handle everything $this_url = KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit")); $oSubDispatcher->redispatch($subevent_var, null, $this, $this_url); exit(0); } else { // what we want is the "additional info" section $additional = $oSubDispatcher->describe_fieldset($this->oFieldset); } $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/edit'); $oTemplate->setData(array( 'context' => $this, 'fieldset_name' => $this->oFieldset->getName(), 'additional' => $additional, )); return $oTemplate->render(); } function do_delete() { $this->startTransaction(); // check if fieldset is associated with a document type - remove association $types = $this->oFieldset->getAssociatedTypes(); $sFieldSetId = $this->oFieldset->getId(); if(!PEAR::isError($types) AND !empty($types)){ foreach($types as $oType){ $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $sFieldSetId); } } $res = $this->oFieldset->delete('true'); $this->oValidator->notErrorFalse($res, array( 'redirect_to' => array('main', ''), 'message' => _kt('Could not delete fieldset'), )); $this->successRedirectToMain(_kt('Fieldset deleted')); } function form_edit() { $oForm = new KTForm; $oForm->setOptions(array( 'identifier' => 'ktcore.fieldsets.edit', 'label' => _kt("Change Fieldset Details"), 'submit_label' => _kt('Update Fieldset'), 'cancel_action' => 'edit', 'fail_action' => 'editfieldset', 'action' => 'savefieldset', 'context' => $this, )); // construct the widget set. // we use a slight variation here, because "type" is only present in certain circumstances. $widgets = array( array('ktcore.widgets.string',array( 'label' => _kt("Fieldset Name"), 'name' => 'name', 'required' => true, 'description' => _kt("Each fieldset needs a unique name."), 'value' => sanitizeForHTML($this->oFieldset->getName()), )), array('ktcore.widgets.text',array( 'label' => _kt("Description"), 'name' => 'description', 'required' => true, 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."), 'value' => sanitizeForHTML($this->oFieldset->getDescription()), )), ); $widgets[] = array('ktcore.widgets.boolean',array( 'label' => _kt("Generic"), 'name' => 'generic', 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."), 'value' => $this->oFieldset->getIsGeneric(), )); $oForm->setWidgets($widgets); // similarly, we construct validators here. $validators = array( array('ktcore.validators.string', array( 'test' => 'name', 'output' => 'name', )), array('ktcore.validators.string', array( 'test' => 'description', 'output' => 'description', )), array('ktcore.validators.boolean', array( 'test' => 'generic', 'output' => 'generic', )), ); $oForm->setValidators($validators); return $oForm; } function do_editfieldset() { $oForm = $this->form_edit(); $this->oPage->setBreadcrumbDetails(_kt('edit fieldset')); return $oForm->renderPage(_kt("Edit Fieldset")); } function do_savefieldset() { $oForm = $this->form_edit(); $res = $oForm->validate(); $data = $res['results']; $errors = $res['errors']; $extra_errors = array(); if ($data['name'] != $this->oFieldset->getName()) { $oOldFieldset = KTFieldset::getByName($data['name']); if (!PEAR::isError($oOldFieldset)) { $extra_errors['name'][] = _kt("A fieldset with that name already exists."); } } if (!empty($errors) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } $this->startTransaction(); $this->oFieldset->setName($data['name']); $this->oFieldset->setDescription($data['description']); $bGeneric = $data['generic']; if ($bGeneric != $this->oFieldset->getIsGeneric() && $bGeneric == true) { // delink it from all doctypes. $aTypes = $this->oFieldset->getAssociatedTypes(); foreach ($aTypes as $oType) { $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $this->oFieldset->getId()); if (PEAR::isError($res)) { $this->errorRedirectTo('edit', _kt('Could not save fieldset changes')); exit(0); } } } $this->oFieldset->setIsGeneric($data['generic']); $res = $this->oFieldset->update(); if (PEAR::isError($res)) { $this->errorRedirectTo('edit', _kt('Could not save fieldset changes')); exit(0); } return $this->successRedirectTo('edit', _kt("Fieldset details updated.")); }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?