|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZWaitUntilDate class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZWaitUntilDate ezwaituntildate.php 00013 \brief The class eZWaitUntilDate does 00014 00015 */ 00016 class eZWaitUntilDate 00017 { 00018 function eZWaitUntilDate( $eventID, $eventVersion ) 00019 { 00020 $this->WorkflowEventID = $eventID; 00021 $this->WorkflowEventVersion = $eventVersion; 00022 $this->Entries = eZWaitUntilDateValue::fetchAllElements( $eventID, $eventVersion ); 00023 } 00024 00025 function attributes() 00026 { 00027 return array( 'workflow_event_id', 00028 'workflow_event_version', 00029 'entry_list', 00030 'classattribute_id_list' ); 00031 } 00032 00033 function hasAttribute( $attr ) 00034 { 00035 return in_array( $attr, $this->attributes() ); 00036 } 00037 00038 function attribute( $attr ) 00039 { 00040 switch ( $attr ) 00041 { 00042 case "workflow_event_id" : 00043 { 00044 return $this->WorkflowEventID; 00045 }break; 00046 case "workflow_event_version" : 00047 { 00048 return $this->WorkflowEventVersion; 00049 }break; 00050 case "entry_list" : 00051 { 00052 return $this->Entries; 00053 }break; 00054 case 'classattribute_id_list' : 00055 { 00056 return $this->classAttributeIDList(); 00057 } 00058 default : 00059 { 00060 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ ); 00061 return null; 00062 }break; 00063 } 00064 } 00065 static function removeWaitUntilDateEntries( $workflowEventID, $workflowEventVersion ) 00066 { 00067 eZWaitUntilDateValue::removeAllElements( $workflowEventID, $workflowEventVersion ); 00068 } 00069 /*! 00070 Adds an enumeration 00071 */ 00072 function addEntry( $contentClassAttributeID, $contentClassID = false ) 00073 { 00074 if ( !isset( $contentClassAttributeID ) ) 00075 { 00076 return; 00077 } 00078 if ( !$contentClassID ) 00079 { 00080 $contentClassAttribute = eZContentClassAttribute::fetch( $contentClassAttributeID ); 00081 $contentClassID = $contentClassAttribute->attribute( 'contentclass_id' ); 00082 } 00083 // Checking if $contentClassAttributeID and $contentClassID already exist (in Entries) 00084 foreach ( $this->Entries as $entrie ) 00085 { 00086 if ( $entrie->attribute( 'contentclass_attribute_id' ) == $contentClassAttributeID and 00087 $entrie->attribute( 'contentclass_id' ) == $contentClassID ) 00088 return; 00089 } 00090 $waitUntilDateValue = eZWaitUntilDateValue::create( $this->WorkflowEventID, $this->WorkflowEventVersion, $contentClassAttributeID, $contentClassID ); 00091 $waitUntilDateValue->store(); 00092 $this->Entries = eZWaitUntilDateValue::fetchAllElements( $this->WorkflowEventID, $this->WorkflowEventVersion ); 00093 } 00094 00095 function removeEntry( $workflowEventID, $id, $version ) 00096 { 00097 eZWaitUntilDateValue::removeByID( $id, $version ); 00098 $this->Entries = eZWaitUntilDateValue::fetchAllElements( $workflowEventID, $version ); 00099 } 00100 00101 function classAttributeIDList() 00102 { 00103 $attributeIDList = array(); 00104 foreach ( $this->Entries as $entry ) 00105 { 00106 $attributeIDList[] = $entry->attribute( 'contentclass_attribute_id' ); 00107 } 00108 return $attributeIDList; 00109 } 00110 00111 function setVersion( $version ) 00112 { 00113 if ( $version == 1 && count( $this->Entries ) == 0 ) 00114 { 00115 $this->Entries = eZWaitUntilDateValue::fetchAllElements( $this->WorkflowEventID, 0 ); 00116 foreach( $this->Entries as $entry ) 00117 { 00118 $entry->setAttribute( "workflow_event_version", 1 ); 00119 $entry->store(); 00120 } 00121 } 00122 if ( $version == 0 ) 00123 { 00124 eZWaitUntilDateValue::removeAllElements( $this->WorkflowEventID, 0 ); 00125 foreach( $this->Entries as $entry ) 00126 { 00127 $oldversion = $entry->attribute( "workflow_event_version" ); 00128 $id = $entry->attribute( "id" ); 00129 $workflowEventID = $entry->attribute( "workflow_event_id" ); 00130 $contentClassID = $entry->attribute( "contentclass_id" ); 00131 $contentClassAttributeID = $entry->attribute( "contentclass_attribute_id" ); 00132 $entryCopy = eZWaitUntilDateValue::createCopy( $id, 00133 $workflowEventID, 00134 0, 00135 $contentClassID, 00136 $contentClassAttributeID ); 00137 00138 $entryCopy->store(); 00139 } 00140 } 00141 } 00142 00143 00144 public $WorkflowEventID; 00145 public $WorkflowEventVersion; 00146 public $Entries; 00147 00148 } 00149 00150 00151 ?>