Exemple #1
0
 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 do_updateActiveLookups()
 {
     global $default;
     $default->log->error(http_build_query($_REQUEST));
     $active_field = KTUtil::arrayGet($_REQUEST, 'active_field');
     // field which is "active".
     $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup');
     // selected value in said field.
     // REMEMBER TO SET CONTENT-TYPE application/xml
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups');
     $aFieldLookups = KTMetadataUtil::getNextValuesForLookup($selected_lookup);
     $oTemplate->setData(array('aFieldLookups' => $aFieldLookups));
     header("Content-Type: application/xml");
     print $oTemplate->render();
     exit(0);
 }