ktwidgets.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 931 行 · 第 1/3 页

SVN-BASE
931
字号
        $oKTConfig =& KTConfig::getSingleton();        $sName = $this->sName;        if (KTUtil::arrayGet($this->aOptions, 'broken_name', false)) {            $this->sName = 'fFolderId';        }        $sPath = KTUtil::addQueryString($sPath, array('code'=>$this->sCode,                                                      'fFolderId'=>$this->iFolderId,                                                      'varname' => $sName));        return $sPath;    }    function getCollection() {        $oCR =& KTColumnRegistry::getSingleton();        //print '<pre>';        foreach($this->aCols as $ns) {            $oCR->getColumn($ns);        }        $this->oCollection = unserialize($this->sCollection);        return $this->oCollection;    }}class KTCoreFolderCollectionWidget extends KTCoreCollectionWidget {    var $sNamespace = 'ktcore.widgets.foldercollection';    var $sTemplate = 'ktcore/forms/widgets/collectionframe';    function configure($aOptions) {        if (!isset($aOptions['value'])) {            $aOptions['value'] = KTUtil::arrayGet($aOptions,'folder_id', 1);        }        $this->value = $aOptions['value'];        $collection = new AdvancedCollection();        $oCR =& KTColumnRegistry::getSingleton();        $col = $oCR->getColumn('ktcore.columns.title');        $col->setOptions(array('qs_params'=>array('fMoveCode'=>$sMoveCode,                                                  'fFolderId'=> $this->value,                                                  'action'=>'startMove')));        $collection->addColumn($col);        $qObj = new FolderBrowseQuery(KTUtil::arrayGet($aOptions,'value'));        $collection->setQueryObject($qObj);        $aO = $collection->getEnvironOptions();        $collection->setOptions($aO);        $aOptions['collection'] = $collection;        $aOptions['broken_name'] = $false;        return parent::configure($aOptions);    }    function getDefault() { return $this->value; }    function setDefault($mValue) {        if ($mValue != $this->value) {            $this->oCollection->setQueryObject(new FolderBrowseQuery($mValue));            $this->value = $mValue;            $this->aOptions['folder_id'] = $this->value;            $this->iFolderId = $this->value;            $this->sCollection = serialize($this->oCollection);            $_SESSION['collection_widgets'][$this->sCode] = serialize($this);        }    }}class KTCoreCollectionPage extends KTStandardDispatcher {    function _generate_breadcrumbs(&$oFolder, $sCode, $aURLParams, $sName = 'fFolderId') {        $aBreadcrumbs = array();        $folder_path_names = $oFolder->getPathArray();        $folder_path_ids = explode(',', $oFolder->getParentFolderIds());        $folder_path_ids[] = $oFolder->getId();        if (!empty($folder_path_ids) && empty($folder_path_ids[0]))        {			array_shift($folder_path_ids);        }        $oRoot = Folder::get(1);        $folder_path_names = array_merge(array($oRoot->getName()), $folder_path_names);        foreach (range(0, count($folder_path_ids) - 1) as $index) {            $id = $folder_path_ids[$index];            $aParams = kt_array_merge($aURLParams, array('fFolderId'=>$id, 'code'=>$sCode, 'varname'=>$sName));            $url = KTUtil::addQueryString($_SERVER['PHP_SELF'], $aParams);            $aBreadcrumbs[] = array('url' => $url, 'name' => $folder_path_names[$index]);        }        return $aBreadcrumbs;    }    function do_main() {        $sCode = KTUtil::arrayGet($_REQUEST, 'code');        $sName = KTUtil::arrayGet($_REQUEST, 'varname','fFolderId');        $oWidget = unserialize($_SESSION['collection_widgets'][$sCode]);        $oCollection = $oWidget->getCollection();        $oFolder = Folder::get(KTUtil::arrayGet($_REQUEST, 'fFolderId', 1));        if (PEAR::isError($oFolder)) {            $this->errorRedirectToMain(_kt('Invalid folder selected.'));            exit(0);        }        $aOptions = array('ignorepermissions' => KTBrowseUtil::inAdminMode($this->oUser, $oFolder));        $oCollection->_queryObj->folder_id = $oFolder->getId();        $aOptions = $oCollection->getEnvironOptions();        $aOptions['return_url'] = KTUtil::addQueryString($_SERVER['PHP_SELF'], array('code'=>$sCode, 'varname' => $sName, 'fFolderId' => $oFolder->getId()));        $oCollection->setOptions($aOptions);        // add the collection code to the title column QS params        foreach($oWidget->aCols as $ns) {            $aColOpts = $oCollection->getColumnOptions($ns);            $aColOpts['qs_params'] = kt_array_merge(KTUtil::arrayGet($aColOpts, 'qs_params', array()),                                                    array('code' => $sCode, 'varname' => $sName));            $oCollection->setColumnOptions($ns, $aColOpts);        }        // make the breadcrumbs        $aBreadcrumbs = $this->_generate_breadcrumbs($oFolder, $sCode, $oWidget->aBCUrlParams, $sName);        print KTTemplating::renderTemplate('ktcore/forms/widgets/collection',            array(                'collection'=> $oCollection,                'folder' => $oFolder,                'breadcrumbs' => $aBreadcrumbs,                'targetname' => $sName,            )        );        exit(0);    }}// based on the selection widget, this carries a mapping array,// which is converted to JSON and inserted into the output. javascript// enforces the various relationships between conditional fields.class KTCoreConditionalSelectionWidget extends KTCoreSelectionWidget {    var $sNamespace = 'ktcore.widgets.conditionalselection';    var $sIdMethod;    var $sLabelMethod;    var $bIsMaster;    var $bMappings;    function _getFieldIdForMetadataId($iMetadata) {	$sTable = 'metadata_lookup';	$sQuery = "SELECT document_field_id FROM " . $sTable . " WHERE id = ?";	$aParams = array($iMetadata);	$res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'document_field_id');	if (PEAR::isError($res)) {	    return false;	}	return $res;    }    function configure($aOptions) {        $res = parent::configure($aOptions);        if (PEAR::isError($res)) {            return $res;        }        $this->sIdMethod = KTUtil::arrayGet($aOptions, 'id_method', 'getId');        $this->sLabelMethod = KTUtil::arrayGet($aOptions, 'label_method');        if (empty($this->sLabelMethod)) {            return PEAR::raiseError(_kt('No label method specified.'));        }        $existing_entities = (array) KTUtil::arrayGet($aOptions, 'existing_entities');        if (empty($this->value)) {            $this->value = array();            foreach ($existing_entities as $oEntity) {                $this->value[] = call_user_func(array(&$oEntity, $this->sIdMethod));            }        }	$this->iField = KTUtil::arrayGet($aOptions, 'field');	$this->iMasterId = KTUtil::arrayGet($aOptions, 'masterid');	// if we're the master, we have to build the dependancy array and store it as JSON	// also, include the javascript	if(KTUtil::arrayGet($aOptions, 'master', false)) {	    $this->bMaster = true;	    $this->aJavascript = array('resources/js/conditional_selection.js');	    $oFieldset = KTFieldset::get(KTUtil::arrayGet($aOptions, 'fieldset'));	    $aLookups = array();	    $aConnections = array();	    foreach($oFieldset->getFields() as $oField) {		$c = array();		foreach($oField->getEnabledValues() as $oMetadata) {		    $a = array();		    // print '<pre>';		    $nvals = KTMetadataUtil::getNextValuesForLookup($oMetadata->getId());		    if($nvals) {			foreach($nvals as $i=>$aVals) {			    $a = array_merge($a, $aVals);			    foreach($aVals as $id) {			      $field = $this->_getFieldIdForMetadataId($id);			      // print 'id ' . $id . ' is in field ' . $field . "<br/>";			      if(!in_array($field, $c)) {				$c[] = $field;			      }			    }			}		    }		    $aLookups[$oMetadata->getId()] = $a;		}		$aConnections[$oField->getId()] = $c;	    }	    //exit(0);	    $oJSON = new Services_JSON;	    $this->sLookupsJSON = $oJSON->encode($aLookups);	    $this->sConnectionsJSON = $oJSON->encode($aConnections);	}        $new_vocab = array();        foreach ($this->aVocab as $oEntity) {            $id = call_user_func(array(&$oEntity, $this->sIdMethod));            $label = call_user_func(array(&$oEntity, $this->sLabelMethod));            $new_vocab[$id] = array($label, $oEntity->getId());        }        $this->aVocab = $new_vocab;    }    function getWidget() {        $bHasErrors = false;        if (count($this->aErrors) != 0) { $bHasErrors = true; }	$this->sTemplate = 'ktcore/forms/widgets/conditional_selection';        $oTemplating =& KTTemplating::getSingleton();        $oTemplate = $oTemplating->loadTemplate($this->sTemplate);        $unselected = KTUtil::arrayGet($this->aOptions, 'unselected_label');        if (!empty($unselected)) {            $vocab = array();            $vocab[] = $unselected;            foreach ($this->aVocab as $k => $v) {                $vocab[$k] = $v;            }            $this->aVocab = $vocab;            if (empty($this->value)) {                $this->value = '0';            }        }        if ($this->bMulti) {            $this->_valuesearch = array();            $value = (array) $this->value;            foreach ($value as $v) {                $this->_valuesearch[$v] = true;            }        }        $aTemplateData = array(            'context' => $this,            'name' => $this->sName,            'has_id' => ($this->sId !== null),            'id' => $this->sId,            'has_value' => ($this->value !== null),            'value' => $this->value,            'options' => $this->aOptions,            'vocab' => $this->aVocab,	    'lookups' => $this->sLookupsJSON,	    'connections' => $this->sConnectionsJSON,	    'master' => $this->bMaster,	    'masterid' => $this->iMasterId,	    'field' => $this->iField,        );        return $oTemplate->render($aTemplateData);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?