PDO = $PDO; $this->pub_name = $name; if ($this->pub_name != "") { $this->_cleanName(); } } public function setDOI ($doi) { $this->DOI = $doi; return; } public function setName ($name) { $this->pub_name = $this->_cleanField($name); } public function setLanguage ($language) { $this->language = $this->_cleanField($language); } public function setAbstractOrig ($abstract) { $this->abstract_orig= $this->_cleanField($abstract); } public function setAbstractEng ($abstract) { $this->abstract_eng= $this->_cleanField($abstract); } public function setAuthors ($authors) { $this->authors = $authors; } public function setAuthorsCountries ($authorsCountries) { $this->authorsCountries = $authorsCountries; } public function setYear ($year) { if ($year < 10000) { $this->pub_year = $year; } } public function setCity ($city) { $this->city = $this->_cleanField($city); } public function setPublisher($publisher) { $this->publisher = $this->_cleanField($publisher); } public function setCitation ($citation) { if (strlen($citation)>3) $this->citation = $citation; else $this->citation = NULL; } public function setId_manual ($id_manual) { $this->id_manual = $id_manual; } protected function _cleanField($in) { // make sure it is in form Surname, N. no leading/trailing whitespaces, no double whitespaces,...) // also remove dot (and add it again, later) return trim ($in, " \n\r\t\v\0."); } /** * Add record (after fields are set) * * @param type $authors_processed set to true if you have array of author ids * @return boolean */ public function add($authors_processed=true, &$already_in=false) { // first make sure that publication is in. This also sets publication id ($this->id) if (!$this->_isPublication()) { if (!$this->_addPublication()) { common::except ('Err cannot add publication, terminating (in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__ .')'); return false; } } else { // set id manual if needed $this->_is_ID_manual(); $alredy_in = true; } $this->_linkAuthors($authors_processed); return $this->id; } protected function _isPublisher() { try { $stmt = $this->PDO->prepare("SELECT id FROM l_publisher where name=:name"); $stmt->execute(array($this->publisher)); // this instead of rowCount to make in compatible with non-mysql DB if ($r = $stmt->fetch(PDO::FETCH_NUM)) { $this->publisher_id = $r[0]; return true; } return false; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); } } protected function _addPublisher() { try { $stmt = $this->PDO->prepare("INSERT INTO l_publisher (name) VALUES (:name)"); $stmt->execute(array($this->publisher)); $this->publisher_id = $this->PDO->lastInsertId(); return true; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } protected function _is_ID_manual() { try { $stmt = $this->PDO->prepare("SELECT IF(ISNULL(id_manual),0,id_manual) as idm FROM publication where id=:id"); $stmt->execute(array($this->id)); // this instead of rowCount to make in compatible with non-mysql DB if ($r = $stmt->fetch(PDO::FETCH_NUM)) { if ($r[0] == 0) { try { $stmt = $this->PDO->prepare("UPDATE publication SET id_manual=:id_manual where id=:id"); $stmt->execute(array('id_manual'=>$this->id_manual, 'id'=>$this->id)); return true; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } } } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } return true; } // links authors to publications protected function _linkAuthors($authors_processed = false) { // link authors from array in $this->authors foreach ($this->authors as $offset=>$author) { // in case of import from citation (no author IDS) if (!$authors_processed) { $author = author::isAuthor($author); } $country = $this->authorsCountries[$offset]??NULL; try { $stmt = $this->PDO->prepare("REPLACE INTO dict_pub_author (id_person, id_publication, ord, id_country) VALUES (:author, :pub, :ord, :country)"); $stmt->execute(array( 'author' => $author, 'pub' => $this->id, 'ord' => ($offset+1), 'country' => $country)); } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } } // this is only a placeholder and *MUST GET IMPLEMENTED FOR DERIVED CLASSES* /* protected function _addMaster() { common::except ('PLEASE CREATE DERIVED _addMaster for this type of literature! (in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__ .')'); } */ protected function _addPublication() { if (!$master_id = $this->_addMaster()) { common::except('Cannot find/add master. Record: ' .print_r ($this->citation, true)); return false; } if ($this->type == -1) { common::except ('PLEASE set pub type in derived class!!! (in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__ .')'); return false; } try { $stmt = $this->PDO->prepare("INSERT INTO publication (citation, title_eng, year, type, id_manual, id_parent, doi, abstract_orig, abstract_eng, id_language) VALUES (:citation, :title, :year, :type, :id_manual, :id_master, :doi, :abstract_orig, :abstract_eng, :id_language)"); $stmt->execute(array( 'citation' => $this->citation, 'title' => $this->pub_name, 'year' => $this->pub_year, 'type' => $this->type, 'id_manual' => $this->id_manual, 'id_master' => $master_id, 'doi' => $this->DOI, 'abstract_orig' => $this->abstract_orig, 'abstract_eng' => $this->abstract_eng, 'id_language' => $this->language)); $this->id = $this->PDO->lastInsertId(); return true; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } protected function _isPublication () { try { $stmt = $this->PDO->prepare("SELECT id, doi FROM publication where title_eng = :title_eng AND year=:year AND type=:type"); $stmt->execute(array('title_eng' => $this->pub_name, 'year' => $this->pub_year, 'type' => $this->type)); if ($r = $stmt->fetch(PDO::FETCH_NUM)) { $this->id = $r[0]; // UPDATE DOI if ($this->DOI != "" && $r[1] == "") { $this->_updateDOI(); } return true; } return false; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } private function _updateDOI() { try { $stmt = $this->PDO->prepare("UPDATE publication SET doi=:doi WHERE id=:id"); $stmt->execute(array( 'id' => $this->id, 'doi' => $this->DOI)); return true; } catch (exception $ex) { common::except ('Err: ' .$ex .' in ' .__DIR__ .'/' .__FILE__ .':' .__LINE__); return false; } } public function setPages ($pages) { // doi returns as a--b $pages = str_replace ("--", "-", $pages); $pps = explode ("-", preg_replace('/[^\d-]/', '', $pages)); $this->fromPage = preg_replace ('/\D/', '', $pps[0]); if ($this->fromPage > 32000) { $this->fromPage = 0; } if (count ($pps) > 1) { $this->toPage = preg_replace ('/\D/', '', $pps[1]); if ($this->toPage > 32000) { $this->toPage = 0; } } return; } } ?>