private static function process($publication, $format, $serializer) { $record = new MARCRecord(); // Set leader $record->setLeader(self::getLeader()); // Add control fields // Add 007 if electronical publication if (self::isElectronical($format)) { $record->addControlField(new ControlField('007', self::getField007())); } // Add 008 $record->addControlField(new ControlField('008', self::getField008($publication->language, $format, $publication->year))); // Add data fields // Add 020 self::addField020($record, $publication, $format); // Add 024 self::addField024($record, $publication, $format); // Add 040 self::addField040($record); // Add 041 self::addField041($record, $publication); // Add 100 self::addField100($record, $publication); // Add 245 self::addField245($record, $publication); // Add 250 self::addField250($record, $publication); // Add 255 self::addField255($record, $publication); // Add 263 self::addField263($record, $publication); // Add 264 * 2 self::addField264a($record, $publication); self::addField264b($record, $publication, $format); // Add 336 self::addField336($record, $publication); // Add 337 self::addField337($record, $format); // Add 338 self::addField338($record, $format); // Add 490 self::addField490($record, $publication); // Add 502 self::addField502($record, $publication); // Add 530 self::addField530($record, $publication, $format); // Add 594 self::addField594($record, 1); self::addField594($record, 2); // Add 700 self::addField700($record, $publication); // Add 776 self::addField776($record, $publication, $format); // Serialize record return $serializer->serialize($record); }
private static function process($publication, $format, $serializer, $form, $publisher) { $record = new MARCRecord(); // Set leader $record->setLeader(self::getLeader()); // Add control fields // Add 007 $record->addControlField(new ControlField('007', self::getField007($format))); // Add 008 $record->addControlField(new ControlField('008', self::getField008($publication->language, $format, $publication->issued_from_year, $publication->frequency))); // Add data fields // Add 022 self::addField022($record, $publication); // Add 040 self::addField040($record); // Add 041 self::addField041($record, $publication); // Add 222 self::addField222($record, $publication, $format); // Add 245 self::addField245($record, $publication, $publisher); // Add 263 self::addField263($record, $publication); // Add 264 * 2 self::addField264a($record, $publication, $form, $publisher); self::addField264b($record, $publication); // Add 310 self::addField310($record, $publication); // Add 336 self::addField336($record); // Add 337 self::addField337($record, $format); // Add 338 self::addField338($record, $format); // Add 362 self::addField362($record, $publication); // Add 594 self::addField594($record); // Add 710 self::addField710($record, $form, $publisher); // Add 760 self::addField760($record, $publication); // Add 762 self::addField762($record, $publication); // Add 776 self::addField776($record, $publication, $format); // Add 776 self::addField780($record, $publication); // Add 856 self::addField856($record, $publication, $format); // Add 935 self::addField935($record); // Serialize record return $serializer->serialize($record); }
/** * Converts the given record to a human readable format. * @param MARCRecord $record MARC record to be serialized * @return String Record in a human readable format */ public function serialize($record) { // Add leader $marc = 'LDR ' . $record->getLeader() . "\n"; // Go through control fields foreach ($record->getControlFields() as $field) { // Field code $marc .= $field->getTag() . ' '; // Field data $marc .= $field->getData() . "\n"; } // Go through all the data fields foreach ($record->getDataFields() as $field) { // Field code $marc .= $field->getTag() . ' '; // Add indicators $marc .= $field->getInd1(); $marc .= $field->getInd2() . ' '; foreach ($field->getSubfields() as $subfield) { // Add code $marc .= '$' . $subfield->getTag() . ' '; // Add data $marc .= $subfield->getData() . ' '; } $marc .= "\n"; } // Return result return $marc; }
function save_to_db() { global $projects_dir, $pguser; $postednum_str = $this->postednum == "" ? "NULL" : "'{$this->postednum}'"; // Call addslashes() on any members of $this that might contain // single-quotes/apostrophes (because they are unescaped, and // would otherwise break the query). $common_project_settings = "\n t_last_edit = UNIX_TIMESTAMP(),\n up_projectid = '{$this->up_projectid}',\n nameofwork = '" . addslashes($this->nameofwork) . "',\n authorsname = '" . addslashes($this->authorsname) . "',\n language = '{$this->language}',\n genre = '{$this->genre}',\n difficulty = '{$this->difficulty_level}',\n special_code = '{$this->special_code}',\n clearance = '" . addslashes($this->clearance) . "',\n comments = '" . addslashes($this->comments) . "',\n image_source = '{$this->image_source}',\n scannercredit = '" . addslashes($this->scannercredit) . "',\n checkedoutby = '{$this->checkedoutby}',\n postednum = {$postednum_str},\n image_preparer = '{$this->image_preparer}',\n text_preparer = '{$this->text_preparer}',\n extra_credits = '" . addslashes($this->extra_credits) . "',\n deletion_reason= '" . addslashes($this->deletion_reason) . "'\n "; $pm_setter = ''; if (user_is_a_sitemanager()) { // can change PM $pm_setter = " username = '******',"; } else { if (isset($this->clone_projectid)) { // cloning a project. The PM should be the same as // that of the project being cloned, if the user // isn't an SA $res = mysql_query("\n SELECT username\n FROM projects\n WHERE projectid='{$this->clone_projectid}'\n ") or die(mysql_error()); list($projectmanager) = mysql_fetch_row($res); $pm_setter = " username = '******',"; } } if (isset($this->projectid)) { // We are updating an already-existing project. // needn't change $pm_setter, as there is no change if the user // isn't an SA // find out what we are changing from $old_pih = new ProjectInfoHolder(); $fatal_error = $old_pih->set_from_db(TRUE, $this->projectid); if ($fatal_error != '') { $fatal_error = _('site error') . ': ' . $fatal_error; echo "<br><center><font size='+1' color='#ff0000'><b>{$fatal_error}</b></font></center>"; exit; } $changed_fields = get_changed_fields($this, $old_pih); // We're particularly interested in knowing // when the project comments change. if (!in_array('comments', $changed_fields)) { // no change $tlcc_setter = ''; } else { // changed! $tlcc_setter = 't_last_change_comments = UNIX_TIMESTAMP(),'; } // We also want to know if the edit is resulting in the project // effectively being checked out to a new PPer if ($old_pih->state == PROJ_POST_FIRST_CHECKED_OUT && in_array('checkedoutby', $changed_fields)) { $md_setter = 'modifieddate = UNIX_TIMESTAMP(),'; $PPer_checkout = TRUE; } else { $md_setter = ''; $PPer_checkout = FALSE; } // Update the projects database with the updated info mysql_query("\n UPDATE projects SET\n {$pm_setter}\n {$tlcc_setter}\n {$md_setter}\n {$common_project_settings}\n WHERE projectid='{$this->projectid}'\n ") or die(mysql_error()); $details1 = implode(' ', $changed_fields); if ($details1 == '') { // There are no changed fields. // Don't just save '' for the details1 column, // because then do_history() won't be able to distinguish // this case (no changed fields) from old cases // (edit occurred before we started recording changed fields). // Instead, use a special value. $details1 = 'NONE'; } $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'edit', $details1); if (!empty($e)) { die($e); } if ($PPer_checkout) { // we fake the project transition... $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'transition', PROJ_POST_FIRST_CHECKED_OUT, PROJ_POST_FIRST_CHECKED_OUT, $this->checkedoutby); if (!empty($e)) { die($e); } } // Update the MARC record with any info we've received. $project = new Project($this->projectid); $marc_record = $project->load_marc_record(); $this->update_marc_record_from_post($marc_record); $project->save_marc_record($marc_record); } else { // We are creating a new project $this->projectid = uniqid("projectID"); // The project ID if ('' == $pm_setter) { $pm_setter = "username = '******',"; } // Insert a new row into the projects table mysql_query("\n INSERT INTO projects\n SET\n projectid = '{$this->projectid}',\n {$pm_setter}\n state = '" . PROJ_NEW . "',\n modifieddate = UNIX_TIMESTAMP(),\n t_last_change_comments = UNIX_TIMESTAMP(),\n {$common_project_settings}\n ") or die(mysql_error()); $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'creation'); if (!empty($e)) { die($e); } $e = project_allow_pages($this->projectid); if (!empty($e)) { die($e); } // Make a directory in the projects_dir for this project mkdir("{$projects_dir}/{$this->projectid}", 0777) or die("System error: unable to mkdir '{$projects_dir}/{$this->projectid}'"); chmod("{$projects_dir}/{$this->projectid}", 0777); // Do MARC record manipulations $project = new Project($this->projectid); $marc_record = new MARCRecord(); // Save original MARC record, if provided $yaz_array = unserialize(base64_decode($this->original_marc_array_encd)); if ($yaz_array !== FALSE) { $marc_record->load_yaz_array($yaz_array); $project->init_marc_record($marc_record); // Update the MARC record with data from POST $this->update_marc_record_from_post($marc_record); $project->save_marc_record($marc_record); } // Create the project's 'good word list' and 'bad word list'. if (isset($this->clone_projectid)) { // We're creating a project via cloning. // Copy the original project's word-lists. $good_words = load_project_good_words($this->clone_projectid); if (is_string($good_words)) { // It's an error message. echo "{$good_words}<br>\n"; $good_words = array(); } $bad_words = load_project_bad_words($this->clone_projectid); if (is_string($bad_words)) { // It's an error message. echo "{$bad_words}<br>\n"; $bad_words = array(); } } else { // We're creating a project by means other than cloning // (from_nothing, from_marc_record, from_uberproject). // Initialize its GWL and BWL to empty. $good_words = array(); $bad_words = array(); } save_project_good_words($this->projectid, $good_words); save_project_bad_words($this->projectid, $bad_words); } // Create/update the Dublin Core file for the project. // When we get here, the project's database entry has been fully // updated, so we can create a Project object and allow it // to pull the relevant fields from the database. $project = new Project($this->projectid); $project->create_dc_xml_oai($marc_record); // If the project has been posted to PG, make the appropriate transition. if ($this->posted) { $err = project_transition($this->projectid, PROJ_SUBMIT_PG_POSTED, $pguser); if ($err != '') { echo "{$err}<br>\n"; exit; } } }
private function _load_record() { $marc_record = new MARCRecord(); $marc_record->load_yaz_array($this->YAZ_ARRAY); return $marc_record; }
function do_search_and_show_hits() { output_header("Search Results"); echo "<br>"; if (empty($_GET['start'])) { $start = 1; } else { $start = $_GET['start']; } if (!empty($_GET['fq'])) { $fullquery = unserialize(base64_decode($_GET['fq'])); } else { $fullquery = query_format(); } global $external_catalog_locator; $id = yaz_connect($external_catalog_locator); yaz_syntax($id, "usmarc"); yaz_element($id, "F"); yaz_search($id, "rpn", trim($fullquery)); $extra_options = array("timeout" => 60); yaz_wait($extra_options); $errorMsg = yaz_error($id); if (!empty($errorMsg)) { echo "<center>"; echo _("The following error has occurred:"); echo "<br><br>"; echo "<b><i>{$errorMsg}</i></b>"; echo "<p>"; $url = "editproject.php?action=createnew"; echo sprintf(_("Please try again. If the problem recurs, please create your project manually by following this <a href='%s'>link</a>."), $url); echo "</center>"; exit; } echo "<center>"; if (yaz_hits($id) == 0) { echo "<b>"; echo _("There were no results returned."); echo "</b>"; echo "<br>"; echo _("Please search again or click 'No Matches' to create the project manually."); echo "<br>"; } else { echo "<b>"; echo sprintf(_("%d results returned. Note that some non-book results may not be displayed."), yaz_hits($id)); echo "<br>"; echo _("Please pick a result from below:"); echo "</b>"; } echo "</center>"; echo "<br><form method='post' action='editproject.php'>"; echo "<input type='hidden' name='action' value='create_from_marc_record'>"; echo "<table border='0 width='100%' cellpadding='0' cellspacing='0'>"; // ----------------------------------------------------- $hits_per_page = 20; // Perhaps later this can be a PM preference or an option on the form. $i = 1; while ($start <= yaz_hits($id) && $i <= $hits_per_page) { $rec = yaz_record($id, $start, "array"); //if it's not a book don't display it. we might want to uncomment in the future if there are too many records being returned - if (substr(yaz_record($id, $start, "raw"), 6, 1) != "a") { $start++; continue; } $marc_record = new MARCRecord(); $marc_record->load_yaz_array($rec); if ($i % 2 == 1) { echo "<tr>"; } echo "<td width='5%' align='center' valign='top'>"; echo "<input type='radio' name='rec' value='" . base64_encode(serialize($rec)) . "'>"; echo "</td>"; echo "<td width='45%' align='left' valign='top'>"; echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'>"; foreach (array(array('label' => _("Title"), 'value' => $marc_record->title), array('label' => _("Author"), 'value' => $marc_record->author), array('label' => _("Publisher"), 'value' => $marc_record->publisher), array('label' => _("Language"), 'value' => $marc_record->language), array('label' => _("LCCN"), 'value' => $marc_record->lccn), array('label' => _("ISBN"), 'value' => $marc_record->isbn)) as $couple) { $label = $couple['label']; $value = $couple['value']; echo "<tr>"; echo "<td width='20%' align='left' valign='top'><b>{$label}</b>:</td>"; echo "<td align='left' valign='top'>{$value}</td>"; echo "</tr>\n"; } echo "</table><p></td>"; if ($i % 2 != 1) { echo "</tr>\n"; } $i++; $start++; } if ($i % 2 != 1) { echo "</tr>\n"; } // ----------------------------------------------------- $encoded_fullquery = base64_encode(serialize($fullquery)); echo "<tr>"; echo "<td colspan='2' width='50%' align='left' valign='top'>"; if (isset($_GET['start']) && $_GET['start'] - $hits_per_page > 0) { $url = "external_catalog_search.php?action=do_search_and_show_hits&start=" . ($_GET['start'] - $hits_per_page) . "&fq={$encoded_fullquery}"; echo "<a href='{$url}'>Previous</a>"; } else { echo " "; } echo "</td>"; echo "<td colspan='2' width='50%' align='right' valign='top'>"; if ($start + $hits_per_page <= yaz_hits($id)) { $url = "external_catalog_search.php?action=do_search_and_show_hits&start={$start}&fq={$encoded_fullquery}"; echo "<a href='{$url}'>Next</a>"; } else { echo " "; } echo "</td>"; echo "</tr>\n"; // ----------------------------------------------------- echo "</table><br><center>"; if (yaz_hits($id) != 0) { echo "<input type='submit' value='", attr_safe(_("Create the Project")), "'> "; } $label = attr_safe(_('Search Again')); $url = "external_catalog_search.php?action=show_query_form"; echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>"; echo " "; $label = attr_safe(_('No Matches')); $url = "editproject.php?action=createnew"; echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>"; echo " "; $label = attr_safe(_('Quit')); $url = "projectmgr.php"; echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>"; echo "</form>"; echo "</center>"; yaz_close($id); }
/** * Merge component parts to this record * * @param MongoCollection $componentParts Component parts to be merged * * @return int Count of records merged */ public function mergeComponentParts($componentParts) { $count = 0; $parts = []; foreach ($componentParts as $componentPart) { $data = MetadataUtils::getRecordData($componentPart, true); $marc = new MARCRecord($data, '', $this->source, $this->idPrefix); $title = $marc->getFieldSubfields('245', ['a' => 1, 'b' => 1, 'n' => 1, 'p' => 1]); $uniTitle = $marc->getFieldSubfields('240', ['a' => 1, 'n' => 1, 'p' => 1]); if (!$uniTitle) { $uniTitle = $marc->getFieldSubfields('130', ['a' => 1, 'n' => 1, 'p' => 1]); } $additionalTitles = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '740', ['a' => 1]]]); $authors = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '100', ['a' => 1, 'e' => 1]], [MarcRecord::GET_NORMAL, '110', ['a' => 1, 'e' => 1]]]); $additionalAuthors = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '700', ['a' => 1, 'e' => 1]], [MarcRecord::GET_NORMAL, '710', ['a' => 1, 'e' => 1]]]); $duration = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '306', ['a' => 1]]]); $languages = [substr($marc->getField('008'), 35, 3)]; $languages = array_unique(array_merge($languages, $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['a' => 1]], [MarcRecord::GET_NORMAL, '041', ['d' => 1]]], false, true, true))); $originalLanguages = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['h' => 1]]], false, true, true); $subtitleLanguages = $marc->getFieldsSubfields([[MarcRecord::GET_NORMAL, '041', ['j' => 1]]], false, true, true); $id = $componentPart['_id']; $newField = ['i1' => ' ', 'i2' => ' ', 's' => [['a' => $id]]]; if ($title) { $newField['s'][] = ['b' => $title]; } if ($authors) { $newField['s'][] = ['c' => array_shift($authors)]; foreach ($authors as $author) { $newField['s'][] = ['d' => $author]; } } foreach ($additionalAuthors as $addAuthor) { $newField['s'][] = ['d' => $addAuthor]; } if ($uniTitle) { $newField['s'][] = ['e' => $uniTitle]; } if ($duration) { $newField['s'][] = ['f' => reset($duration)]; } foreach ($additionalTitles as $addTitle) { $newField['s'][] = ['g' => $addTitle]; } foreach ($languages as $language) { if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') { $newField['s'][] = ['h' => $language]; } } foreach ($originalLanguages as $language) { if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') { $newField['s'][] = ['i' => $language]; } } foreach ($subtitleLanguages as $language) { if (preg_match('/^\\w{3}$/', $language) && $language != 'zxx' && $language != 'und') { $newField['s'][] = ['j' => $language]; } } $key = MetadataUtils::createIdSortKey($id); $parts["{$key} {$count}"] = $newField; ++$count; } ksort($parts); $this->fields['979'] = array_values($parts); return $count; }