diff --git a/includes/class-Event.php b/includes/class-Event.php index eb2b0cc..8dddd25 100644 --- a/includes/class-Event.php +++ b/includes/class-Event.php @@ -1,459 +1,474 @@ . 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 = [] ) { if( !isset( $args['adverb'] ) ) { $args['adverb'] = false; } 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 ); + /** + * Get the Event description rendered in HTML + * + * @return string + */ + public function getEventDescriptionHTML( $args = [] ) { + return Markdown::parse( $this->getEventDescription(), $args ); } - function getEventAbstractHTML( $args = [] ) { - return Markdown::parse( __( $this->getEventAbstract() ), $args ); + /** + * Get the Event abstract rendered in HTML + * + * @return string + */ + public function getEventAbstractHTML( $args = [] ) { + return Markdown::parse( $this->getEventAbstract(), $args ); } - function getEventNoteHTML( $args = [] ) { - return Markdown::parse( __( $this->getEventNote() ), $args ); + /** + * Get the Event notes rendered in HTML + * + * @return string + */ + public 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'; /** * Description 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(); } /** * Generate the appropriate SELECT for the User Abstract * * @return string */ public static function ABSTRACT_L10N() { return i18n_coalesce( self::ABSTRACT, 'event_abstract_%s' ); } /** * Generate the appropriate SELECT for the User Description * * @return string */ public static function DESCRIPTION_L10N() { return i18n_coalesce( self::DESCRIPTION, 'event_description_%s' ); } /** * Generate the appropriate SELECT for the User Description * * @return string */ public static function NOTE_L10N() { return i18n_coalesce( self::NOTE, 'event_description_%s' ); } /** * All the public Event fields * * @return array */ public static function fields() { return [ self::ID_, self::UID, self::TITLE, self::DESCRIPTION_L10N(), self::ABSTRACT_L10N(), self::NOTE_L10n(), self::SUBTITLE, self::IMAGE, self::START, self::END, self::LANGUAGE, ]; } } diff --git a/l10n/mieti.php b/l10n/mieti.php index 453787c..e94d33f 100755 --- a/l10n/mieti.php +++ b/l10n/mieti.php @@ -1,136 +1,134 @@ #!/usr/bin/php . # Usage: # ./mieti.php > trebbia.php require __DIR__ . '/../load.php'; empty( $argv ) and error_die("THIS FILE CAN SPAWN PHP CODE?!? RUN AWAY (╯°□°)╯"); $date = date( 'c' ); // header to be put in trebbia.php echo <<< EOF . # Last update: $date EOF; // end header spawn_gnu( Conference::T, [ Conference::TITLE, Conference::DESCRIPTION, ], Conference::UID ); spawn_gnu( Event::T, [ Event::TITLE, Event::SUBTITLE, - Event::ABSTRACT, - Event::DESCRIPTION, ], Event::UID ); spawn_gnu( Location::T, [ Location::NAME, Location::ADDRESS, Location::NOTE, ] ); spawn_gnu( Track::T, [ Track::NAME, Track::LABEL, ], Track::UID ); spawn_gnu( Chapter::T, [ Chapter::NAME ], Chapter::UID ); spawn_gnu( Room ::T, [ Room ::NAME ], Room ::UID ); spawn_gnu( Skill ::T, [ Skill ::TITLE ], Skill ::UID ); // footer to be put in trebbia.php echo <<< EOF ###################################### ##### Th-th-th-that's all folks! ##### ###################################### EOF; // end footer function spawn_gnu( $from, $fields, $identifier = null ) { if( ! $identifier ) { $identifier = "{$from}_ID"; } // Stripping evil carriage returns from the database $cols = []; foreach( $fields as $field ) { $cols[] = new DBCol( $field, sprintf( 'REPLACE(`%1$s`, \'\r\n\', \'\n\')', $field ), '-' ); } query_update( $from, $cols, '1' /* WHERE 1 */ ); $results = Query::factory() ->select( $fields ) ->select( $identifier ) ->from( $from ) ->queryGenerator(); foreach( $results as $result ) { $uid = $result->get( $identifier ); spawn_linux( $from, $uid, $result, $fields ); } } function spawn_linux( $from, $uid, $obj, $properties ) { foreach( $properties as $property ) { $value = $obj->get( $property ); if( empty( $value ) ) { continue; } echo "\n\n"; printf( "// %s[%s]::%s\n", $from, $uid, $property ); $value = addcslashes( $value, '"\\' ); printf( '__("%s");', $value ); } }