예제 #1
0
 /**
  * This returns all metadata for the document.
  *
  * <code>
  * $ktapi = new KTAPI();
  * $session = $ktapi->start_system_session();
  * $document = $ktapi->get_document_by_id($documentid);
  * $metadata = $document->get_metadata();
  * foreach($metadata as $fieldset){
  *     echo '<br><br>Fieldset: '.$fieldset['fieldset'];
  *
  *     foreach($fieldset['fields'] as $field){
  *         echo '<br>Field name: '.$field['name'] . ' Value: '. $field['value'];
  *     }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @return array An array of metadata fieldsets and fields
  */
 function get_metadata()
 {
     $doctypeid = $this->document->getDocumentTypeID();
     $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid);
     if (is_null($fieldsets) || PEAR::isError($fieldsets)) {
         return array();
     }
     $results = array();
     foreach ($fieldsets as $fieldset) {
         if ($fieldset->getIsConditional()) {
             /* this is not implemented...*/
             continue;
         }
         $fields = $fieldset->getFields();
         $result = array('fieldset' => $fieldset->getName(), 'description' => $fieldset->getDescription());
         $fieldsresult = array();
         foreach ($fields as $field) {
             $value = '';
             $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field);
             if (!is_null($fieldvalue) && !PEAR::isError($fieldvalue)) {
                 $value = $fieldvalue->getValue();
             }
             $controltype = 'string';
             if ($field->getHasLookup()) {
                 $controltype = 'lookup';
                 if ($field->getHasLookupTree()) {
                     $controltype = 'tree';
                 }
             }
             switch ($controltype) {
                 case 'lookup':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     break;
                 case 'tree':
                     $selection = KTAPI::get_metadata_tree($field->getId());
                     break;
                 default:
                     $selection = array();
             }
             $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value == '' ? 'n/a' : $value, 'blankvalue' => $value == '' ? '1' : '0', 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection);
         }
         $result['fields'] = $fieldsresult;
         $results[] = $result;
     }
     return $results;
 }
 function widgetsForFieldset($fieldsetOrType, $sContainerName, $oDocument = null)
 {
     // this is likely to be called repeatedly.
     if (is_null($this->oWF)) {
         $this->oWF =& KTWidgetFactory::getSingleton();
     }
     // we're going to create one of two things, here:
     //   - conditional fieldset widget
     //   - a "Fieldset" widget
     // FIXME delegate.
     $oFieldset =& $fieldsetOrType;
     $widgets = array();
     $fields = $oFieldset->getFields();
     if ($oFieldset->getIsConditional()) {
         $iMasterId = $oFieldset->getMasterFieldId();
         $oMasterField = DocumentField::get($iMasterId);
         $newfields = array();
         $newfields[] = $oMasterField;
         foreach ($fields as $oField) {
             if ($oField->getId() != $iMasterId) {
                 $newfields[] = $oField;
             }
         }
         foreach ($newfields as $oField) {
             $fname = 'metadata_' . $oField->getId();
             $value = null;
             if (!is_null($oDocument)) {
                 $oFL = DocumentFieldLink::getByDocumentAndField($oDocument, $oField);
                 if (!is_null($oFL) && !PEAR::isError($oFL)) {
                     $value = $oFL->getValue();
                 }
             }
             $widgets[] = $this->oWF->get('ktcore.widgets.conditionalselection', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'id_method' => 'getName', 'label_method' => 'getName', 'unselected_label' => _kt("No selection."), 'simple_select' => false, 'master' => $oField->getId() == $iMasterId, 'masterid' => $iMasterId, 'fieldset' => $oFieldset->getId(), 'field' => $oField->getId()));
         }
     } else {
         foreach ($fields as $oField) {
             $fname = 'metadata_' . $oField->getId();
             $value = null;
             // check if we had an old value
             if (!is_null($oDocument)) {
                 $oFL = DocumentFieldLink::getByDocumentAndField($oDocument, $oField);
                 if (!is_null($oFL) && !PEAR::isError($oFL)) {
                     $value = $oFL->getValue();
                 }
             }
             // we have to hack in support for the hardcoded types of fields
             // handled by the "generic" widget.
             //
             // we try to make this a little more "sane"
             $type = '';
             if ($oField->getHasLookup()) {
                 if ($oField->getHasLookupTree()) {
                     $type = 'ktcore.fields.tree';
                 } else {
                     $type = 'ktcore.fields.lookup';
                 }
             } else {
                 $type = 'ktcore.fields.string';
             }
             if ($type == 'ktcore.fields.string') {
                 $widgets[] = $this->oWF->get('ktcore.widgets.string', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription()));
             } else {
                 if ($type == 'ktcore.fields.lookup') {
                     $widgets[] = $this->oWF->get('ktcore.widgets.entityselection', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'id_method' => 'getName', 'label_method' => 'getName', 'unselected_label' => _kt("No selection."), 'simple_select' => false));
                 } else {
                     if ($type == 'ktcore.fields.tree') {
                         $widgets[] = $this->oWF->get('ktcore.widgets.treemetadata', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'field_id' => $oField->getId()));
                     }
                 }
             }
         }
     }
     return array($this->oWF->get('ktcore.widgets.fieldset', array('label' => $oFieldset->getName(), 'description' => $oFieldset->getDescription(), 'name' => $sContainerName, 'widgets' => $widgets)));
 }