/**
  * 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;
 }
Esempio n. 2
0
 /**
  * This should actually not be in ktapi, but in webservice
  * This method gets metadata fieldsets based on the document type
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $document_type The type of document
  * @return mixed Error object|SOAP object|Array of fieldsets
  */
 public function get_document_type_metadata($document_type = 'Default')
 {
     // now get document type specifc ids
     $typeid = $this->get_documenttypeid($document_type);
     if (is_a($typeid, 'KTAPI_DocumentTypeError')) {
         return $typeid;
     }
     if (is_null($typeid) || PEAR::isError($typeid)) {
         $response['message'] = $typeid->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     $doctype_ids = KTFieldset::getForDocumentType($typeid, array('ids' => false));
     if (is_null($doctype_ids) || PEAR::isError($doctype_ids)) {
         $response['message'] = $generic_ids->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     // first get generic ids
     $generic_ids = KTFieldset::getGenericFieldsets(array('ids' => false));
     if (is_null($generic_ids) || PEAR::isError($generic_ids)) {
         $response['message'] = $generic_ids->getMessage();
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response);
     }
     // lets merge the results
     $fieldsets = kt_array_merge($generic_ids, $doctype_ids);
     $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 = 'n/a';
             //$controltype = 'string';
             // Replace with true
             $controltype = strtolower($field->getDataType());
             if ($field->getHasLookup()) {
                 $controltype = 'lookup';
                 if ($field->getHasLookupTree()) {
                     $controltype = 'tree';
                 }
             }
             $options = array();
             if ($field->getInetLookupType() == 'multiwithcheckboxes' || $field->getInetLookupType() == 'multiwithlist') {
                 $controltype = 'multiselect';
             }
             switch ($controltype) {
                 case 'lookup':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     break;
                 case 'tree':
                     $selection = KTAPI::get_metadata_tree($field->getId());
                     break;
                 case 'large text':
                     $options = array('ishtml' => $field->getIsHTML(), 'maxlength' => $field->getMaxLength());
                     $selection = array();
                     break;
                 case 'multiselect':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     $options = array('type' => $field->getInetLookupType());
                     break;
                 default:
                     $selection = array();
             }
             $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value, 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection, 'options' => $options);
         }
         $result['fields'] = $fieldsresult;
         $results[] = $result;
     }
     return $results;
 }