diff --git a/admin/conference.php b/admin/conference.php index 3b2a57a..0685cfb 100644 --- a/admin/conference.php +++ b/admin/conference.php @@ -1,211 +1,212 @@ . require 'load.php'; // check if you can see the backend require_permission( 'backend' ); // current Conference infos $conference = null; $conference_ID = null; // known text fields $TEXT_FIELDS = [ Conference::TITLE => __( "Titolo" ), Conference::ACRONYM => __( "Titolo breve" ), Conference::SUBTITLE => __( "Sottotitolo" ), Conference::UID => __( "Codice" ), + Conference::HOME => __( "Pagina principale" ), Conference::EVENTS_URL => __( "URL Eventi" ), Conference::PERSONS_URL => __( "URL Utenti" ), Conference::START => __( "Inizio" ) . ' YYYY-MM-DD HH:ii:ss', Conference::END => __( "Fine" ) . ' YYYY-MM-DD HH:ii:ss', ]; // check if we should create a new Conference if( isset( $_GET['create'] ) || isset( $_POST['create'] ) ) { // check if you can create a new Conference require_permission( 'add-conference' ); // check if we are editing an already existing Conference } else { // check the current Conference $conference_ID = $_GET['id'] ?? $_POST['id'] ?? 0; // check if the ID has sense if( !$conference_ID ) { error_die( "missing conference id" ); } // query the Conference $conference = ( new QueryConference() ) ->whereConferenceID( $conference_ID ) ->queryRow(); // no Conference no party if( !$conference ) { // I do not want to spend so much time for this http_response_code( 404 ); echo "Missing Conference"; exit; } // check if I'm allowed to edit this conference if( !$conference->isConferenceEditable() ) { // no way missing_privileges(); } } // check if you want to save the Conference if( is_action( 'save-conference' ) ) { // receive data to be saved $data = []; foreach( $TEXT_FIELDS as $field => $label ) { // something can be missing $value = $_POST[ $field ] ?? ''; // cast everything to string // note that it will be escaped later by the Query class $data[ $field ] = (string) $value; } // prepare to query $query = new QueryConference(); // here the user pressed the 'Save' button if( $conference ) { // save existing $query->whereConference( $conference ) ->update( $data ); } else { // create a new one $query->insertRow( $data ); // gotcha! $conference_ID = last_inserted_ID(); } // POST -> redirect -> GET http_redirect( Conference::editURL( [ 'id' => $conference_ID, ] ) ); } // events list $events = []; if( $conference ) { // query all the visible Events related to this Conference $events = ( new QueryEvent() ) ->whereConference( $conference ) ->queryGenerator(); } Header::spawn( null, [ 'title' => __( "Conferenza" ), ] ); ?>
$label ): ?>


{ $field }; // for DateTime(s), show raw date if( $value instanceof DateTime ) { $value = $value->format( 'Y-m-d H:i:s' ); } echo value( $value ); } ?> />

. /* * Event edit * * From this page you can create/edit an User and assign some skills/interests etc. */ // load configurations and framework require 'load.php'; // inherit the Conference or specify one $conference_uid = $_GET['conference_uid'] ?? $_POST['conference_uid'] ?? CURRENT_CONFERENCE_UID; // check if the Conference exists $conference = ( new QueryConference() ) ->whereConferenceUID( $conference_uid ) ->queryRow(); // no Conference no party if( !$conference ) { error( "missing conference with UID $conferene_uid" ); die_with_404(); } // retrieve the Event (if existing) $event = null; if( isset( $_GET['id'] ) ) { // no Event no party $event = ( new QueryEvent() ) ->whereConference( $conference ) ->joinConference() - ->joinChapter() + ->joinChapter( 'LEFT' ) ->whereEventID( $_GET['id'] ) ->queryRow(); // no Event no party if( !$event ) { die_with_404(); } // no editable no party if( !$event->isEventEditable() ) { missing_privileges(); } } else { // check if there are permissions to add event if( !has_permission( 'add-event' ) ) { missing_privileges(); } } $warning = null; // check if the user submitted a form // check which one if( $_POST ) { // the user is submitting the save form if( is_action( 'save-event' ) ) { $conference_ID = $conference->getConferenceID(); $data = []; $data[] = new DBCol( Event::TITLE, $_POST['title'], 's' ); $data[] = new DBCol( Event::UID, $_POST['uid'], 's' ); $data[] = new DBCol( Event::LANGUAGE, $_POST['language'], 's' ); $data[] = new DBCol( Event::SUBTITLE, $_POST['subtitle'], 's' ); $data[] = new DBCol( Event::START, $_POST['start'], 's' ); $data[] = new DBCol( Event::END, $_POST['end'], 's' ); $data[] = new DBCol( Event::IMAGE, $_POST['image'], 'snull' ); $data[] = new DBCol( Chapter::ID, $_POST['chapter'], 'd' ); $data[] = new DBCol( Room::ID, $_POST['room'], 'd' ); $data[] = new DBCol( Track::ID, $_POST['track'], 'd' ); $data[] = new DBCol( Conference::ID, $conference_ID, 'd' ); // for each language save the fields foreach( all_languages() as $lang ) { foreach( Event::fields_i18n() as $i18n_column => $label ) { // generic column name in this language $field = $i18n_column . '_' . $lang->getISO(); // sent column value $value = $_POST[ $field ] ?? null; // prepare to be saved $data[] = new DBCol( $field, $value, 'snull' ); } } // convert empty strings to NULL, if possible foreach( $data as $row ) { $row->promoteNULL(); } if( $event ) { // update the existing Event ( new QueryEvent() ) ->whereEvent( $event ) ->update( $data ); } else { // insert a new Event Event::factory() ->insertRow( $data ); } $id = $event ? $event->getEventID() : last_inserted_ID(); // get the updated Event $event = FullEvent::factory() ->whereInt( Event::ID, $id ) ->queryRow(); // POST-redirect-GET http_redirect( $event->getFullEventEditURL(), 303 ); } /** * Change the Image */ if( $event && is_action( 'change-image' ) ) { // prepare the image uploader $image = new FileUploader( 'image', [ 'category' => 'image', 'override-filename' => "event-" . $event->getEventUID(), ] ); // prepare the image pathnames $img_url = $event->getConferenceUID() . _ . 'images'; $img_path = ABSPATH . __ . $event->getConferenceUID() . __ . 'images'; // really upload that shitty image somewhere if( $image->fileChoosed() ) { $ok = $image->uploadTo( $img_path, $status, $filename, $ext ); if( $ok ) { // now update ( new QueryEvent() ) ->whereEvent( $event ) ->update( [ 'event_img' => $img_url . "/$filename.$ext", ] ); // POST-redirect-GET http_redirect( $event->getFullEventEditURL(), 303 ); } else { $warning = $image->getErrorMessage(); } } } /* * Add the user */ if( $event && is_action( 'add-user' ) && isset( $_POST['user'] ) ) { // Add user $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { ( new QueryEventUser() ) ->whereEvent( $event ) ->whereUser( $user ) ->delete(); ( new QueryEventUser() )->insertRow( [ new DBCol( Event::ID, $event->getEventID(), 'd' ), new DBCol( User ::ID, $user->getUserID(), 'd' ), new DBCol( EventUser::ORDER, 0, 'd' ), ] ); } } /** * Update an user order */ if( $event && is_action( 'update-user' ) && isset( $_POST['user'] ) ) { $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { if ( !empty( $_POST['delete'] ) ) { // Delete user EventUser::delete( $event->getEventID(), $user->getUserID() ); } elseif( isset( $_POST['order'] ) ) { // change order EventUser::factory() ->whereInt( Event::ID, $event->getEventID() ) ->whereInt( User ::ID, $user->getUserID() ) ->update( [ new DBCol( EventUser::ORDER, $_POST['order'], 'd') ] ); } } } // post -> redirect -> get (no: it hide errors) // http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 ); } if( $event ) { Header::spawn( null, [ 'title' => sprintf( __("Modifica %s: %s"), $event->getChapterName(), $event->getEventTitle() ), ] ); } else { Header::spawn( null, [ 'title' => sprintf( __( "Aggiungi %s" ), __( "Evento" ) ), ] ); } ?>

getConferenceURL(), esc_html( $conference->getConferenceTitle() ) . icon( 'home', 'left' ) ) ?>

- + hasEventPermalink() ): ?>

getEventURL(), // text __( "Vedi" ) . icon( 'account_box', 'left' ) ) ?>

get( Event::TITLE ) ); } ?> />
get( Event::UID ) ); } ?> />
get( Event::SUBTITLE ) ); } ?> />
get( Event::LANGUAGE ) ); } ?> />
getEventStart()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['start'] ) ) { echo value( $_GET['start'] ); } ?> />
getEventEnd()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['end'] ) ) { echo value( $_GET['end'] ); } ?> />
$label ): ?>

getISO() ?>
get( Event::IMAGE ) ); } ?>/ > hasEventImage() ): ?> <?= esc_attr( $event->getEventTitle() ) ?>

factoryUserByEvent() ->select( [ User::UID, EventUser::ORDER, ] ) ->defaultClass( EventUser::class ) ->orderBy( EventUser::ORDER ) ->queryGenerator(); ?> valid() ): ?>

$user ): ?>
getUserUID() ) ?> />
getEventUserOrder() ) ?>" />

getUserEditURL(), sprintf( __( "Modifica %s" ), __( "Utente" ) ) ) ?>

. /** * Header of the website */ class Header { /** * Spawn the header * * @param $menu_uid string Menu entry UID (if any) or page title * @param $args array Header arguments */ public static function spawn( $menu_uid = null, $args = [] ) { $menu = $menu_uid ? menu_entry( $menu_uid ) : null; $args = array_replace( [ 'show-title' => true, 'nav-title' => SITE_NAME_SHORT, 'head-title' => null, 'title' => $menu ? $menu->name : null, 'url' => $menu ? keep_url_in_language( $menu->url ) : null, 'not-found' => false, 'user-navbar' => true, 'container' => true, 'alert' => null, 'alert.type' => null, 'noindex' => NOINDEX ], $args ); if( ! isset( $args['og'] ) ) { $args['og'] = []; } $args['og'] = array_replace( [ - 'image' => STATIC_URL . '/ld-2016-logo-purple.png', // It's better an absolute URL here 'type' => 'website', 'url' => $args['url'], 'title' => $args['title'] ], $args['og'] ); if( $args['head-title'] === null ) { $args['head-title'] = sprintf( __("%s - %s"), $args['title'], $args['nav-title'] ); } // force the permalink to this URL if( $args['url'] && FORCE_PERMALINK ) { force_permalink( $args['url'] ); } // sent the proper content type and charset header('Content-Type: text/html; charset=' . CHARSET); // declare that this page was not found if( $args['not-found'] ) { http_response_code( 404 ); } // enqueue_css('materialize'); // enqueue_css('materialize.custom'); // enqueue_css('materialize.icons'); // enqueue_js('jquery'); // enqueue_js('materialize'); // Close header - Start $args['container'] && inject_in_module('footer', function() { ?>
getISO(); ?> <?= esc_html( $args['head-title'] ) ?> $value): ?>

. +// permalink Conference +// %1$d: Conference ID +// %2$s: Conference UID +define_default( 'PERMALINK_CONFERENCE', '%2$s' ); + trait ConferenceTrait { /** * Get conference ID * * @return int */ public function getConferenceID() { return $this->nonnull( Conference::ID ); } /** * Get conference UID * * @return string */ function getConferenceUID() { return $this->get( Conference::UID ); } + /** + * Get the Conference home (if any) + * + * Do not confuse with self#getConferenceURL() that you should use instead. + * + * @return string + */ + public function getConferenceHome() { + return $this->get( Conference::HOME ); + } + /** * Get localized conference title * * @return string */ public function getConferenceTitle() { return __( $this->get( Conference::TITLE ) ); } /** * Get the Conference URL * * @param boolean $absolute Set to true to force an absolute URL * @return string */ public function getConferenceURL( $absolute = false ) { - $url = sprintf( PERMALINK_CONFERENCE, $this->getConferenceUID() ); + + $url = null; + + // check if the home URL is known + $custom_home = $this->getConferenceHome(); + if( $custom_home ) { + + // use the known home URL + $url = $custom_home; + } else { + + // generate the home URL + $url = sprintf( PERMALINK_CONFERENCE, + $this->getConferenceID(), + $this->getConferenceUID() + ); + } + + // normalize this URL to our needs $url = site_page( $url, $absolute ); + + // eventually append the i18n query string if( $this->hasConferenceI18nSupport() ) { $url = keep_url_in_language( $url ); } + return $url; } /** * Get the Conference edit URL * * @param boolean $absolute Set to true to prefere an absolute URL * @return string */ public function getConferenceEditURL() { // query string $args = [ 'id' => $this->getConferenceID(), ]; return Conference::editURL( $args, $absolute ); } /** * Check if the Conference has URLs for every Event * * @return boolean */ public function hasConferenceEventsURL() { return $this->has( 'conference_events_url' ); } + /** + * Get the Conference Events URL format + * + * @return string + */ + public function getConferenceEventsURLFormat() { + return $this->get( Conference::EVENTS_URL ); + } + function getConferenceHumanStart() { return HumanTime::diff( $this->getConferenceStart() ); } function getConferenceHumanEnd() { return HumanTime::diff( $this->getConferenceEnd() ); } /** * Get the Conference date start * * @param string $format If specified, return the formatted date * @return DateTime|string */ public function getConferenceStart( $format = null ) { $date = $this->get( 'conference_start' ); if( $format ) { return $date->format( $format ); } return $date; } /** * Check if this Conference has the internationalization support * * @return boolean */ public function hasConferenceI18nSupport() { return $this->hasConferenceEventsURL(); } /** * Get the Conference date end * * @param string $format If specified, return the formatted date */ public function getConferenceEnd( $format = null ) { $date = $this->get( 'conference_end' ); if( $format ) { return $date->format( $format ); } return $date; } /** * Get URL to trop-iCal API for this conference * * @param boolean $absolute Set to true for an absolute URL * @return string */ function getConferenceCalURL( $absolute = false ) { $conf = urlencode( $this->getConferenceUID() ); return site_page( "api/tropical.php?conference=$conf", $absolute ); } /** * Get localized conference description * * @return string */ public function getConferenceDescription() { return nl2br( __( $this->get( Conference::DESCRIPTION ) ) ); } /** * Get localized conference quote * * @return string */ public function getConferenceQuote() { return nl2br( __( $this->get( 'conference_quote' ) ) ); } /** * Get localized conference subtitle * * @return string */ public function getConferenceSubtitle() { return __( $this->get( Conference::SUBTITLE ) ); } /** * Factory a FullEvent by this conference * * @return Query */ public function factoryFullEventByConference() { return FullEvent::factoryByConference( $this->getConferenceID() ); } /** * Get the URL to create an Event in this Conference * * @param boolean $absolute Flag to have an absolute URL * @return string */ public function getURLToCreateEventInConference( $args = [], $absolute = false ) { $args['conference'] = $this->getConferenceUID(); return FullEvent::editURL( $args, $absolute ); } /** * Check if this Conference is editable by me */ public function isConferenceEditable() { return has_permission( 'edit-conferences' ); } /** * Normalize a Conference object */ protected function normalizeConference() { $this->integers( Conference::ID, Conference::DAYS, Location::ID ); $this->datetimes( Conference::START, Conference::END ); } } /** * A Conference is an event in a certain Location */ class Conference extends Queried { use ConferenceTrait; /** * Database table name */ const T = 'conference'; /** * Conference ID column */ const ID = 'conference_ID'; /** * Conference UID column */ const UID = 'conference_uid'; + /** + * Conference home URL + */ + const HOME = 'conference_home'; + /** * Conference title column */ const TITLE = 'conference_title'; /** * Description column name */ const DESCRIPTION = 'conference_description'; /** * Subtitle column name */ const SUBTITLE = 'conference_subtitle'; /** * Start column name */ const START = 'conference_start'; /** * End column name */ const END = 'conference_end'; /** * Acronym column name */ const ACRONYM = 'conference_acronym'; /** * Persons URL column name */ const PERSONS_URL = 'conference_persons_url'; /** * Events URL column name */ const EVENTS_URL = 'conference_events_url'; /** * Days column name */ const DAYS = 'conference_days'; /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Complete Location ID column name */ const LOCATION_ = self::T . DOT . Location::ID; /** * Maximum UID length * * @override */ const MAXLEN_UID = 32; /** * Constructor */ public function __construct() { $this->normalizeConference(); } /** * Build the conference edit URL * * @param array $args Query string arguments * @param boolean $absolute Flag to prefere an absolute URL * @return string */ public static function editURL( $args = [], $absolute = false ) { // build the base URL $url = site_page( ADMIN_BASE_URL . '/conference.php', $absolute ); // append the query string return http_build_get_query( $url, $args ); } /** * All the public fields of a Conference * * @return array */ public static function fields() { return [ self::ID_, self::TITLE, self::UID, self::TITLE, self::SUBTITLE, self::DESCRIPTION, self::START, self::END, self::ACRONYM, self::PERSONS_URL, self::EVENTS_URL, self::DAYS, ]; } } diff --git a/includes/class-FullEvent.php b/includes/class-FullEvent.php index 6ea776f..5c7a44b 100644 --- a/includes/class-FullEvent.php +++ b/includes/class-FullEvent.php @@ -1,207 +1,220 @@ . class_exists('Event'); class_exists('Conference'); class_exists('Location'); class_exists('Room'); class_exists('Chapter'); class_exists('Track'); trait FullEventTrait { /** * Check if the Event has a permalink * * @return bool */ public function hasEventPermalink() { return $this->has( Conference::UID ) && $this->has( Event ::UID ) && $this->has( Chapter ::UID ); } /** * Get the Event URL * * @param boolean $absolute Set to true to force an absolute URL * @return string */ public function getEventURL( $absolute = false ) { return FullEvent::permalink( $this->getConferenceUID(), $this->getEventUID(), $this->getChapterUID(), + $this->getConferenceEventsURLFormat(), $absolute ); } /** * Create a Query to find the next Event in the same Room * * @return Query */ public function factoryNextFullEvent() { $date = $this->getEventEnd( 'Y-m-d H:i:s' ); return $this->factoryFullEventInSameContext() ->whereStr( 'event_start', $date, '>=' ) ->orderBy( 'event_start', 'ASC' ); } /** * Create a Query to find the previous Event in the same Room * * @return Query */ public function factoryPreviousFullEvent( $compare = '<=' ) { $date = $this->getEventStart( 'Y-m-d H:i:s' ); return $this->factoryFullEventInSameContext() ->whereStr( 'event_end', $date, '<=' ) ->orderBy( 'event_end', 'DESC' ); } /** * Get the edit URL for this FullEvent * * @param boolean $absolute Flag to require an absolute URL * @return string */ public function getFullEventEditURL( $absolute = false ) { return FullEvent::editURL( [ 'uid' => $this->getEventUID(), 'conference' => $this->getConferenceUID() ], $absolute ); } private function factoryFullEventInSameContext() { return FullEvent::factory() ->whereInt( 'event.conference_ID', $this->getConferenceID() ) ->whereInt( 'event.room_ID', $this->getRoomID() ); } } /** * An Event with all the bells and whistles */ class FullEvent extends Queried { use FullEventTrait; use EventTrait; use ConferenceTrait; use LocationTrait; use ChapterTrait; use RoomTrait; use TrackTrait; public function __construct() { $this->normalizeEvent(); $this->normalizeConference(); $this->normalizeChapter(); $this->normalizeRoom(); $this->normalizeTrack(); } /** * Query constructor * * @return Query */ public static function factory() { return ( new QueryEvent() ) ->select( Conference::fields() ) ->select( Event ::fields() ) ->select( Track ::fields() ) ->select( Chapter ::fields() ) ->select( Room ::fields() ) ->joinConference() ->joinTrackChapterRoom() ->defaultClass( __CLASS__ ); } static function factoryByConference( $conference_ID ) { return self::factory() ->whereInt( Event::CONFERENCE_, $conference_ID ); } /** * @deprecate Use self::factoryFromConferenceAndUID() instead */ static function factoryByConferenceAndUID( $conference_ID, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } /** * Factory from a Conference object and the Event UID * * @param object $conference * @param string $event_uid * @return Query */ public static function factoryFromConferenceAndEventUID( $conference, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); $conference_ID = $conference->getConferenceID(); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } static function queryByConferenceAndUID( $conference_ID, $event_uid ) { return self::factoryByConferenceAndUID( $conference_ID, $event_uid ) ->queryRow(); } static function factoryByUser( $user_ID ) { return self::factory() ->from( EventUser::T ) ->equals( EventUser::EVENT_, Event::ID_ ) ->whereInt( EventUser::USER_, $user_ID ) ->orderBy( EventUser::ORDER ); } static function factoryByConferenceChapter( $conference_ID, $chapter_ID ) { return self::factoryByConference( $conference_ID ) ->whereInt( Event::CHAPTER_, $chapter_ID ); } /** * Get an absolute FullEvent permalink * * @param $conference_uid string Conference UID * @param $event_uid string Event UID * @param $chapter_uid string Chapter UID - * @param string $absolute Force an absolute URL + * @param $absolute string Force an absolute URL + * @param $format string Permalink in printf format. Arguments: 1 Conference UID, 2 Event UID, 3 Chapter UID * @return string */ - public static function permalink( $conference_uid, $event_uid, $chapter_uid, $absolute = false ) { - $url = sprintf( PERMALINK_EVENT, $conference_uid, $event_uid, $chapter_uid ) ; + public static function permalink( $conference_uid, $event_uid, $chapter_uid, $absolute = false, $format = null ) { + + // eventually take a default format + if( !$format ) { + $format = PERMALINK_EVENT; + } + + // make the permalink + $url = sprintf( $format, $conference_uid, $event_uid, $chapter_uid ); + + // adapt the URL for our needs $url = site_page( $url, $absolute ); + + // eventually append I18N query string return keep_url_in_language( $url ); } /** * Get the edit URL to a FullEvent * * @param array $args Arguments for the edit page * @param boolean $absolute Flag to require an absolute URL * @return string */ public static function editURL( $args, $absolute = false ) { $url = site_page( ADMIN_BASE_URL . '/edit.php', $absolute ); return http_build_get_query( $url, $args ); } } diff --git a/includes/class-QueryConference.php b/includes/class-QueryConference.php index 48fd951..8dfc2e2 100644 --- a/includes/class-QueryConference.php +++ b/includes/class-QueryConference.php @@ -1,144 +1,144 @@ . /** * Class able to query a Conference */ trait QueryConferenceTrait { /* * Univoque Location ID column name * * Used from ConferenceTrait. * * @var */ protected $LOCATION_ID = 'conference.location_ID'; /** * Limit to a specific Conference * * @param $conference Conference * @return self */ public function whereConference( $conference ) { return $this->whereConferenceID( $conference->getConferenceID() ); } /** * Limit to a specific Conference ID * * @param $id Conference ID * @return self */ public function whereConferenceID( $id ) { return $this->whereInt( $this->CONFERENCE_ID, $id ); } /** * Exclude a specific Conference * * @param $conference Conference * @return self */ public function whereConferenceNot( $conference ) { $id = $conference->getConferenceID(); return $this->joinConference() ->whereInt( Event::CONFERENCE_, $id, '<>' ); } /** * Where the Conference UID is... * * @param string $uid Conference UID * @return self */ public function whereConferenceUID( $uid ) { return $this->whereStr( Conference::UID, $uid ); } /** * Join a table to the Conference table * * You can call it multiple time safely. * * @return self */ public function joinConference() { if( empty( $this->joinedConference ) ) { $this->joinOn( 'INNER', Conference::T, Conference::ID_, $this->CONFERENCE_ID ); $this->joinedConference = true; } return $this; } /** * Join Events to their Location (and Conference. asd) * * You can call it multiple time safely. * * @param string $join_type Join type * @return self */ public function joinLocation( $join_type = 'INNER' ) { if( empty( $this->joinedLocation ) ) { $this->joinOn( $join_type, Location::T, $this->LOCATION_ID, 'location.location_ID' ); $this->joinedLocation = true; } return $this; } /** * Check if the Conference has support for internationalization * * @return self */ public function whereConferenceHasI18nSupport() { return $this->compare( 'conference_events_url', 'IS NOT', 'NULL' ); } } /** * Conference */ class QueryConference extends Query { use QueryConferenceTrait; /* * Univoque Conference ID column name * * Used from ConferenceTrait. * * @var */ protected $CONFERENCE_ID = 'conference.conference_ID'; /** * Constructor */ public function __construct( $db = null ) { // set database connection and default result class - parent::__construct( $db, Conference::class ); + parent::__construct( $db, FullConference::class ); // set the default table $this->from( Conference::T ); } } diff --git a/includes/class-QueryEvent.php b/includes/class-QueryEvent.php index 261ee6d..6e4e4cb 100644 --- a/includes/class-QueryEvent.php +++ b/includes/class-QueryEvent.php @@ -1,199 +1,200 @@ . // load dependent traits class_exists( QueryConference::class, true ); /** * Methods for a QueryEvent class */ trait QueryEventTrait { use QueryConferenceTrait; /** * Where the Event is... * * @param object $event Event * @return self */ public function whereEvent( $event ) { return $this->whereEventID( $event->getEventID() ); } /** * Where the Event ID is... * * @param int $id Event ID * @return self */ public function whereEventID( $id ) { return $this->whereInt( $this->EVENT_ID, $id ); } /** * Where the Event UID is this one * * @param string $uid Event UID * @return self */ public function whereEventUID( $uid ) { return $this->whereStr( Event::UID, $uid ); } /** * Where the Event is editable by me */ public function whereEventIsEditable() { throw new Exception( "to be implemented" ); } } /** * Class able to query a FullEvent. */ class QueryEvent extends Query { use QueryEventTrait; /** * Univoque Event ID column name * * @var */ protected $EVENT_ID = 'event.event_ID'; /** * Univoque Chapter ID column name * * @var */ protected $CHAPTER_ID = 'event.chapter_ID'; /* * Univoque Conference ID column name * * Used from ConferenceTrait#joinConference() * * @var */ protected $CONFERENCE_ID = 'event.conference_ID'; /** * Univoque Track ID column name * * @var */ protected $TRACK_ID = 'event.track_ID'; /** * Univoque Room ID column name * * @var */ protected $ROOM_ID = 'event.room_ID'; /** * Constructor */ public function __construct() { parent::__construct(); $this->from( Event::T ); $this->defaultClass( FullEvent::class ); } /** * Limit to a certain User * * @deprecated * * @param $user User * @return self */ public function whereUser( $user ) { return $this->joinEventUser() ->whereInt( EventUser::USER_, $user->getUserID() ); } /** * Join a table with the Chapter table * + * @param string $type Join type * @return self */ - public function joinChapter() { - return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID ); + public function joinChapter( $type = 'INNER' ) { + return $this->joinOn( $type, 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID ); } /** * Join a table with the Track table * * @return self */ public function joinTrack() { return $this->joinOn( 'INNER', Track::T, Track::ID_, $this->TRACK_ID ); } /** * Join a table with the Room table * * @return self */ public function joinRoom() { return $this->joinOn( 'INNER', Room::T, Room::ID_, $this->ROOM_ID ); } /** * Join Events to User IDs * * You can call it multiple time safely. * * @return self */ public function joinEventUser() { if( empty( $this->joinedEventUser ) ) { $this->from( EventUser::T ); $this->equals( EventUser::EVENT_, Event::ID_ ); $this->joinedEventUser = true; } return $this; } /** * Join Events and their Track, Chapter and Room (can be NULL). * * You can call it multiple time safely. * * @return self */ public function joinTrackChapterRoom() { if( empty( $this->joinedTrackChapterRoom ) ) { $this->from( Room::T ) ->equals( Room::ID_, Event::ROOM_ ); $this->from( Track::T ) ->equals( Track::ID_, Event::TRACK_ ); $this->from( Chapter::T ) ->equals( Chapter::ID_, Event::CHAPTER_ ); $this->joinedTrackChapterRoom = true; } return $this; } }