protected function getNodeForMetadata(Docman_Metadata $metadata)
 {
     $metaDataFactory = new Docman_MetadataFactory($metadata->getGroupId());
     if ($metaDataFactory->isRealMetadata($metadata->getLabel())) {
         $node = $this->doc->createElement('property');
         $node->setAttribute('title', $metadata->getName());
         if ($metadata->getValue() instanceof ArrayIterator) {
             $this->getNodeForMetadataValues($metadata->getValue(), $node);
         } else {
             $value = $metadata->getValue();
             if ($value != '' && $metadata->getType() == PLUGIN_DOCMAN_METADATA_TYPE_DATE) {
                 $value = date('c', $value);
             }
             $node->appendChild($this->doc->createTextNode($value));
         }
         return $node;
     }
 }
Example #2
0
 function testCloneRealMetadata()
 {
     // Parameters
     $dstGroupId = '321';
     $metadataMapping = array();
     // Factory to test
     $srcMdF = new MetadataFactoryMockedForCloneRealMd($this);
     $srcMd1 = new Docman_ListMetadata();
     $srcMd1->setId(301);
     $srcMd1->setType(PLUGIN_DOCMAN_METADATA_TYPE_LIST);
     $srcMd2 = new Docman_Metadata();
     $srcMd2->setId(302);
     $srcMd2->setType(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
     $srcMdF->setReturnValue('getRealMetadataList', array($srcMd1, $srcMd2));
     $srcMdF->expectOnce('getRealMetadataList', array(false));
     $srcMdF->expectCallCount('_cloneOneMetadata', 2);
     $srcMdF->expectAt(0, '_cloneOneMetadata', array($dstGroupId, $srcMd1, $metadataMapping));
     $srcMdF->expectAt(1, '_cloneOneMetadata', array($dstGroupId, $srcMd2, $metadataMapping));
     // Run the test
     $srcMdF->_cloneRealMetadata($dstGroupId, $metadataMapping);
 }
 private function getCustomPropertyName(Docman_Metadata $item_metadata)
 {
     return self::CUSTOM_PROPERTY_PREFIX . '_' . $item_metadata->getId();
 }
 function Docman_ListMetadata()
 {
     parent::Docman_Metadata();
     $this->defaultValue = array();
 }
 /**
  * Create a new metadata based on an existing one in another project.
  *
  * @see cloneMetadata
  * 
  * @param Integer         $dstGroupId      Project where the md is created
  * @param Docman_Metadata $md              Metadata to clone
  * @param Array           $metadataMapping Map between src and dst metadata id
  */
 function _cloneOneMetadata($dstGroupId, $md, &$metadataMapping)
 {
     $dstMdFactory = $this->_getMetadataFactory($dstGroupId);
     $dstMdIter = $dstMdFactory->findByName($md->getName());
     if ($dstMdIter->count() == 0) {
         $newMd = clone $md;
         $newMdId = $dstMdFactory->create($newMd);
         $newMd->setId($newMdId);
         $metadataMapping['md'][$md->getId()] = $newMdId;
         // If current metadata is a list of values, clone values
         if ($newMdId > 0 && $md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
             $srcLoveFactory = $this->_getListOfValuesElementFactory($md->getId());
             $values = $srcLoveFactory->cloneValues($md, $newMd);
             foreach ($values as $srcId => $dstId) {
                 $metadataMapping['love'][$srcId] = $dstId;
             }
         }
         $event_manager = $this->_getEventManager();
         $event_manager->processEvent('plugin_docman_after_metadata_clone', array('srcProjectId' => $this->groupId, 'targetProjectId' => $dstGroupId, 'md' => $md));
     }
 }
 /**
  * Return form to create a new metadata
  */
 function getNewMetadataForm($groupId)
 {
     $content = '';
     $content .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_title') . '</h3>' . "\n";
     $content .= '<form name="admin_create_metadata" method="post" action="?group_id=' . $groupId . '&action=admin_create_metadata" class="docman_form">';
     $content .= '<table>';
     $md = new Docman_Metadata();
     $md->setCanChangeName(true);
     $md->setCanChangeType(true);
     $md->setCanChangeDescription(true);
     $md->setCanChangeIsEmptyAllowed(true);
     $md->setCanChangeIsMultipleValuesAllowed(true);
     $md->setIsEmptyAllowed(true);
     $md->setIsMultipleValuesAllowed(false);
     $sthCanChange = '';
     $metaMdHtml = new Docman_MetaMetadataHtml($md);
     $content .= $metaMdHtml->getName($sthCanChange);
     $content .= $metaMdHtml->getDescription($sthCanChange);
     $content .= $metaMdHtml->getType($sthCanChange);
     $content .= $metaMdHtml->getEmptyAllowed($sthCanChange);
     $content .= $metaMdHtml->getMultipleValuesAllowed($sthCanChange);
     $content .= $metaMdHtml->getUseIt($sthCanChange);
     $content .= '<tr>';
     $content .= '<td colspan="2">';
     $content .= '<input name="submit" type="submit" value="' . $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_submit') . '" />';
     $content .= '</td>';
     $content .= '</tr>';
     $content .= '</table>';
     $content .= '</form>';
     return $content;
 }
 /**
  * Export values in destination metadata.
  *
  * This method perform 2 things:
  * - import the missing values in the current list.
  * - re-order the values with the following paradigm:
  *   - the values defined in the source metadata first (whereever they
  *     where in the current list).
  *   - keep the values that only exists in current list with the same order
  *     but at the end of the list.
  *
  * To achieve the last point (ordering) we use a trick:
  * - reverse the list and add each element of this list at the beginning of
  * the current one.
  * With reverse, the last element of the source list will
  * be the first to be treated. We insert it at the beginning so the last
  * element of the source list will appears before all the existing elements.
  * Then each elements will be inserted at the beginning too so they will 
  * appears in the right order.
  * 
  * @param Docman_Metadata $srcMd   Source metadata
  * @param Docman_Metadata $dstMd   Destination metadata
  * @param Array           $loveMap Map between elements of $srcMd and $dstMd
  */
 function exportValues($srcMd, $dstMd, $loveMap)
 {
     $dstLoveFactory = $this->getMetadataListOfValuesElementFactory($dstMd->getId());
     $srcLoveArray = $this->getListByFieldId($srcMd->getId(), $srcMd->getLabel(), true);
     // \o/ trick \o/
     $reverseLoveArray = array_reverse($srcLoveArray);
     foreach ($reverseLoveArray as $srcLove) {
         if ($srcLove->getId() > PLUGIN_DOCMAN_ITEM_STATUS_NONE) {
             if (!isset($loveMap[$srcLove->getId()])) {
                 $newLove = clone $srcLove;
                 $newLove->setRank('beg');
                 $dstLoveFactory->create($newLove);
             } else {
                 // Update
                 $updLove = clone $srcLove;
                 $updLove->setId($loveMap[$srcLove->getId()]);
                 $updLove->setRank('beg');
                 $dstLoveFactory->update($updLove);
             }
         }
     }
 }
 /**
  * Create a new metadata based on an existing one in another project.
  *
  * @see cloneMetadata
  * 
  * @param Integer         $dstGroupId      Project where the md is created
  * @param Docman_Metadata $md              Metadata to clone
  * @param Array           $metadataMapping Map between src and dst metadata id
  */
 function _cloneOneMetadata($dstGroupId, $md, &$metadataMapping)
 {
     $dstMdFactory = $this->_getMetadataFactory($dstGroupId);
     $dstMdIter = $dstMdFactory->findByName($md->getName());
     if ($dstMdIter->count() == 0) {
         $newMd = clone $md;
         $newMdId = $dstMdFactory->create($newMd);
         $newMd->setId($newMdId);
         $metadataMapping['md'][$md->getId()] = $newMdId;
         // If current metadata is a list of values, clone values
         if ($newMdId > 0 && $md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
             $srcLoveFactory = $this->_getListOfValuesElementFactory($md->getId());
             $values = $srcLoveFactory->cloneValues($md, $newMd);
             foreach ($values as $srcId => $dstId) {
                 $metadataMapping['love'][$srcId] = $dstId;
             }
         }
     }
 }
 function getGlobalSearchMetadata()
 {
     // Special case for a fake metadata: generic text search
     $md = new Docman_Metadata();
     $md->setGroupId($this->groupId);
     $md->setName($GLOBALS['Language']->getText('plugin_docman', 'filters_global_txt'));
     $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_TEXT);
     $md->setUseIt(PLUGIN_DOCMAN_METADATA_USED);
     $md->setLabel('global_txt');
     return $md;
 }