|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZPolicyLimitationValue class 00004 // 00005 // Created on: <19-Aug-2002 11:28:06 sp> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezpolicylimitationvalue.php 00032 */ 00033 00034 /*! 00035 \class eZPolicyLimitationValue ezpolicylimitationvalue.php 00036 \ingroup eZRole 00037 \brief Defines a limitation value for a policy in the permission system 00038 00039 */ 00040 //include_once( "kernel/classes/ezpersistentobject.php" ); 00041 00042 class eZPolicyLimitationValue extends eZPersistentObject 00043 { 00044 /*! 00045 Constructor 00046 */ 00047 function eZPolicyLimitationValue( $row ) 00048 { 00049 $this->eZPersistentObject( $row ); 00050 } 00051 00052 00053 static function definition() 00054 { 00055 return array( "fields" => array( "id" => array( 'name' => 'ID', 00056 'datatype' => 'integer', 00057 'default' => 0, 00058 'required' => true ), 00059 'limitation_id' => array( 'name' => 'LimitationID', 00060 'datatype' => 'integer', 00061 'default' => 0, 00062 'required' => true, 00063 'foreign_class' => 'eZPolicyLimitation', 00064 'foreign_attribute' => 'id', 00065 'multiplicity' => '1..*' ), 00066 'value' => array( 'name' => 'Value', 00067 'datatype' => 'text', 00068 'default' => '', 00069 'required' => true ) ), 00070 "keys" => array( "id" ), 00071 "increment_key" => "id", 00072 "sort" => array( "value" => "asc" ), 00073 "class_name" => "eZPolicyLimitationValue", 00074 "name" => "ezpolicy_limitation_value" ); 00075 } 00076 00077 00078 /*! 00079 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00080 the calls within a db transaction; thus within db->begin and db->commit. 00081 */ 00082 static function createNew( $limitationID, $value ) 00083 { 00084 $limitationValue = new eZPolicyLimitationValue( array() ); 00085 $limitationValue->setAttribute( 'limitation_id', $limitationID ); 00086 $limitationValue->setAttribute( 'value', $value ); 00087 $limitationValue->store(); 00088 00089 return $limitationValue; 00090 } 00091 00092 /*! 00093 \static 00094 Creates a new limitation value for the limitation \a $limitationID and returns it. 00095 \note The value is not stored. 00096 */ 00097 static function create( $limitationID, $value ) 00098 { 00099 $row = array( 'id' => null, 00100 'limitation_id' => $limitationID, 00101 'value' => $value ); 00102 return new eZPolicyLimitationValue( $row ); 00103 } 00104 00105 /*! 00106 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00107 the calls within a db transaction; thus within db->begin and db->commit. 00108 */ 00109 function copy( $limitationID ) 00110 { 00111 $newValue = eZPolicyLimitationValue::createNew( $limitationID, $this->attribute( 'value' ) ); 00112 } 00113 00114 static function fetchList( $limitationID, $asObject = true ) 00115 { 00116 return eZPersistentObject::fetchObjectList( eZPolicyLimitationValue::definition(), 00117 null, 00118 array( 'limitation_id' => $limitationID ), 00119 null, 00120 null, 00121 $asObject ); 00122 } 00123 00124 /*! 00125 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00126 the calls within a db transaction; thus within db->begin and db->commit. 00127 */ 00128 static function removeByValue( $value, $policyID = false ) 00129 { 00130 if ( $policyID ) 00131 { 00132 $limitationIDList = array(); 00133 $limitations = eZPolicyLimitation::fetchByPolicyID( $policyID, false ); 00134 foreach ( $limitations as $limitationArray ) 00135 { 00136 $limitationIDList[] = $limitationArray['id']; 00137 } 00138 if ( count( $limitationIDList ) > 0 ) 00139 { 00140 eZPersistentObject::removeObject( eZPolicyLimitationValue::definition(), 00141 array( 'limitation_id' => array( $limitationIDList ), 00142 "value" => $value ) ); 00143 return; 00144 } 00145 } 00146 eZPersistentObject::removeObject( eZPolicyLimitationValue::definition(), 00147 array( "value" => $value ) ); 00148 } 00149 00150 } 00151 00152 ?>