From 7583f905dd04b309169be6eb796890891b9ee8e8 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 2 Nov 2010 09:19:48 +0300 Subject: Rename class and new class --- bibtex.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/bibtex.php b/bibtex.php index ef81614..acda55a 100644 --- a/bibtex.php +++ b/bibtex.php @@ -176,7 +176,7 @@ class BibtexParser * Example class for very special purpose * */ -class BibtexParserGoga extends BibtexParser +class BibtexParserTeam extends BibtexParser { protected $entry; @@ -541,5 +541,57 @@ class BibtexParserGoga extends BibtexParser } } + +class BibtexParserWorker extends BibtexParserTeam +{ + /* + * Compare entries for sorting + * + */ + protected function cmp_entries(&$a, &$b) + { + // by entry type + $type = array ( + 'article' => 10, + 'book' => 20, + 'inbook' => 30, + 'booklet' => 40, + 'inproceedings' => 50, + 'grant' => 1000, // for grants, not for publications ;-) + 'misc' => 999999, // We use misc for articles in non-reviewed journals + ); + $x = $type[$a['entry']]; // FIXME : other entry type if needed + $y = $type[$b['entry']]; + if ($x < $y) {return -1;}; + if ($x > $y) {return 1;}; + + // by year (if range - by last year) + $x = preg_match('/.*([0-9]{4})/ui', $a['year'], $matches) ? $matches[1] : 0; + $y = preg_match('/.*([0-9]{4})/ui', $b['year'], $matches) ? $matches[1] : 0; + // die ("$x < $y"); + if ($x > $y) {return -1;}; + if ($x < $y) {return 1;}; + + + // by journal importance, + // which is defined by order of @STRING commands for BiBTeX + // (strings are stored in $this->STRINGS) + $x = empty($a['journal']) ? 'NONE' : $a['journal']; + $y = empty($b['journal']) ? 'NONE' : $b['journal']; + // Not a journal. Maybe grant? + if (($x === 'NONE') && ($y === 'NONE')) + { // 'organization' is my (Igor's) extention + $x = empty($a['organization']) ? 'NONE' : $a['organization']; + $y = empty($b['organization']) ? 'NONE' : $b['organization']; + } + $x = empty($this->STRINGS_o[$x]) ? 999999 : $this->STRINGS_o[$x]; + $y = empty($this->STRINGS_o[$y]) ? 999999 : $this->STRINGS_o[$y]; + if ($x < $y) {return -1;}; + if ($x > $y) {return 1;}; + + return 0; + } +} + ?> -- cgit v1.2.3