Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • Hawk\App
  • Hawk\ButtonInput
  • Hawk\Cache
  • Hawk\CheckboxInput
  • Hawk\ColorInput
  • Hawk\Conf
  • Hawk\Controller
  • Hawk\Crypto
  • Hawk\DatabaseSessionHandler
  • Hawk\DatetimeInput
  • Hawk\DB
  • Hawk\DBExample
  • Hawk\DeleteInput
  • Hawk\Dialogbox
  • Hawk\EmailInput
  • Hawk\ErrorHandler
  • Hawk\Event
  • Hawk\FileInput
  • Hawk\FileSystem
  • Hawk\FloatInput
  • Hawk\Form
  • Hawk\FormFieldset
  • Hawk\FormInput
  • Hawk\GenericModel
  • Hawk\GifImage
  • Hawk\HawkApi
  • Hawk\HawkUpdater
  • Hawk\HiddenInput
  • Hawk\HtmlInput
  • Hawk\HTTPRequest
  • Hawk\Icon
  • Hawk\Image
  • Hawk\IntegerInput
  • Hawk\ItemList
  • Hawk\ItemListField
  • Hawk\JpegImage
  • Hawk\Lang
  • Hawk\Language
  • Hawk\LeftSidebarTab
  • Hawk\Less
  • Hawk\Logger
  • Hawk\Mail
  • Hawk\MenuItem
  • Hawk\Model
  • Hawk\NoSidebarTab
  • Hawk\NumberInput
  • Hawk\ObjectInput
  • Hawk\Option
  • Hawk\Panel
  • Hawk\PasswordInput
  • Hawk\Permission
  • Hawk\Plugin
  • Hawk\PluginInstaller
  • Hawk\PngImage
  • Hawk\ProfileQuestion
  • Hawk\ProfileQuestionValue
  • Hawk\RadioInput
  • Hawk\Request
  • Hawk\Response
  • Hawk\RightSidebarTab
  • Hawk\Role
  • Hawk\RolePermission
  • Hawk\Route
  • Hawk\Router
  • Hawk\SelectInput
  • Hawk\Session
  • Hawk\Singleton
  • Hawk\SubmitInput
  • Hawk\Tabs
  • Hawk\TextareaInput
  • Hawk\TextInput
  • Hawk\Theme
  • Hawk\TimeInput
  • Hawk\Upload
  • Hawk\User
  • Hawk\View
  • Hawk\View\Plugins\Accordion
  • Hawk\View\Plugins\Button
  • Hawk\View\Plugins\Form
  • Hawk\View\Plugins\Icon
  • Hawk\View\Plugins\Import
  • Hawk\View\Plugins\Panel
  • Hawk\View\Plugins\Tabs
  • Hawk\View\Plugins\Text
  • Hawk\View\Plugins\Uri
  • Hawk\View\Plugins\Widget
  • Hawk\ViewPlugin
  • Hawk\Widget
  • Hawk\WysiwygInput

Traits

  • Hawk\Utils

Exceptions

  • Hawk\AppStopException
  • Hawk\DBExampleException
  • Hawk\DBException
  • Hawk\FileSystemException
  • Hawk\HawkApiException
  • Hawk\ImageException
  • Hawk\MailException
  • Hawk\UploadException
  • Hawk\ViewException
  1 <?php
  2 /**
  3  * Language.php
  4  *
  5  * @author  Elvyrra SAS
  6  * @license http://rem.mit-license.org/ MIT
  7  */
  8 namespace Hawk;
  9 
 10 
 11 /**
 12  * This class the language model
 13  *
 14  * @package BaseModels
 15  */
 16 class Language extends Model{
 17     /**
 18      * The associated table
 19      */
 20     protected static $tablename = "Language";
 21 
 22     /**
 23      * The primary key in the table
 24      */
 25     protected static $primaryColumn = 'tag';
 26 
 27 
 28     /**
 29      * The class instances
 30      */
 31     private static $instances = array();
 32 
 33 
 34     /**
 35      * Find a language by it tag
 36      *
 37      * @param string $tag The language tag to find
 38      *
 39      * @return Language the language instance
 40      */
 41     public static function getByTag($tag){
 42         if(!isset(self::$instances[$tag])) {
 43             self::$instances[$tag] = self::getById($tag);
 44         }
 45 
 46         return self::$instances[$tag];
 47     }
 48 
 49     /**
 50      * Get all active languages
 51      *
 52      * @return array The list of language instances
 53      */
 54     public static function getAllActive(){
 55         return self::getListByExample(
 56             new DBExample(
 57                 array(
 58                 'active' => 1
 59                 )
 60             )
 61         );
 62     }
 63 
 64     /**
 65      * Get the current language
 66      *
 67      * @return Language The current language instance
 68      */
 69     public static function current(){
 70         return self::getByTag(LANGUAGE);
 71     }
 72 
 73     /**
 74      * Set the language as the default one for the application
 75      */
 76     public function setDefault(){
 77         $this->dbo->query('UPDATE '. self::getTable() . ' SET isDefault = CASE WHEN `tag` = :tag THEN 1 ELSE 0 END', array('tag' => $this->tag));
 78     }
 79 
 80 
 81     /**
 82      * Save a set of translations in the language
 83      *
 84      * @param array $translations The translations to save
 85      */
 86     public function saveTranslations($translations){
 87         foreach($translations as $plugin => $trs){
 88             $currentData = Lang::getUserTranslations($plugin, $this->tag);
 89 
 90             if(empty($currentData)) {
 91                 $data = $trs;
 92             }
 93             else{
 94                 $data = array_merge($currentData, $trs);
 95             }
 96             Lang::saveUserTranslations($plugin, $this->tag, $data);
 97         }
 98     }
 99 
100     /**
101      * Remove translations for the language
102      *
103      * @param array $translations The keys to remove
104      */
105     public function removeTranslations($translations){
106         foreach ($translations as $plugin => $keys) {
107             $currentData = Lang::getUserTranslations($plugin, $this->tag);
108             foreach($keys as $key){
109                 unset($currentData[$key]);
110             }
111             Lang::saveUserTranslations($plugin, $this->tag, $currentData);
112         }
113     }
114 }
Hawk - PHP documentation API documentation generated by ApiGen