示例#1
0
 /**
  *
  * @param SimpleXMLElement $sxeNode
  * @param LexEntryModel $entry
  * @param LiftMergeRule $mergeRule
  * @throws \Exception
  */
 public function readEntry($sxeNode, $entry, $mergeRule = LiftMergeRule::CREATE_DUPLICATES)
 {
     $this->nodeErrors = array();
     $this->nodeErrors[] = new LiftImportNodeError(LiftImportNodeError::ENTRY, (string) $sxeNode['guid']);
     foreach ($sxeNode as $element) {
         switch ($element->getName()) {
             case 'lexical-unit':
                 if ($mergeRule != LiftMergeRule::IMPORT_LOSES || Id::isEmpty($entry->id)) {
                     $entry->guid = (string) $sxeNode['guid'];
                     $entry->authorInfo->createdDate = new \DateTime((string) $sxeNode['dateCreated']);
                     $entry->authorInfo->modifiedDate = new \DateTime((string) $sxeNode['dateModified']);
                     $entry->lexeme = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::LEXEME]->inputSystems);
                 }
                 break;
             case 'citation':
                 $entry->citationForm = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::CITATIONFORM]->inputSystems);
                 break;
             case 'note':
                 if ($element['type'] == '') {
                     $entry->note = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::NOTE]->inputSystems);
                 } else {
                     $this->addKnownUnhandledElement('Note: ' . $element['type']);
                 }
                 break;
             case 'etymology':
                 $entry->etymology = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::ETYMOLOGY]->inputSystems, true);
                 if ($element->{'gloss'}) {
                     $this->readMultiTextGloss($element->gloss, $entry->etymologyGloss, $this->projectModel->config->entry->fields[LexiconConfigObj::ETYMOLOGYGLOSS]->inputSystems);
                 }
                 foreach ($element->{'field'} as $field) {
                     if ($field['type'] == 'comment') {
                         $entry->etymologyComment = $this->readMultiText($field, $this->projectModel->config->entry->fields[LexiconConfigObj::ETYMOLOGYCOMMENT]->inputSystems);
                     } else {
                         $this->currentNodeError()->addUnhandledField($field['type'], 'etymology');
                     }
                 }
                 break;
             case 'pronunciation':
                 $entry->pronunciation = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::PRONUNCIATION]->inputSystems, true);
                 if ($element->{'media'}) {
                     $this->addKnownUnhandledElement('pronunciation: media');
                 }
                 break;
             case 'field':
                 switch ($element['type']) {
                     case 'literal-meaning':
                         $entry->literalMeaning = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::LITERALMEANING]->inputSystems);
                         break;
                     case 'summary-definition':
                         $entry->summaryDefinition = $this->readMultiText($element, $this->projectModel->config->entry->fields[LexiconConfigObj::SUMMARYDEFINITION]->inputSystems);
                         break;
                     case 'import-residue':
                         // Currently ignored in LanguageForge
                         break;
                     default:
                         if ($this->isEntryCustomField($element['type'])) {
                             $this->addEntryCustomField($element, $element['type'], $entry);
                         } else {
                             $this->currentNodeError()->addUnhandledField($element['type']);
                         }
                 }
                 break;
             case 'trait':
                 switch ($element['name']) {
                     case 'morph-type':
                         $entry->morphologyType = (string) $element['value'];
                         break;
                     case 'do-not-publish-in':
                     case 'DoNotUseForParsing':
                         $this->addKnownUnhandledElement('trait: ' . $element['name']);
                         break;
                     default:
                         if ($this->isEntryCustomField($element['name'])) {
                             $this->addEntryCustomField($element, $element['name'], $entry);
                         } else {
                             $this->currentNodeError()->addUnhandledTrait($element['name']);
                         }
                 }
                 break;
             case 'sense':
                 $liftId = '';
                 if (isset($element['id'])) {
                     $liftId = (string) $element['id'];
                 }
                 $existingSenseIndex = $entry->searchSensesFor('liftId', $liftId);
                 if ($existingSenseIndex >= 0) {
                     switch ($mergeRule) {
                         case LiftMergeRule::CREATE_DUPLICATES:
                             $sense = new Sense('');
                             $entry->senses[] = $this->readSense($element, $sense);
                             break;
                         case LiftMergeRule::IMPORT_WINS:
                             $sense = new Sense($liftId);
                             $entry->senses[$existingSenseIndex] = $this->readSense($element, $sense);
                             break;
                         case LiftMergeRule::IMPORT_LOSES:
                             break;
                         default:
                             throw new \Exception("unknown LiftMergeRule " . $mergeRule);
                     }
                 } else {
                     $sense = new Sense($liftId);
                     $entry->senses[] = $this->readSense($element, $sense);
                 }
                 break;
             case 'variant':
             case 'relation':
                 $this->addKnownUnhandledElement('Element: ' . $element->getName());
                 break;
             default:
                 $this->currentNodeError()->addUnhandledElement($element->getName());
         }
     }
     if (!$this->currentNodeError()->hasErrors()) {
         unset($this->nodeErrors[count($this->nodeErrors) - 1]);
     }
 }
 /**
  * Determines if project with given langauge code exists
  * @param string $languageCode
  * @return boolean
  */
 public static function checkProjectExists($languageCode)
 {
     $project = new SemDomTransProjectModel();
     $project->readByCode($languageCode);
     if (Id::isEmpty($project->id)) {
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * Writes the model to the mongo collection
  * @return string The unique id of the object written
  * @see MongoMapper::write()
  */
 public function write()
 {
     CodeGuard::checkTypeAndThrow($this->id, 'Api\\Model\\Mapper\\Id');
     $this->dateModified = new \DateTime();
     if (Id::isEmpty($this->id)) {
         $this->dateCreated = new \DateTime();
     }
     $this->id->id = $this->_mapper->write($this, $this->id->id);
     return $this->id->id;
 }
 public function cleanPreviousProject($languageCode)
 {
     $p = new SemDomTransProjectModel();
     $p->readByCode($languageCode, self::TESTVERSION);
     if (!Id::isEmpty($p->id)) {
         $this->cleanProjectEnvironment($p);
     } else {
         // create the project and then clean the project environment
         $p = new SemDomTransProjectModel();
         $p->projectCode = SemDomTransProjectModel::projectCode($languageCode, self::TESTVERSION);
         $p->write();
         $this->cleanProjectEnvironment($p);
     }
     $p->remove();
 }