TranslationStashStorage.php

Go to the documentation of this file.
00001 <?php
00014 class TranslationStashStorage {
00015     protected $db;
00016     protected $dbTable;
00017 
00018     public function __construct( DatabaseBase $db, $table = 'translate_stash' ) {
00019         $this->db = $db;
00020         $this->dbTable = $table;
00021     }
00022 
00027     public function addTranslation( StashedTranslation $item ) {
00028         $row = array(
00029             'ts_user' => $item->getUser()->getId(),
00030             'ts_title' => $item->getTitle()->getDBKey(),
00031             'ts_namespace' => $item->getTitle()->getNamespace(),
00032             'ts_value' => $item->getValue(),
00033             'ts_metadata' => serialize( $item->getMetadata() ),
00034         );
00035 
00036         $indexes = array(
00037             array( 'ts_user', 'ts_namespace', 'ts_title'  )
00038         );
00039 
00040         $this->db->replace( $this->dbTable, $indexes, $row, __METHOD__ );
00041     }
00042 
00043 
00049     public function getTranslations( User $user ) {
00050         $conds = array( 'ts_user' => $user->getId() );
00051         $fields = array( 'ts_namespace', 'ts_title', 'ts_value', 'ts_metadata' );
00052 
00053         $res = $this->db->select( $this->dbTable, $fields, $conds, __METHOD__ );
00054 
00055         $objects = array();
00056         foreach ( $res as $row ) {
00057             $objects[] = new StashedTranslation(
00058                 $user,
00059                 Title::makeTitle( $row->ts_namespace, $row->ts_title ),
00060                 $row->ts_value,
00061                 unserialize( $row->ts_metadata )
00062             );
00063         }
00064 
00065         return $objects;
00066     }
00067 
00073     public function deleteTranslations( User $user ) {
00074         $conds = array( 'ts_user' => $user->getId() );
00075         $this->db->delete( $this->dbTable, $conds, __METHOD__ );
00076     }
00077 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3