diff --git a/l10n/mieti.php b/l10n/mieti.php index e94d33f..3a3c2bf 100755 --- a/l10n/mieti.php +++ b/l10n/mieti.php @@ -1,134 +1,179 @@ #!/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::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 ); +generate_gnu_gettext_from_table( + Conference::T, + Conference::ID, + // select all Conference(s) with i18n suppport + ( new QueryConference() ) + ->whereConferenceHasI18nSupport(), + [ + Conference::TITLE, + Conference::DESCRIPTION, + ], + Conference::UID +); + +generate_gnu_gettext_from_table( + Event::T, + Event::ID, + // select all Event(s) related to a conference that has i18n suppport + ( new QueryEvent() ) + ->where( + "EXISTS (" . + ( new QueryConference() ) + ->whereConferenceHasI18nSupport() + ->equals( 'conference.conference_ID', 'event.event_ID' ) + ->getQuery() + . ")" + ), + [ + Event::TITLE, + Event::SUBTITLE, + ], + Event::UID +); + +generate_gnu_gettext_from_table( + Location::T, + Location::ID, + null, + [ + Location::NAME, + Location::ADDRESS, + Location::NOTE, + + ] +); + +generate_gnu_gettext_from_table( + Track::T, + Track::ID, + null, + [ + Track::NAME, + Track::LABEL, + ], + Track::UID +); + +generate_gnu_gettext_from_table( Chapter::T, Chapter::ID, null, [ Chapter::NAME ], Chapter::UID ); +generate_gnu_gettext_from_table( Room ::T, Room ::ID, null, [ Room ::NAME ], Room ::UID ); +generate_gnu_gettext_from_table( Skill ::T, Skill ::ID, null, [ 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 ) { +function generate_gnu_gettext_from_table( $table, $id, $query, $fields, $identifier = null ) { if( ! $identifier ) { - $identifier = "{$from}_ID"; + $identifier = $id; + } + + if( !$query ) { + $query = new Query(); + $query->from( $table ); } // 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() + // run clean text fields + ( clone $query ) + ->where( 1 ) // just a condition + ->update( $cols ); + + // select the rows + $results = $query ->select( $fields ) ->select( $identifier ) - ->from( $from ) ->queryGenerator(); + // for each row do something foreach( $results as $result ) { $uid = $result->get( $identifier ); - spawn_linux( $from, $uid, $result, $fields ); + generate_gnu_gettext_from_row( $table, $uid, $result, $fields ); } } -function spawn_linux( $from, $uid, $obj, $properties ) { +function generate_gnu_gettext_from_row( $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 ); } }