/** * @see SpecialSetEntity::getValue() * * @since 0.4 * * @param Fingerprint $fingerprint * @param string $languageCode * * @return string */ protected function getValue(Fingerprint $fingerprint, $languageCode) { if ($fingerprint->hasAliasGroup($languageCode)) { return implode('|', $fingerprint->getAliasGroup($languageCode)->getAliases()); } return ''; }
/** * @param Fingerprint $fingerprint * * @return string[] */ public static function getMainTermsAsLowerCaseStrings(Fingerprint $fingerprint) { $strings = array(); $langsToUse = array('en', 'en-gb'); foreach ($langsToUse as $lang) { try { $strings[] = $fingerprint->getLabel($lang)->getText(); } catch (Exception $e) { // Ignore! } try { $strings = array_merge($strings, $fingerprint->getAliasGroup($lang)->getAliases()); } catch (Exception $e) { // Ignore! } } return array_map('strtolower', $strings); }
/** * Applies the change to the fingerprint * * @param Fingerprint $fingerprint * * @throws ChangeOpException */ private function updateFingerprint(Fingerprint $fingerprint) { if ($fingerprint->getAliasGroups()->hasGroupForLanguage($this->languageCode)) { $oldAliases = $fingerprint->getAliasGroup($this->languageCode)->getAliases(); } else { $oldAliases = array(); } if ($this->action === 'set' || $this->action === '') { $newAliases = $this->aliases; } elseif ($this->action === 'add') { $newAliases = array_merge($oldAliases, $this->aliases); } elseif ($this->action === 'remove') { $newAliases = array_diff($oldAliases, $this->aliases); } else { throw new ChangeOpException('Bad action: ' . $this->action); } $fingerprint->getAliasGroups()->setAliasesForLanguage($this->languageCode, $newAliases); }
/** * @expectedException OutOfBoundsException */ public function testRemoveAliasGroupMakesGetterThrowException() { $this->fingerprint->removeAliasGroup('en'); $this->fingerprint->getAliasGroup('en'); }
/** * @param Fingerprint $fingerprint * * @return ChangeOp[] */ private function getChangeOps(Fingerprint $fingerprint) { $changeOpFactory = $this->changeOpFactory; $changeOps = array(); if ($this->label !== '') { if (!$fingerprint->hasLabel($this->languageCode) || $fingerprint->getLabel($this->languageCode)->getText() !== $this->label) { $changeOps['wbsetlabel'] = $changeOpFactory->newSetLabelOp($this->languageCode, $this->label); } } elseif ($fingerprint->hasLabel($this->languageCode)) { $changeOps['wbsetlabel'] = $changeOpFactory->newRemoveLabelOp($this->languageCode); } if ($this->description !== '') { if (!$fingerprint->hasDescription($this->languageCode) || $fingerprint->getDescription($this->languageCode)->getText() !== $this->description) { $changeOps['wbsetdescription'] = $changeOpFactory->newSetDescriptionOp($this->languageCode, $this->description); } } elseif ($fingerprint->hasDescription($this->languageCode)) { $changeOps['wbsetdescription'] = $changeOpFactory->newRemoveDescriptionOp($this->languageCode); } if (!empty($this->aliases)) { if (!$fingerprint->hasAliasGroup($this->languageCode) || $fingerprint->getAliasGroup($this->languageCode)->getAliases() !== $this->aliases) { $changeOps['wbsetaliases'] = $changeOpFactory->newSetAliasesOp($this->languageCode, $this->aliases); } } elseif ($fingerprint->hasAliasGroup($this->languageCode)) { $changeOps['wbsetaliases'] = $changeOpFactory->newRemoveAliasesOp($this->languageCode, $fingerprint->getAliasGroup($this->languageCode)->getAliases()); } return $changeOps; }