private function getCustomPropertyName(Docman_Metadata $item_metadata) { return self::CUSTOM_PROPERTY_PREFIX . '_' . $item_metadata->getId(); }
/** * 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; } } $event_manager = $this->_getEventManager(); $event_manager->processEvent('plugin_docman_after_metadata_clone', array('srcProjectId' => $this->groupId, 'targetProjectId' => $dstGroupId, 'md' => $md)); } }
/** * 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; } } } }