- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / private / classes / ezcontentobjectstategrouplanguage.php
1 <?php
2 /**
3  * File containing the eZContentObjectStateGroupLanguage class.
4  *
5  * @copyright Copyright (C) 1999-2010 eZ Systems AS. All rights reserved.
6  * @license http://ez.no/licenses/gnu_gpl GNU GPL v2
7  * @version //autogentag//
8  * @package kernel
9  */
10
11 /**
12  * This class takes care of the localization of a content object state group.
13  *
14  * Instances of this class contain the name and description of a content object state group in a specific language.
15  *
16  * @version //autogentag//
17  * @package kernel
18  * @see eZContentObjectStateGroup
19  */
20 class eZContentObjectStateGroupLanguage extends eZPersistentObject
21 {
22     function __construct( $row = array() )
23     {
24         $this->eZPersistentObject( $row );
25     }
26
27     static function definition()
28     {
29         static $definition = array( "fields" => array( "contentobject_state_group_id" => array( "name" => "ContentObjectStateGroupID",
30                                                                                   "datatype" => "integer",
31                                                                                   "required" => false ),
32                                          "name" => array( "name" => "Name",
33                                                           "datatype" => "string",
34                                                           "required" => false ),
35                                          "description" => array( "name" => "Description",
36                                                                  "datatype" => "text",
37                                                                  "required" => false ),
38                                          "language_id" => array( "name" => "LanguageID",
39                                                                  "datatype" => "integer",
40                                                                  "required" => false ) ),
41                       "keys" => array( "contentobject_state_group_id",
42                                        "language_id" ),
43                       "function_attributes" => array( "language" => "language",
44                                                       "is_valid" => "isValid",
45                                                       "real_language_id" => "realLanguageID",
46                                                     ),
47                       "increment_key" => false,
48                       "class_name" => "eZContentObjectStateGroupLanguage",
49                       "sort" => array(),
50                       "name" => "ezcobj_state_group_language" );
51         return $definition;
52     }
53
54     /**
55      * Retrieve the available languages of a content object state group by its numerical ID
56      *
57      * @param integer $id
58      * @return array an array of eZContentObjectStateGroupLanguage objects
59      */
60     public static function fetchByGroup( $id )
61     {
62         return eZPersistentObject::fetchObjectList( eZContentObjectStateGroupLanguage::definition(), null, array( 'contentobject_state_group_id' => $id ) );
63     }
64
65     /**
66      * Check if the data inside the content object state group language are valid and can be stored in the database
67      *
68      * @param array $messages
69      * @return boolean
70      */
71     public function isValid( &$messages = array() )
72     {
73         $isValid = true;
74         if ( isset( $this->Name ) && strlen( $this->Name ) > 45 )
75         {
76             $messages[] = ezpI18n::translate( 'kernel/state/edit', 'Name in %language_name is too long. Maximum 45 characters allowed.', null, array( '%language_name' => $this->language()->attribute( 'locale_object' )->attribute( 'intl_language_name' ) ) );
77             $isValid = false;
78         }
79
80         if ( ( !isset( $this->Name ) || $this->Name == '' ) && $this->Description != '' )
81         {
82             $messages[] = ezpI18n::translate( 'kernel/state/edit', 'Name in %language_name: input required', null, array( '%language_name' => $this->language()->attribute( 'locale_object' )->attribute( 'intl_language_name' ) ) );
83             $isValid = false;
84         }
85
86         return $isValid;
87     }
88
89     /**
90      * return the eZ Publish content language associated with this content object state group language
91      *
92      * @return eZContentLanguage
93      */
94     public function language()
95     {
96         return eZContentLanguage::fetch( $this->LanguageID & ~1 );
97     }
98
99     /**
100      * Return if this content object state group language has any data to store (= not empty)
101      *
102      * @return boolean
103      */
104     public function hasData()
105     {
106         return ( isset( $this->Name) && trim( $this->Name ) != '' ) || ( isset( $this->Description ) && trim( $this->Description ) != '' );
107     }
108
109     /**
110      * returns the language id, without the always available bit
111      *
112      * @return int language id
113      */
114     public function realLanguageID()
115     {
116         return $this->LanguageID & ~1;
117     }
118 }
119 ?>