public function generateSINMap($request) { $this->clearSINMap(); for ($i = 0; $request->getVal("source_id{$i}"); $i++) { $id = $request->getVal("source_id{$i}"); $namespace = $request->getVal("source_namespace{$i}"); $title = urldecode($request->getVal("source_title{$i}")); $title = ESINHandler::correctSourceTitle($title, $namespace); $recordName = $request->getVal("record_name{$i}"); $page = $request->getVal("source_page{$i}"); $quality = $request->getVal("source_quality{$i}"); $date = $request->getVal("source_date{$i}"); $notes = $request->getVal("source_notes{$i}"); $images = $request->getVal("source_images{$i}"); $text = trim($request->getVal("source_text{$i}")); if (!StructuredData::isEmpty($title) || !StructuredData::isEmpty($recordName) || !StructuredData::isEmpty($page) || !StructuredData::isEmpty($quality) || !StructuredData::isEmpty($date) || !StructuredData::isEmpty($notes) || !StructuredData::isEmpty($images) || !StructuredData::isEmpty($text)) { $found = false; foreach ($this->sources as &$src) { if ($title == $src['title'] && $recordName == $src['record_name'] && $page == $src['page'] && $quality == $src['quality'] && $date == $src['date'] && $notes == $src['notes'] && $images == $src['images'] && $text == $src['source_citation']) { $this->sinMap[$id] = $src['id']; $found = true; break; } } if (!$found) { $newId = 'S' . (count($this->sources) + 1); $this->sinMap[$id] = $newId; $this->sources[] = array('id' => $newId, 'title' => $title, 'record_name' => $recordName, 'page' => $page, 'quality' => $quality, 'date' => $date, 'notes' => $notes, 'images' => $images, 'source_citation' => $text); } } } $foundPrimary = false; for ($i = 0; $request->getVal("image_id{$i}"); $i++) { $id = $request->getVal("image_id{$i}"); $filename = str_replace('_', ' ', urldecode($request->getVal("image_filename{$i}"))); $caption = $request->getVal("image_caption{$i}"); $primary = $request->getVal("image_primary{$i}"); if (!StructuredData::isEmpty($filename)) { if ($primary) { if ($foundPrimary) { $primary = ''; } else { $primary = 'true'; $foundPrimary = true; } } $found = false; foreach ($this->images as &$img) { if ($filename == $img['filename'] && $caption == $img['caption'] && $primary == $img['primary']) { $this->sinMap[$id] = $img['id']; $found = true; break; } } if (!$found) { $newId = 'I' . (count($this->images) + 1); $this->sinMap[$id] = $newId; $this->images[] = array('id' => $newId, 'filename' => $filename, 'caption' => $caption, 'primary' => $primary); } } } for ($i = 0; $request->getVal("note_id{$i}"); $i++) { $id = $request->getVal("note_id{$i}"); $text = trim($request->getVal("note_text{$i}")); if (!StructuredData::isEmpty($text)) { $found = false; foreach ($this->notes as &$note) { if ($text == $note['note']) { $this->sinMap[$id] = $note['id']; $found = true; break; } } if (!$found) { $newId = 'N' . (count($this->notes) + 1); $this->sinMap[$id] = $newId; $this->notes[] = array('id' => $newId, 'note' => $text); } } } }
/** * Return xml elements from data in request * @param unknown $request */ protected function fromEditFields($request) { global $wgESINHandler; // wfDebug("WR:FromEditFields\n"); $result = ''; $wgESINHandler->generateSINMap($request); // must be called before fromEventsFacts or fromSourcesImagesNotes or mapSIN $primaryNameFound = false; for ($i = 0; $i == 0 || $request->getVal("alt_name{$i}"); $i++) { $given = $request->getVal("given{$i}"); $surname = $request->getVal("surname{$i}"); $titlePrefix = $request->getVal("title_prefix{$i}"); $titleSuffix = $request->getVal("title_suffix{$i}"); $sources = $wgESINHandler->mapSIN($request->getVal("name_sources{$i}")); $notes = $wgESINHandler->mapSIN($request->getVal("name_notes{$i}")); if (!StructuredData::isEmpty($given) || !StructuredData::isEmpty($surname) || !StructuredData::isEmpty($titlePrefix) || !StructuredData::isEmpty($titleSuffix) || !StructuredData::isEmpty($sources) || !StructuredData::isEmpty($notes)) { $type = $i == 0 ? '' : $request->getVal("alt_name{$i}"); if (!$primaryNameFound && ($i == 0 || $type == PERSON::$ALT_NAME_TAG)) { $primaryNameFound = true; $result .= $this->addMultiAttrFieldToXml(array('given' => $given, 'surname' => $surname, 'title_prefix' => $titlePrefix, 'title_suffix' => $titleSuffix, 'sources' => $sources, 'notes' => $notes), 'name'); } else { $result .= $this->addMultiAttrFieldToXml(array('type' => $type, 'given' => $given, 'surname' => $surname, 'title_prefix' => $titlePrefix, 'title_suffix' => $titleSuffix, 'sources' => $sources, 'notes' => $notes), 'alt_name'); } } } $result .= $this->addSingleLineFieldToXml($request->getVal('gender'), 'gender'); $result .= $this->fromFamily($request, 'child_of_family'); $result .= $this->fromFamily($request, 'spouse_of_family'); $result .= $wgESINHandler->fromEventsFacts($request, self::$STD_EVENT_TYPES); $result .= $wgESINHandler->fromSourcesImagesNotes($request); $wgESINHandler->clearSINMap(); return $result; }