/** * @param Publication $publication * * @return string * @throws exceptions\DBDuplicateEntryException * @throws exceptions\DBForeignKeyException */ public function store(Publication $publication) { if ($publication->getTypeId()) { $type_id = $publication->getTypeId(); } else { $repo = new TypeRepository($this->db); $type = $repo->where('name', '=', $publication->getTypeName())->findSingle(); $type_id = $type->getId(); } if ($publication->getStudyFieldId()) { $study_field_id = $publication->getStudyFieldId(); } else { $repo = new StudyFieldRepository($this->db); $type = $repo->where('name', '=', $publication->getStudyField())->findSingle(); $study_field_id = $type->getId(); } $query = 'INSERT INTO publications (type_id, study_field_id, title, date_published, booktitle, journal, volume, number, pages_from, pages_to, series, edition, note, location, publisher, institution, school, address, isbn, doi, howpublished, abstract, copyright, `foreign`) VALUES (:type_id, :study_field_id, :title, :date_published, :booktitle, :journal, :volume, :number, :pages_from, :pages_to, :series, :edition, :note, :location, :publisher, :institution, :school, :address, :isbn, :doi, :howpublished, :abstract, :copyright, :foreign);'; $this->db->prepare($query); $this->db->bindValue(':type_id', $type_id); $this->db->bindValue(':study_field_id', $study_field_id); $this->db->bindValue(':title', $publication->getTitle()); $this->db->bindValue(':date_published', $publication->getDatePublished()); $this->db->bindValue(':booktitle', $publication->getBooktitle()); $this->db->bindValue(':journal', $publication->getJournal()); $this->db->bindValue(':volume', $publication->getVolume()); $this->db->bindValue(':number', $publication->getNumber()); $this->db->bindValue(':pages_from', $publication->getFirstPage()); $this->db->bindValue(':pages_to', $publication->getLastPage()); $this->db->bindValue(':series', $publication->getSeries()); $this->db->bindValue(':edition', $publication->getEdition()); $this->db->bindValue(':note', $publication->getNote()); $this->db->bindValue(':location', $publication->getLocation()); $this->db->bindValue(':publisher', $publication->getPublisher()); $this->db->bindValue(':institution', $publication->getInstitution()); $this->db->bindValue(':school', $publication->getSchool()); $this->db->bindValue(':address', $publication->getAddress()); $this->db->bindValue(':isbn', $publication->getIsbn()); $this->db->bindValue(':doi', $publication->getDoi()); $this->db->bindValue(':howpublished', $publication->getHowpublished()); $this->db->bindValue(':abstract', $publication->getAbstract()); $this->db->bindValue(':copyright', $publication->getCopyright()); $this->db->bindValue(':foreign', $publication->getForeign()); $this->db->execute(); return $this->db->lastInsertId(); }
/** * @param bool $link * * @return string */ public function showStudyField($link = true) { if ($link) { $url = Request::createUrl(array('p' => 'study_field', 'id' => $this->publication->getStudyFieldId())); return '<a href="' . $this->html($url) . '">' . $this->html($this->publication->getStudyField()) . '</a>'; } else { return $this->html($this->publication->getStudyField()); } }