00001 <?php
00002
00016 class PublicationDate extends DataObject {
00017
00019 var $dateFormats;
00020
00024 function PublicationDate() {
00025
00026 $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00027 $this->dateFormats =& $onixCodelistItemDao->getCodes('List55');
00028
00029 parent::DataObject();
00030 }
00031
00036 function getPublicationFormatId() {
00037 return $this->getData('publicationFormatId');
00038 }
00039
00044 function setPublicationformatId($publicationFormatId) {
00045 return $this->setData('publicationFormatId', $publicationFormatId);
00046 }
00047
00052 function setRole($role) {
00053 $this->setData('role', $role);
00054 }
00055
00060 function getRole() {
00061 return $this->getData('role');
00062 }
00063
00068 function setDateFormat($format) {
00069 $this->setData('dateFormat', $format);
00070 }
00071
00076 function getDateFormat() {
00077 return $this->getData('dateFormat');
00078 }
00079
00084 function getNameForONIXCode() {
00085 $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00086 $codes =& $onixCodelistItemDao->getCodes('List163');
00087 return $codes[$this->getRole()];
00088 }
00089
00094 function setDate($date) {
00095 $this->setData('date', $date);
00096 }
00097
00102 function getDate() {
00103 return $this->getData('date');
00104 }
00105
00110 function isHijriCalendar() {
00111 $format = $this->dateFormats[$this->getDateFormat()];
00112 if (stristr($format, '(H)')) {
00113 return true;
00114 } else {
00115 return false;
00116 }
00117 }
00118
00123 function isFreeText() {
00124 $format = $this->dateFormats[$this->getDateFormat()];
00125 if (stristr($format, 'string')) {
00126 return true;
00127 } else {
00128 return false;
00129 }
00130 }
00131
00138 function getReadableDates() {
00139 $format = $this->dateFormats[$this->getDateFormat()];
00140 $dateFormatShort = Config::getVar('general', 'date_format_short');
00141
00142 if ($this->isHijriCalendar()) {
00143 $format = preg_replace('/\s*\(H\)/i', '', $format);
00144 }
00145
00146
00147 $dates = array();
00148
00149 if (!$this->isFreeText()) {
00150
00151
00152
00153 $numbers = str_split($this->getDate());
00154
00155
00156 assert(count($numbers) == count(str_split($format)));
00157
00158
00159
00160 if (substr_count($format, 'Y') == 8) {
00161 preg_match('/^(YYYY.*)(YYYY.*)$/', $format, $matches);
00162 $dateFormats = array($matches[1], $matches[2]);
00163 } else {
00164 $dateFormats = array($format);
00165 }
00166
00167 foreach ($dateFormats as $format) {
00168 $formatCharacters = str_split($format);
00169 $previousFormatCharacter = '';
00170 $thisDate = '';
00171 $separator = '-';
00172 $containsMonth = false;
00173
00174 for ($i = 0 ; $i < count($formatCharacters) ; $i ++) {
00175 switch ($formatCharacters[$i]) {
00176
00177
00178 case 'T':
00179 $separator = ':';
00180 $thisDate .= ' ';
00181 break;
00182 case 'M':
00183 $containsMonth = true;
00184 default:
00185 if ($i > 0 && $previousFormatCharacter != $formatCharacters[$i] && $previousFormatCharacter != 'T') {
00186 $thisDate .= $separator;
00187 }
00188 $thisDate .= $numbers[$i];
00189 break;
00190 }
00191
00192 $previousFormatCharacter = $formatCharacters[$i];
00193 }
00194
00195
00196
00197 if ($containsMonth) {
00198 $thisDate = strftime($dateFormatShort, strtotime($thisDate));
00199 }
00200
00201 $dates[] = $thisDate;
00202
00203 $numbers = array_slice($numbers, count($formatCharacters));
00204 }
00205
00206 } else {
00207 $dates[] = $this->getDate();
00208 }
00209 return $dates;
00210 }
00211 }
00212
00213 ?>