echoln("
Welcome at the AEGEE Photo page. On this page you can find photos of a lot of AEGEE events from the past. On this page, members could upload their own photos.
");
$this->echoln("There are currently " . number_format($this->getPhotoCount(), 0, ",", ".") . " photos online in " . number_format($this->getBookCount(), 0, ",", ".") . " books. ");
$this->echoln("There are " . number_format($this->getEventCount(), 0, ",", ".") . " events of which you can find photos on this page.
");
$photos = $this->getRandomPhotos(2 * MAX_PHOTO_THUMB_COLS + 1);
$this->echoln("Random photos:
");
if( $photos != null ) {
$this->echoln("");
$r = 1;
$colWidth = 100 / MAX_PHOTO_THUMB_COLS;
while( $r <= MAX_PHOTO_THUMB_COLS * 2 ) {
if( $r % MAX_PHOTO_THUMB_COLS == 1 ) {
$this->echoln("");
}
$this->echoln("");
if( isset($photos[$r]) ) {
$title = $this->getPhotoTitle($photos[$r]);
$this->echoln("");
$this->echoln("");
$this->echoln("");
}
$this->echoln(" | ");
if( $r % MAX_PHOTO_THUMB_COLS == 0 ) {
$this->echoln("
");
}
$r++;
}
$this->echoln("
");
$this->echoln("Featured photo:
");
$title = $this->getPhotoTitle($photos[0]);
$this->echoln("");
$this->echoln("");
$this->echoln("
" . $title);
$this->echoln("
");
}
}
private function getPhotoTitle($photo) {
return $photo['event'] . " (" . $this->formatDate($photo['event_start']) . " - " . $this->formatDate($photo['event_end']) . ") - " .
$photo['book'] . " - " .
($photo['comment'] == null ? $photo['nr'] : $photo['nr'] . ": " . $photo['comment']);
}
private function getPhotoCount() {
$queryBuilder = new QueryBuilder($this->getDbMySQL(), "photo");
$queryBuilder->addField(new DBMethodCount("id"), "photoCount");
$result = $this->getDbMySQL()->select($queryBuilder->toQuery());
if( $result->numRows() == 1 ) {
$row = $result->fetchAssoc();
return $row['photoCount'];
}else {
return "unknown";
}
}
private function getBookCount() {
$queryBuilder = new QueryBuilder($this->getDbMySQL(), "book");
$queryBuilder->addField(new DBMethodCount("id"), "bookCount");
$queryBuilder->addWhereGreater("uid", 0);
$queryBuilder->addWhereGreater("photocount", 0);
$result = $this->getDbMySQL()->select($queryBuilder->toQuery());
if( $result->numRows() == 1 ) {
$row = $result->fetchAssoc();
return $row['bookCount'];
}else {
return "unknown";
}
}
private function getEventCount() {
$queryBuilder = new QueryBuilder($this->getDbMySQL(), "event");
$queryBuilder->addField("event.eventcode", "eventCount");
$queryBuilder->addInnerJoin("book", "eventcode", "event.eventcode");
$queryBuilder->addWhereGreater("book.photocount", 0);
$queryBuilder->addGroup("event.eventcode");
$result = $this->getDbMySQL()->select($queryBuilder->toQuery());
return $result->numRows();
}
private function getRandomPhotos($count, $invokeCount = 0) {
$queryBuilder = new QueryBuilder($this->getDbMySQL(), "photo");
$queryBuilder->addField(new DBMethodMax("id"), "maxId");
$result = $this->getDbMySQL()->select($queryBuilder->toQuery());
if( $result->numRows() == 1 ) {
$maxId = $result->fetchAssoc()['maxId'];
$randomIds = array();
for( $i = 0; $i < $count * 2; $i++ ) {
$randomIds[] = mt_rand(1, $maxId);
}
$queryBuilder = new QueryBuilder($this->getDbMySQL(), "photo");
$queryBuilder->addField("photo.id", "photo_id");
$queryBuilder->addField("photo.comment", "comment");
$queryBuilder->addField(array("book_id", "nr", "date_add", "height_thumb", "width_thumb", "height_big", "width_big"));
$queryBuilder->addField("book.title", "book");
$queryBuilder->addField("event.title", "event");
$queryBuilder->addField("event.datestart", "event_start");
$queryBuilder->addField("event.dateend", "event_end");
$queryBuilder->addInnerJoin("book", "id", "photo.book_id", "book");
$queryBuilder->addInnerJoin("event", "eventcode", "book.eventcode", "event");
$queryBuilder->addWhereIn("photo.id", $randomIds);
$queryBuilder->addOrderRandom();
$queryBuilder->setLimit($count);
$result = $this->getDbMySQL()->select($queryBuilder->toQuery());
if( $result != null ) {
$photos = $result->fetchAssocAll();
if( count($photos) < $count ) {
if( $invokeCount < 4 ) {
$photos = array_merge($photos, $this->getRandomPhotos($count - count($photos), $invokeCount + 1));
}
}
return $photos;
}
}
return null;
}
}
?>