/** * 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); } }
/** The processor for creating metadata node of Party. Called from create_obj_node. As party-person is different to party-group, there are two sub-functions are called accordingly. * \param $table_name Type: string. The table name will be used to retrieve data from. * \param $id_party Type: integer. Internal party id associated to this party-group. * \see Function create_party. */ private function create_group($table_name, $id_party) { $db = $this->db; // echo 'table: ',$table_name,' party: ',$id_party,"\n"; $query = sprintf("SELECT customer_name, abn, post_code, address, city, state, country, tel, fax, email, www, description FROM %s WHERE id_org = %s", $table_name, $id_party); //echo $query; $res = exec_pdo_query($db, $query); $info = $res->fetch(PDO::FETCH_ASSOC); $c = $this->create_name_node(); $this->create_namePart($c, $info['customer_name']); if (!empty($info['abn'])) { $this->create_identifier_node($info['abn'], 'abn'); } if (!empty($info['description'])) { $this->create_description_node($info['description']); } $l_node = $this->create_location_node(); $a_node = $this->create_address_node($l_node); $this->create_physcial_fone_fax($a_node, $info['tel'], 'telephoneNumber'); $this->create_physcial_fone_fax($a_node, $info['fax'], 'faxNumber'); $add_txt = trim($info['address']) . ', ' . $info['city'] . ' ' . $info['state'] . ' ' . $info['post_code'] . ', ' . $info['country']; $this->create_physcial_addr_txt($a_node, $add_txt); // related objects: // their members: $query = "SELECT list_pub_members({$id_party})"; $res = exec_pdo_query($db, $query); $info = $res->fetch(PDO::FETCH_NUM); foreach ($info as $item) { $this->create_relatedObject($item, 'hasMember'); } }