Esempio n. 1
0
 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);
             }
         }
     }
 }