diff --git a/2019/index.php b/2019/index.php index a4f727b..46b9111 100644 --- a/2019/index.php +++ b/2019/index.php @@ -1,421 +1,422 @@ . require 'load.php'; enqueue_js('jquery'); enqueue_js('typed'); enqueue_js('leaflet'); enqueue_js('leaflet.init'); enqueue_css('leaflet'); $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); $conference or die_with_404(); FORCE_PERMALINK and $conference->forceConferencePermalink(); template( 'header', [ 'conference' => $conference, 'intro' => true, ] ); ?>

aula base, l'aula per sistemisti o programmatori e divertiti!" ) ?>

getConferenceStart(); // query all the events that belongs to this conference // and that belongs to this chapter // order by date $events = FullEvent::factoryByConference( $conference->getConferenceID() ) ->whereStr( Track::UID, $track ) ->orderBy( Event::START, 'ASC' ) ->queryResults(); ?> get( Event::START ) ?>

getEventTitle() ) ?>

hasEventSubtitle() ): ?>

getEventSubtitle() ) ?>

-
+

 getEventStart( 'H:i' ) - ?>  (getHumanEventDuration( [ 'long' => false ] ) ?>) +
+   -

+

hasEventAbstract() ): ?>

getEventAbstractHTML() ?>

 info

 

isEventEditable() ): ?> getFullEventEditURL(), __( "Modifica" ) ) ?>
add( $one_hour ); $last_event_end = clone $last_event_start; $last_event_end->add( $one_hour ); ?>

printLocationLeaflet() ?>

. trait EventTrait { /** * Get event ID * * @return int */ public function getEventID() { return $this->nonnull( Event::ID ); } /** * Get event UID * * @return string */ public function getEventUID() { return $this->get( Event::UID ); } /** * Get localized event title * * @return string */ public function getEventTitle() { return __( $this->get( Event::TITLE ) ); } /** * Check if the Event has a subtitle * * @return boolean */ public function hasEventSubtitle() { $title = $this->get( Event::SUBTITLE ); return !empty( $title ); } /** * Get localized event subtitle * * @return string */ public function getEventSubtitle() { return __( $this->get( Event::SUBTITLE ) ); } /** * Get an human event start date * * @return string */ public function getEventHumanStart() { return HumanTime::diff( $this->getEventStart() ); } /** * Get an human event end date * * @return string */ public function getEventHumanEnd() { return HumanTime::diff( $this->getEventEnd() ); } /** * Get event start date * * @param string If present, format of the date * @return DateTime|string */ public function getEventStart( $format = null ) { $date = $this->get( Event::START ); if( $format ) { return $date->format( $format ); } return $date; } /** * When event end date * * @param string If present, format of the date * @return DateTime|string */ public function getEventEnd( $format = null ) { $date = $this->get( Event::END ); if( $format ) { return $date->format( $format ); } return $date; } /** * Get the event duration * * @return DateInterval */ public function getEventDuration( $format ) { $start = $this->get( Event::START ); $end = $this->get( Event::END ); return $start->diff( $end )->format( $format ); } + /** + * Get the Event duration in a human-readable format + * + * @return string + */ + public function getHumanEventDuration( $args = [] ) { + $complete = true; + return HumanTime::diff( + $this->get( Event::START ), + $this->get( Event::END ), + $args + ); + } + /** * It has an Event image? * * @return bool */ public function hasEventImage() { return $this->has( Event::IMAGE ); } /** * Get the path to the Event image * * @param boolean $absolute Try to force an absolute URL * @return string */ public function getEventImage( $absolute = false ) { return site_page( $this->get( Event::IMAGE ), $absolute ); } /** * It has event description? * * @return bool */ public function hasEventDescription() { return null !== $this->get( Event::DESCRIPTION ); } /** * It has an event abstract? * * @return bool */ public function hasEventAbstract() { return null !== $this->get( Event::ABSTRACT ); } /** * It has an event note? * * @return bool */ function hasEventNote() { return null !== $this->get( Event::NOTE ); } /** * Get the event description * * @return string */ public function getEventDescription() { return $this->get( Event::DESCRIPTION ); } /** * Get the event abstract * * @return string */ public function getEventAbstract() { return $this->get( Event::ABSTRACT ); } /** * Get the event note * * @return string */ public function getEventNote() { return $this->get( Event::NOTE ); } function getEventDescriptionHTML( $args = [] ) { return Markdown::parse( __( $this->getEventDescription() ), $args ); } function getEventAbstractHTML( $args = [] ) { return Markdown::parse( __( $this->getEventAbstract() ), $args ); } function getEventNoteHTML( $args = [] ) { return Markdown::parse( __( $this->getEventNote() ), $args ); } /** * Factory Users by this event * * @return Query */ public function factoryUserByEvent() { return User::factoryByEvent( $this->getEventID() ); } /** * Factory Sharables by this event * * @return Query */ public function factorySharebleByEvent() { return Sharable::factoryByEvent( $this->getEventID() ); } /** * You can edit this event? * * @return bool */ public function isEventEditable() { return has_permission('edit-events'); } /** * Insert subscription if not exists */ function addSubscription($email) { $exists = Subscription::getStandardQuery( $email, $this->getEventID() )->getRow('Subscription'); $exists || Subscription::insert( $email, $this->getEventID() ); return $exists; } /** * Get URL to trop-iCal API for this event * * @param boolean $absolute Set to true for an absolute URL * @return string */ public function getEventCalURL( $absolute = false ) { $event = urlencode( $this->getEventUID() ); $conf = urlencode( $this->getConferenceUID() ); return site_page( "api/tropical.php?conference=$conf&event=$event", $absolute ); } /** * Are event subscriptions available? * * @return bool */ public function areEventSubscriptionsAvailable() { return $this->get( 'event_subscriptions' ) && ! $this->isEventPassed(); } /** * Is event passed? * * @return bool */ public function isEventPassed() { $now = new DateTime('now'); return $now->diff( $this->get('event_end') )->invert === 1; } /** * Normalize an Event object */ protected function normalizeEvent() { $this->integers( Event::ID ); $this->datetimes( Event::START, Event::END ); $this->booleans('event_subscriptions'); } } /** * An Event can be a talk or a lesson etc. */ class Event extends Queried { use EventTrait; /** * Database table name */ const T = 'event'; /** * ID column name */ const ID = 'event_ID'; /** * UID column name */ const UID = 'event_uid'; /** * Title column name */ const TITLE = 'event_title'; /** * Subtitle column name */ const SUBTITLE = 'event_subtitle'; /** * Image column name */ const IMAGE = 'event_img'; /** * Start column name */ const START = 'event_start'; /** * End column name */ const END = 'event_end'; /** * Description column name */ const DESCRIPTION = 'event_description'; /** * Abstract column name */ const ABSTRACT = 'event_abstract'; /** * Note column name */ const NOTE = 'event_note'; /** * Language column name */ const LANGUAGE = 'event_language'; /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Complete conference ID column name */ const CONFERENCE_ = self::T . DOT . Conference::ID; /** * Complete room ID column name */ const ROOM_ = self::T . DOT . Room::ID; /** * Complete track ID column name */ const TRACK_ = self::T . DOT . Track::ID; /** * Complete chapter ID column name */ const CHAPTER_ = self::T . DOT . Chapter::ID; /** * Maximum UID length * * @override */ const MAXLEN_UID = 100; /** * Constructor */ public function __construct() { $this->normalizeEvent(); } } diff --git a/includes/class-HumanTime.php b/includes/class-HumanTime.php index 10d322a..d18370e 100644 --- a/includes/class-HumanTime.php +++ b/includes/class-HumanTime.php @@ -1,168 +1,208 @@ . +/** + * Handle time difference in a human-readable format + */ class HumanTime { - static function diff($from, $to = null) { + + /** + * Get the time difference between two dates (or just one date and now) + * + * @param DateTime $from + * @param DateTime $to + * @param array $args + * @return string + */ + public static function diff( $from, $to = null, & $args = [] ) { + + if( !isset( $args['complete'] ) ) { + $args['complete'] = false; + } + + if( !isset( $args['long'] ) ) { + $args['long'] = true; + } + if( $to === null ) { $to = new DateTime('now'); - } + } $diff = $from->diff( $to ); $human = self::humanize( $diff->y, $diff->m, $diff->d, $diff->h, $diff->i, $diff->s, $diff->days, $diff->invert, $from, - $complete + $args ); - if( $complete ) { + if( $args['complete'] ) { return $human; } if( $diff->invert ) { return sprintf( __("fra %s"), $human ); } return sprintf( __("%s fa"), $human ); } - static private function humanize($y, $m, $d, $h, $i, $s, $days, $invert, $from, & $complete) { - $complete = false; + private static function humanize( $y, $m, $d, $h, $i, $s, $days, $invert, $from, & $args ) { + + $long = & $args['long']; + $complete = & $args['complete']; // Top-down: From far away to recently // We are human if( $d > 200 ) { $y++; } if( $y > 1 ) { - return sprintf( __("%d anni"), $y ); + $phrase = $long + ? __("%d anni") + : __( "%d y" ); + return sprintf( $phrase, $y ); } if( $y === 1 ) { - return __("un anno"); + return $long + ? __( "un anno" ) + : __( "1 y" ); } // This year if( $m > 1 ) { - return sprintf( __("%d mesi"), $m ); + $phrase = $long + ? __( "%d mesi" ) + : __( "%d m" ); + return sprintf( $phrase, $m ); } if( $m === 1 ) { - return __("un mese"); + return $long + ? __( "un mese" ) + : __( "1 m" ); } // This month // We are human $d_fake = $d; if( $h > 18 ) { $d_fake++; } - if( $d_fake > 13 ) { + if( $d_fake > 13 && !$long ) { return sprintf( __("%d settimane"), $d_fake / 7 ); } - if( $d_fake > 6 ) { + if( $d_fake > 6 && !$long ) { return __("una settimana"); } if( $d_fake > 1 ) { - return sprintf( __("%d giorni"), $d_fake ); + $phrase = $long + ? __( "%d giorni" ) + : __( "%d d" ); + return sprintf( $phrase, $d_fake ); } if( $d_fake === 1 ) { $complete = true; return $invert ? __("domani") : _("ieri"); } // Today // We are human $h_fake = $h; if( $i > 40 ) { $h_fake++; } if( $h_fake > 3 ) { $complete = true; return __("oggi"); } if( $h > 1 ) { if( $m > 0 ) { return sprintf( __("%d ore e %d minuti"), $h, $i ); } return sprintf( __("%d ore"), $h ); } // In this hour // We are human - $i_fake = $i; + $i_fake = $i + $h * 60; if( $s > 50 ) { $i_fake++; } if( $i_fake > 52 ) { - return __("un'ora"); + return $long + ? __( "un'ora" ) + : __( "1 h" ); } if( $i_fake > 37 ) { return __("tre quarti d'ora"); } if( $i_fake > 22 ) { - return __("mezzora"); + return $long + ? __( "mezzora" ) + : __( "½ h" ); } if( $i_fake > 1 ) { return sprintf( __("%d minuti"), $i_fake ); } if( $i_fake === 1 ) { return sprintf( __("un minuto") ); } if( $s > 10 ) { return sprintf( __("%d secondi"), $s ); } $complete = true; return __("proprio ora"); } }