/**
  * 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);
             }
         }
     }
 }
コード例 #2
0
 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;
     }
 }