$v) { $this-> $k = utf8_decode($aa[$k]); } } function translateStringToTime($string) { $components = split(' ', $string); $date = $components[0]; $hour = $components[1]; $dateComponents = split('/', $date); $day = $dateComponents[0]; $month = $dateComponents[1]; $year = $dateComponents[2]; $hourComponents = split(':', $hour); $hour = $hourComponents[0]; $minutes = $hourComponents[1]; return mktime($hour, $minutes, 0, $month, $day, $year); } function getCreationDate() { if (isset ($this->creationDate) && (strcmp($this->creationDate, "") != 0)) { return $this->translateStringToTime($this->creationDate); } } function getReferedSubjectBegin() { if (isset ($this->referedSubjectBegin) && (strcmp($this->referedSubjectBegin, "") != 0)) { return $this->translateStringToTime($this->referedSubjectBegin); } } function getReferedSubjectEnd() { if (isset ($this->referedSubjectEnd) && (strcmp($this->referedSubjectEnd, "") != 0)) { return $this->translateStringToTime($this->referedSubjectEnd); } } function getPublicationBegin() { if (isset ($this->publicationBegin) && (strcmp($this->publicationBegin, "") != 0)) { return $this->translateStringToTime($this->publicationBegin); } } function getPublicationEnd() { if (isset ($this->publicationEnd) && (strcmp($this->publicationEnd, "") != 0)) { return $this->translateStringToTime($this->publicationEnd); } } function hasAuthor() { return isset($this->author) && (strcmp($this->author, "") != 0); } function hasPlace() { return isset($this->place) && (strcmp($this->place, "") != 0); } } function readAnnouncementDatabase($data) { if (!isset ($data) || strcmp($data, "") == 0) { return array (); } // read the XML database $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $values, $tags); xml_parser_free($parser); // loop through the structures foreach ($tags as $key => $val) { if ($key == "net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementDTO") { $molranges = $val; for ($i = 0; $i < count($molranges); $i += 2) { $offset = $molranges[$i] + 1; $len = $molranges[$i +1] - $offset; $tdb[] = parseMol(array_slice($values, $offset, $len)); } } else { continue; } } return $tdb; } function parseMol($mvalues) { for ($i = 0; $i < count($mvalues); $i++) { @ $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"]; } return new Announcement($mol); } function eventsComparator($a1, $a2) { $a1ReferedSubjectBegin = $a1->getReferedSubjectBegin(); $a2ReferedSubjectBegin = $a2->getReferedSubjectBegin(); $now = time(); if (isset ($a1ReferedSubjectBegin) && isset ($a2ReferedSubjectBegin)) { if ($a1ReferedSubjectBegin < $now) return 1; if ($a2ReferedSubjectBegin < $now) return -1; return $a1ReferedSubjectBegin - $a2ReferedSubjectBegin; } return 1; } function newsComparator($a1, $a2) { return $a2->getCreationDate() - $a1->getCreationDate(); } function publishedAnnouncementFilter($a) { $today = time(); $announcementPublicationEnd = $a->getPublicationEnd(); $announcementPublicationBegin = $a->getPublicationBegin(); $announcementCreationDate = $a->getCreationDate(); //return (!isset ($announcementPublicationBegin) || $announcementPublicationBegin <= $today) && ($today >= $announcementCreationDate); return (((!isset ($announcementPublicationEnd) || $announcementPublicationEnd >= $today)) && ((!isset ($announcementPublicationBegin) || $announcementPublicationBegin <= $today)) && ($today >= $announcementCreationDate)); } function sameAnnouncement($a1, $a2) { return (strcmp($a1->id, $a2->id) == 0); } function arrayContainsAnnouncement($array, $annouccement) { $result = false; for ($i = 0; $i < count($array); $i++) { if (sameAnnouncement($annouccement, $array[$i])) { $result = true; break; } } return $result; } function removeAnnouncementDuplicates($array) { $newArray = array (); for ($i = 0; $i < count($array); $i++) { if (!arrayContainsAnnouncement($newArray, $array[$i])) { $newArray[count($newArray)] = $array[$i]; } } return $newArray; } function getLatestActiveAnnouncements($board, $howMany, $sorter, $since) { $currentYear = date("Y"); $currentMonth = date("n"); $contents = getAnnouncements($currentMonth, $currentYear, $board); $contents = removeSuccessString($contents); $announcements = readAnnouncementDatabase($contents); $announcements = array_filter($announcements, "publishedAnnouncementFilter"); $i = 0; if (count($announcements) < $howMany) { $previousContentsMonth = $currentMonth; } $previousContentsYear = $currentYear; while (count($announcements) < $howMany && $previousContentsYear >= $since) { $previousContentsMonth--; if ($previousContentsMonth == 0) { $previousContentsMonth = 12; $previousContentsYear--; } $moreContents = getAnnouncements($previousContentsMonth, $previousContentsYear, $board); $moreContents = removeSuccessString($moreContents); $moreAnnouncements = readAnnouncementDatabase($moreContents); $moreAnnouncements = array_filter($moreAnnouncements, "publishedAnnouncementFilter"); $announcements = array_merge($announcements, $moreAnnouncements); $announcements = removeAnnouncementDuplicates($announcements); if ($i == 3) { break; } $i++; } usort($announcements, $sorter); $announcements = array_slice($announcements, 0, $howMany); return $announcements; } function getAnnouncementsFor($month, $year, $board) { $contents = getAnnouncements($month, $year, $board); $contents = removeSuccessString($contents); $announcements = readAnnouncementDatabase($contents); return $announcements; } ?>