125 lines
4.6 KiB
PHP
125 lines
4.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class for publishing, updating, deleting, approving entries
|
|
*
|
|
* @author may
|
|
*/
|
|
class publish extends _import {
|
|
|
|
private $authors = [],
|
|
$authors_countries = []; // same order as above, country ids for dict_pub_author.id_country
|
|
|
|
protected $publication_id = 0;
|
|
|
|
/**
|
|
* Add entry for the consideration (review)
|
|
*
|
|
* @param type $json_data Json data from the form
|
|
*/
|
|
public function consider($json_data) {
|
|
|
|
$data = json_decode(htmlspecialchars_decode($json_data));
|
|
|
|
$this->current_recors['topic'] = [];
|
|
$this->current_recors['module'] = [];
|
|
$this->current_recors['round'] = [];
|
|
$this->current_recors['item'] = [];
|
|
|
|
foreach ($data as $element) {
|
|
switch ($element->name) {
|
|
|
|
case 'topic':
|
|
case 'item':
|
|
case 'module':
|
|
case 'round':
|
|
$this->current_record[$element->name][] = $element->value;
|
|
break;
|
|
|
|
default:
|
|
$this->current_record[$element->name] = $element->value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$this->compose_authors()) {
|
|
return "ERROR";
|
|
}
|
|
|
|
// Prepare array for _import::add_publication
|
|
$this->prep_array();
|
|
|
|
if (!$this->publication_id = $this->add_publication(true)) {
|
|
return ('Record already exists in the database.');
|
|
}
|
|
|
|
$this->linkItems();
|
|
$this->linkModules();
|
|
$this->linkTopics();
|
|
$this->linkrounds();
|
|
|
|
return ("OK");
|
|
}
|
|
|
|
private function prep_array() {
|
|
// currently for journal article only
|
|
$this->current_record['citation_data'] = array();
|
|
$this->current_record['citation_data']['journal'] = $this->current_record['journalName']??'';
|
|
$this->current_record['citation_data']['title'] = $this->current_record['title']??'';
|
|
$this->current_record['citation_data']['doi'] = $this->current_record['doi']??'';
|
|
$this->current_record['citation_data']['volume'] = $this->current_record['volume']??'';
|
|
$this->current_record['citation_data']['issue'] = $this->current_record['issue']??'';
|
|
$this->current_record['citation_data']['number'] = $this->current_record['issue']??'';
|
|
$this->current_record['citation_data']['abstract_eng'] = $this->current_record['abstract_eng']??'';
|
|
$this->current_record['citation_data']['abstract_orig'] = $this->current_record['abstract_orig']??'';
|
|
$this->current_record['citation_data']['number'] = $this->current_record['issue']??'';
|
|
$this->current_record['citation_data']['pages'] = $this->current_record['fromPage'] . '--' .$this->current_record['toPage'];
|
|
$this->current_record['citation'] = $this->current_record['citation']??NULL;
|
|
|
|
$this->current_record['year_pub'] = $this->current_record['year']??'';
|
|
$this->current_record['type'] = $this->current_record['pubType']??'';
|
|
|
|
if ($this->current_record['language'] == -1) {
|
|
$this->current_record['language'] = $this->newLanguage($this->current_record['newLang']);
|
|
}
|
|
else {
|
|
$this->current_record['language'] = $this->current_record['language']??'';
|
|
}
|
|
$this->current_record['author_data'] = $this->authors;
|
|
$this->current_record['author_countries'] = $this->authors_countries;
|
|
}
|
|
|
|
|
|
// make sure you insert them
|
|
private function compose_authors () {
|
|
// up to 99 authors
|
|
for ($num=1; $num<100; $num++) {
|
|
|
|
// if author n=x exists
|
|
if (isset ($this->current_record['auth' .$num .'name1'])) {
|
|
|
|
// get the ID
|
|
$auth_id = author::findOrAdd(
|
|
$this->current_record['auth' .$num .'name1'],
|
|
$this->current_record['auth' .$num .'name2'],
|
|
$this->current_record['auth' .$num .'lastname'],
|
|
$this->current_record['auth' .$num .'lastname2'],
|
|
$this->current_record['auth' .$num .'citation']);
|
|
|
|
if ($auth_id!=false) {
|
|
$this->authors[] = $auth_id;
|
|
$this->authors_countries[] = $this->current_record['auth' .$num .'affil'];
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|