Esempio n. 1
0
    /**
     * This is the general entrance of creating actual content.
     * When anything goes wrong, e.g. found no record, or $set_name is not recognised, an exception will be thrown.
     *
     * \param $set_name Type: string. The name of set is going to be created.
     * \param $key Type: string. The main identifier used in the system. There can be other identifiers.
     */
    public function create_obj_node($set_name, $key) {
        $set_name = strtolower($set_name);
        if (in_array($set_name, prepare_set_names())) {
            try {
                $record = Database::get()->querySingle("select * from oai_record where oai_identifier = ?s", $key);
                $metadata = Database::get()->queryArray("select * from oai_metadata where oai_record = ?d", $record->id);
                
                $meta_record = array();
                foreach ($metadata as $meta_row) {
                    $meta_record[$meta_row->field] = $meta_row->value;
                }
                
                foreach ($meta_record as $rkey => $rvalue) {
                    if (!strncmp($rkey, 'dc_', 3)) {
                        $is_serialized = false;
                        $valArr = @unserialize(base64_decode($rvalue));

                        if ($valArr !== false) {
                            $is_serialized = true;
                        }

                        if ($is_serialized) {
                            foreach ($valArr as $vkey => $vvalue) {
                                // handle multi-dimensional arrays for combined multi-lang & simple multiplicity
                                if (is_array($vvalue)) {
                                    foreach ($vvalue as $vkey2 => $vvalue2) {
                                        $added_node = $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $vvalue2);
                                        // numeric vkeys show simple multiplicity
                                        // string vkeys show multi-lang multiplicity requiring xml:lang attribute
                                        if (!is_numeric($vkey2)) {
                                            $added_node->setAttribute('xml:lang', $vkey2);
                                        }
                                    }
                                } else {
                                    $added_node = $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $vvalue);
                                    // numeric vkeys show simple multiplicity
                                    // string vkeys show multi-lang multiplicity requiring xml:lang attribute
                                    if (!is_numeric($vkey)) {
                                        $added_node->setAttribute('xml:lang', $vkey);
                                    }
                                }
                            }
                        } else {
                            $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $rvalue);
                        }
                    }
                }
            } catch (PDOException $e) {
                echo "$key returned no record.\n";
                echo $e->getMessage();
            }
        } else {
            throw new Exception('Wrong set name was used: ' . $set_name);
        }
    }
Esempio n. 2
0
 /**
  * This is the general entrence of creating actual content.
  * When anything goes wrong, e.g. found no record, or $set_name is not recognised, an exception will be thrown.
  * And for this implementation, data are stored in a database therefore a PDO is needed. But the source can be any.
  *
  * \param $set_name Type: string. The name of set is going to be created.
  * \param $key Type: string. The main identifier used in the system. There can be other identifiers.
  */
 public function create_obj_node($set_name, $key)
 {
     $set_name = strtolower($set_name);
     if (in_array($set_name, prepare_set_names())) {
         try {
             $query = "select * from oai_record where oai_identifier = '" . $key . "'";
             $res = exec_pdo_query($this->db, $query);
             $record = $res->fetch(PDO::FETCH_ASSOC);
             foreach ($record as $rkey => $rvalue) {
                 if (!strncmp($rkey, 'dc_', 3)) {
                     $is_serialized = false;
                     $valArr = @unserialize(base64_decode($rvalue));
                     if ($valArr !== false) {
                         $is_serialized = true;
                     }
                     if ($is_serialized) {
                         foreach ($valArr as $vkey => $vvalue) {
                             // handle multi-dimensional arrays for combined multi-lang & simple multiplicity
                             if (is_array($vvalue)) {
                                 foreach ($vvalue as $vkey2 => $vvalue2) {
                                     $added_node = $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $vvalue2);
                                     // numeric vkeys show simple multiplicity
                                     // string vkeys show multi-lang multiplicity requiring xml:lang attribute
                                     if (!is_numeric($vkey2)) {
                                         $added_node->setAttribute('xml:lang', $vkey2);
                                     }
                                 }
                             } else {
                                 $added_node = $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $vvalue);
                                 // numeric vkeys show simple multiplicity
                                 // string vkeys show multi-lang multiplicity requiring xml:lang attribute
                                 if (!is_numeric($vkey)) {
                                     $added_node->setAttribute('xml:lang', $vkey);
                                 }
                             }
                         }
                     } else {
                         $this->oai_pmh->addChild($this->working_node, str_replace("dc_", "dc:", $rkey), $rvalue);
                     }
                 }
             }
         } catch (PDOException $e) {
             echo "{$key} returned no record.\n";
             echo $e->getMessage();
         }
     } else {
         throw new Exception('Wrong set name was used: ' . $set_name);
     }
 }
Esempio n. 3
0
 /**
  * This is the general entrence of creating actual content. It calls different functions for different type of RIF-CS model.
  * When anything goes wrong, e.g. found no record, or $set_name is not recognised, an exception will be thrown.
  * And for this implementation, data are stored in a database therefore a PDO is needed. But the source can be any.
  *
  * \param $set_name Type: string. The name of set is going to be created. Can be one of activity, collection or party.
  * \param $key Type: string. The main identifier used in ANDS system. There can be other identifier.
  *
  * \see create_activity, create_collection, create_party
  */
 function create_obj_node($set_name, $key)
 {
     $db = $this->db;
     $set_name = strtolower($set_name);
     if (in_array($set_name, prepare_set_names())) {
         try {
             // Get ori_id and which the original table is:
             $query = "select ori_table_name, ori_id from oai_headers where oai_identifier = '" . $key . "'";
             $res = exec_pdo_query($db, $query);
             $record = $res->fetch(PDO::FETCH_ASSOC);
         } catch (PDOException $e) {
             echo "{$key} returned no record.\n";
             echo $e->getMessage();
         }
         $processor = 'create_' . substr($set_name, 6);
         $this->create_regObject(REG_OBJ_GROUP, $key, MY_URI);
         $this->{$processor}($record['ori_table_name'], $record['ori_id']);
         $this->create_identifier_node($key);
         $this->create_identifier_node('table=' . $record['ori_table_name'] . '+id=' . $record['ori_id']);
     } else {
         throw new Exception('Wrong set name was used: ' . $set_name);
     }
 }