eZ Publish  [4.0]
ezcontentclassname.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Created on: <02-Oct-2006 13:37:23 dl>
00004 //
00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00006 // SOFTWARE NAME: eZ Publish
00007 // SOFTWARE RELEASE: 4.0.x
00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00009 // SOFTWARE LICENSE: GNU General Public License v2.0
00010 // NOTICE: >
00011 //   This program is free software; you can redistribute it and/or
00012 //   modify it under the terms of version 2.0  of the GNU General
00013 //   Public License as published by the Free Software Foundation.
00014 //
00015 //   This program is distributed in the hope that it will be useful,
00016 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //   GNU General Public License for more details.
00019 //
00020 //   You should have received a copy of version 2.0 of the GNU General
00021 //   Public License along with this program; if not, write to the Free
00022 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 //   MA 02110-1301, USA.
00024 //
00025 //
00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00027 //
00028 
00029 class eZContentClassName extends eZPersistentObject
00030 {
00031     function eZContentClassName( $row )
00032     {
00033         eZPersistentObject::eZPersistentObject( $row );
00034     }
00035 
00036     static function definition()
00037     {
00038         return array( 'fields' => array( 'contentclass_id' => array( 'name' => 'ContentClassID',
00039                                                                      'datatype' => 'integer',
00040                                                                      'default' => 0,
00041                                                                      'required' => true,
00042                                                                      'foreign_class' => 'eZContentClass',
00043                                                                      'foreign_attribute' => 'id',
00044                                                                      'multiplicity' => '1..*' ),
00045                                          'contentclass_version' => array( 'name' => 'ContentClassVersion',
00046                                                                           'datatype' => 'integer',
00047                                                                           'default' => 0,
00048                                                                           'required' => true ),
00049                                          'language_locale' => array( 'name' => 'LanguageLocale',
00050                                                                      'datatype' => 'string',
00051                                                                      'default' => '',
00052                                                                      'required' => true ),
00053                                          'language_id' => array( 'name' => 'LanguageID',
00054                                                                  'datatype' => 'integer',
00055                                                                  'default' => 0,
00056                                                                  'required' => true,
00057                                                                  'foreign_class' => 'eZContentLanguage',
00058                                                                  'foreign_attribute' => 'id',
00059                                                                  'multiplicity' => '1..*' ),
00060                                          'name' => array( 'name' => 'Name',
00061                                                                     'datatype' => 'string',
00062                                                                     'default' => '',
00063                                                                     'required' => false ) ),
00064                       'keys' => array( 'contentclass_id',
00065                                        'contentclass_version',
00066                                        'language_locale' ),
00067                       'function_attributes' => array(),
00068                       'class_name' => 'eZContentClassName',
00069                       'sort' => array( 'contentclass_id' => 'asc' ),
00070                       'name' => 'ezcontentclass_name' );
00071     }
00072 
00073     static function fetchList( $classID, $classVersion, $languageLocaleList, $asObjects = true, $fields = null, $sorts = null, $limit = null )
00074     {
00075         $conds = array();
00076 
00077         if ( is_array( $languageLocaleList ) && count( $languageLocaleList ) > 0 )
00078             $conds[ 'language_locale'] = array( $languageLocaleList );
00079 
00080         $conds[ 'contentclass_id'] = $classID;
00081         $conds[ 'contentclass_version'] = $classVersion;
00082 
00083         return eZPersistentObject::fetchObjectList( eZContentClassName::definition(),
00084                                                             $fields,
00085                                                             $conds,
00086                                                             $sorts,
00087                                                             $limit,
00088                                                             $asObjects );
00089     }
00090 
00091     /*!
00092      \return the SQL where-condition for selecting the rows (with class names) in the correct language,
00093      i. e. in the most prioritized language from those in which an object exists.
00094 
00095      \param languageTable Name of the table containing the attribute with bitmaps, e.g. ezcontentclass
00096      \param languageListTable Name of the table containing the attribute with language id.
00097     */
00098     static function sqlFilter( $languageTable = 'ezcontentclass' )
00099     {
00100         $def = eZContentClassName::definition();
00101         $languageListTable = $def['name'];
00102         $sqlFilter = array( 'nameField' => "$languageListTable.name",
00103                             'from' => "$languageListTable",
00104                             'where' => "$languageTable.id = $languageListTable.contentclass_id AND
00105                                         $languageTable.version = $languageListTable.contentclass_version AND " .
00106                                         eZContentLanguage::sqlFilter( $languageListTable, $languageTable ),
00107                             'orderBy' => "$languageListTable.name" );
00108 
00109         return $sqlFilter;
00110     }
00111 
00112     /*!
00113      The same as 'sqlFilter' but adds symbol ',' to 'nameField' and 'from' parts
00114     */
00115     static function sqlAppendFilter( $languageTable = 'ezcontentclass' )
00116     {
00117         $def = eZContentClassName::definition();
00118         $languageListTable = $def['name'];
00119         $sqlFilter = array( 'nameField' => ", $languageListTable.name",
00120                             'from' => ", $languageListTable",
00121                             'where' => "AND $languageTable.id = $languageListTable.contentclass_id AND
00122                                         $languageTable.version = $languageListTable.contentclass_version AND " .
00123                                         eZContentLanguage::sqlFilter( $languageListTable, $languageTable ),
00124                             'orderBy' => "$languageListTable.name" );
00125 
00126         return $sqlFilter;
00127     }
00128 
00129     /*!
00130      The same as 'sqlFilter' but all fields are empty
00131     */
00132     static function sqlEmptyFilter()
00133     {
00134         return array( 'nameField' => '',
00135                       'from' => '',
00136                       'where' => '',
00137                       'orderBy' => '' );
00138     }
00139 
00140     static function removeClassName( $contentClassID, $contentClassVersion )
00141     {
00142         $db = eZDb::instance();
00143         $db->begin();
00144 
00145         $sql = "DELETE FROM ezcontentclass_name WHERE contentclass_id = $contentClassID AND contentclass_version = $contentClassVersion";
00146         $db->query( $sql );
00147 
00148         $db->commit();
00149     }
00150 
00151 }
00152 
00153 ?>