TranslateMetadata.php

Go to the documentation of this file.
00001 <?php
00013 class TranslateMetadata {
00014     protected static $cache = null;
00015 
00022     public static function get( $group, $key ) {
00023         if ( self::$cache === null ) {
00024             $dbr = wfGetDB( DB_SLAVE );
00025             self::$cache = $dbr->select( 'translate_metadata', '*', array(), __METHOD__ );
00026         }
00027 
00028         foreach ( self::$cache as $row ) {
00029             if ( $row->tmd_group === $group && $row->tmd_key === $key ) {
00030                 return $row->tmd_value;
00031             }
00032         }
00033 
00034         return false;
00035     }
00036 
00044     public static function set( $group, $key, $value ) {
00045         $dbw = wfGetDB( DB_MASTER );
00046         $data = array( 'tmd_group' => $group, 'tmd_key' => $key, 'tmd_value' => $value );
00047         if ( $value === false ) {
00048             unset( $data['tmd_value'] );
00049             $dbw->delete( 'translate_metadata', $data );
00050         } else {
00051             $dbw->replace(
00052                 'translate_metadata',
00053                 array( array( 'tmd_group', 'tmd_key' ) ),
00054                 $data,
00055                 __METHOD__
00056             );
00057         }
00058 
00059         self::$cache = null;
00060     }
00061 
00069     public static function getSubgroups( $groupId ) {
00070         $groups = self::get( $groupId, 'subgroups' );
00071         if ( $groups !== false ) {
00072             if ( strpos( $groups, '|' ) !== false ) {
00073                 $groups = explode( '|', $groups );
00074             } else {
00075                 $groups = array_map( 'trim', explode( ',', $groups ) );
00076             }
00077 
00078             foreach ( $groups as $index => $id ) {
00079                 if ( trim( $id ) === '' ) {
00080                     unset( $groups[$index] );
00081                 }
00082             }
00083         }
00084 
00085         return $groups;
00086     }
00087 
00094     public static function setSubgroups( $groupId, $subgroupIds ) {
00095         $subgroups = implode( '|', $subgroupIds );
00096         self::set( $groupId, 'subgroups', $subgroups );
00097     }
00098 
00104     public static function deleteGroup( $groupId ) {
00105         $dbw = wfGetDB( DB_MASTER );
00106         $conds = array( 'tmd_group' => $groupId );
00107         $dbw->delete( 'translate_metadata', $conds );
00108     }
00109 }
Generated on Tue Oct 29 00:00:26 2013 for MediaWiki Translate Extension by  doxygen 1.6.3