/** * Public Method to create the watermark metadata map in the target project (customized for the import purpose) * @param Docman_Metadata object dm: the metadata object to be checked * @return array ('md' => int matched metadataId, 'love' => related loves) */ public function getWatermarkMetadataMap($md) { // get the metadata iterator from target project $dmd = new Docman_MetadataDao(CodendiDataAccess::instance()); $dar = $dmd->searchByName($this->targetProjectId, $md->getName()); // if the name doesn't match then return md = 0 $dar->rewind(); if (!$dar->valid()) { return array('md' => 0, 'love' => array()); } else { // check metadata properties type, useIt, AllowMultipleValue if it doesn't much then return md = 0 while ($dar->valid()) { $row = $dar->current(); if ($row['use_it'] == $md->isUsed() && $row['data_type'] == $md->getType() && $row['mul_val_ok'] == $md->isMultipleValuesAllowed()) { // it seams that the metadata is ok // check now if source Metadata values already exist $dmlovef = new Docman_MetadataListOfValuesElementFactory($md->getId()); $loveIter = $dmlovef->getIteratorByFieldId($md->getId(), $md->getLabel(), true); $dmloveft = new Docman_MetadataListOfValuesElementFactory($row['field_id']); $loveIter->rewind(); $i = 0; $loves = array(); while ($loveIter->valid()) { $love = $loveIter->current(); $lovetIter = $dmloveft->getByName($love->getName(), $row['field_id'], true); $lovetIter->rewind(); if (!$lovetIter->valid()) { return array('md' => 0, 'love' => array()); } $lovet = $lovetIter->current(); $dwmdvf = new DocmanWatermark_MetadataValueFactory(); $loves[$i]['value_id'] = $lovet->getId(); $loves[$i]['watermark'] = $dwmdvf->isWatermarkedOnValue($love->getId()); $i++; $loveIter->next(); } return array('md' => $row['field_id'], 'love' => $loves); } $dar->next(); } return array('md' => 0, 'love' => array()); } }
/** * Try to find matching values between 2 metadata */ function getLoveMapping($md, $dstMdId, &$metadataMapping) { // Special treatement for value 'Any' that is not recorded in the DB but // that is always 0. $metadataMapping['love'][0] = 0; $loveArray = $this->getListByFieldId($md->getId(), $md->getLabel(), true); $loveIter = new ArrayIterator($loveArray); $loveIter->rewind(); while ($loveIter->valid()) { $love = $loveIter->current(); $dstLoveFactory = new Docman_MetadataListOfValuesElementFactory($dstMdId); $ei = $dstLoveFactory->getByName($love->getName(), $md->getLabel()); if ($ei->count() == 1) { // Found exactly one name that match $ei->rewind(); $dstLove = $ei->current(); // Mapping in both sense to make the usage of the map // easier $metadataMapping['love'][$love->getId()] = $dstLove->getId(); $metadataMapping['love'][$dstLove->getId()] = $love->getId(); } $loveIter->next(); } }