コード例 #1
0
 /**
  * Import metadata.
  *
  * @param Omeka_Record $object The Fedora object record.
  * @param string $dsid The dsid to import.
  */
 public function import($object, $dsid)
 {
     // Get object parent item.
     $item = $object->getItem();
     // Get metadata XML for the datastream.
     $xml = new DOMXPath($this->getMetadataXml($object, $dsid));
     // Get DC elements.
     $elements = $this->db->getTable('Element')->findBySet('Dublin Core');
     // Run queries and write texts.
     foreach ($elements as $element) {
         // Execute for the element.
         $queries = $this->getQueries($element->name);
         $nodes = $this->queryAll($xml, $queries);
         // Write new element texts.
         foreach ($nodes as $node) {
             $text = new ElementText();
             $text->record_id = $item->id;
             $text->record_type = 'Item';
             $text->element_id = $element->id;
             $text->html = 0;
             $text->text = $node->nodeValue;
             $text->save();
         }
     }
 }
コード例 #2
0
 /**
  *Adds an element (text and ID) to an Item
  *
  * @param $record_id Item  The item to which an element will be added
  * @param $element_id string the ID of the element type
  * @param $elementText string the text to add to the element
  * @throws Omeka_Record_Exception
  * @throws Omeka_Validate_Exception
  */
 private function saveElementText($record_id, $element_id, $elementText)
 {
     $text = new ElementText();
     $text->record_id = $record_id;
     $text->record_type = 'Item';
     $text->html = 0;
     $text->element_id = $element_id;
     $text->text = $elementText;
     if ($text->isValid()) {
         $text->save();
     } else {
         throw new Omeka_Validate_Exception('invalid element(Record ID, Element ID, ElementText): ' . strval($record_id) . ',' . $element_id . ',' . $elementText);
     }
 }
コード例 #3
0
 public function perform()
 {
     $db = get_db();
     $elementSet = new ElementSet();
     $elementSet->record_type = "UserProfilesType";
     $elementSet->name = "Contributor Elements";
     $elementSet->description = "";
     $elementSet->save();
     $importData = $this->_importContributorFields($elementSet);
     $type_id = $importData['type_id'];
     $contribFieldElementMap = $importData['contribFieldElementMap'];
     $userContributorMap = unserialize(file_get_contents(CONTRIBUTION_PLUGIN_DIR . '/upgrade_files/user_contributor_map.txt'));
     foreach ($userContributorMap as $userId => $contributorIds) {
         $contribIds = implode(',', $contributorIds);
         $sql = "SELECT * FROM {$db->ContributionContributorValue} WHERE `contributor_id` IN ({$contribIds})";
         $res = $db->query($sql);
         $contributorValues = $res->fetchAll();
         $profile = new UserProfilesProfile();
         $profile->owner_id = $userId;
         $profile->public = true;
         $profile->element_set_id = $elementSet->id;
         $profile->type_id = $type_id;
         $profile->setRelationData(array('subject_id' => $userId));
         $profile->save();
         $elTextArray = array();
         foreach ($contributorValues as $value) {
             //dig up element_id
             $fieldId = $value['field_id'];
             $elementId = $contribFieldElementMap[$fieldId];
             $elementText = new ElementText();
             $elementText->element_id = $elementId;
             $elementText->text = $value['value'];
             $elementText->html = 0;
             $elementText->record_type = 'UserProfilesProfile';
             $elementText->record_id = $profile->id;
             $elementText->save();
             release_object($elementText);
         }
         release_object($profile);
     }
     set_option('user_profiles_contributors_imported', true);
 }
 /**
  * Create an element text for an item.
  *
  * @param Omeka_record $item        The item.
  * @param string       $elementSet  The element set.
  * @param string       $elementName The element name.
  * @param string       $value       The value for the text.
  *
  * @return Omeka_record $text The new text.
  */
 public function __text($item, $elementSet, $elementName, $value)
 {
     // Get tables.
     $_db = get_db();
     $elementTable = $_db->getTable('Element');
     $elementTextTable = $_db->getTable('ElementText');
     $recordTypeTable = $_db->getTable('RecordType');
     // Fetch element record and the item type id.
     $element = $elementTable->findByElementSetNameAndElementName($elementSet, $elementName);
     $itemTypeId = $recordTypeTable->findIdFromName('Item');
     $text = new ElementText();
     $text->record_id = $item->id;
     $text->record_type_id = $itemTypeId;
     $text->element_id = $element->id;
     $text->text = $value;
     $text->save();
     return $text;
 }
コード例 #5
0
 /**
  * This cereates and element text and adds it to an item.
  *
  * @param Item    $item    The item to add the data to.
  * @param Element $element The element to add the text to.
  * @param string  $text    The text data.
  * @param bool    $html    Is the text really HTML? (Default is FALSE.)
  *
  * @return ElementText
  * @author Eric Rochester <*****@*****.**>
  **/
 protected function addElementText($item, $element, $text, $html = 0)
 {
     $etext = new ElementText();
     $etext->setText($text);
     $etext->html = $html;
     $etext->element_id = $element->id;
     $etext->record_id = $item->id;
     $etext->record_type = get_class($item);
     $etext->save();
     $item[$element->name] = $etext;
     return $etext;
 }