eZ Publish  [4.0]
ezwaituntildate.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZWaitUntilDate class
00004 //
00005 // Created on: <09-Jan-2003 16:20:05 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 ezwaituntildate.php
00032 */
00033 
00034 /*!
00035   \class eZWaitUntilDate ezwaituntildate.php
00036   \brief The class eZWaitUntilDate does
00037 
00038 */
00039 //include_once( 'kernel/classes/workflowtypes/event/ezwaituntildate/ezwaituntildatevalue.php' );
00040 
00041 class eZWaitUntilDate
00042 {
00043     function eZWaitUntilDate( $eventID, $eventVersion )
00044     {
00045         $this->WorkflowEventID = $eventID;
00046         $this->WorkflowEventVersion = $eventVersion;
00047         $this->Entries = eZWaitUntilDateValue::fetchAllElements( $eventID, $eventVersion );
00048     }
00049 
00050     function attributes()
00051     {
00052         return array( 'workflow_event_id',
00053                       'workflow_event_version',
00054                       'entry_list',
00055                       'classattribute_id_list' );
00056     }
00057 
00058     function hasAttribute( $attr )
00059     {
00060         return in_array( $attr, $this->attributes() );
00061     }
00062 
00063     function attribute( $attr )
00064     {
00065         switch ( $attr )
00066         {
00067             case "workflow_event_id" :
00068             {
00069                 return $this->WorkflowEventID;
00070             }break;
00071             case "workflow_event_version" :
00072             {
00073                 return $this->WorkflowEventVersion;
00074             }break;
00075             case "entry_list" :
00076             {
00077                 return $this->Entries;
00078             }break;
00079             case 'classattribute_id_list' :
00080             {
00081                 return $this->classAttributeIDList();
00082             }
00083             default :
00084             {
00085                 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZWaitUntilDate::attribute' );
00086                 return null;
00087             }break;
00088         }
00089     }
00090     static function removeWaitUntilDateEntries( $workflowEventID, $workflowEventVersion )
00091     {
00092          eZWaitUntilDateValue::removeAllElements( $workflowEventID, $workflowEventVersion );
00093     }
00094     /*!
00095      Adds an enumeration
00096     */
00097     function addEntry( $contentClassAttributeID, $contentClassID = false )
00098     {
00099         if ( !isset( $contentClassAttributeID ) )
00100         {
00101             return;
00102         }
00103         if ( !$contentClassID )
00104         {
00105             $contentClassAttribute = eZContentClassAttribute::fetch( $contentClassAttributeID );
00106             $contentClassID = $contentClassAttribute->attribute( 'contentclass_id' );
00107         }
00108         // Checking if $contentClassAttributeID and $contentClassID already exist (in Entries)
00109         foreach ( $this->Entries as $entrie )
00110         {
00111             if ( $entrie->attribute( 'contentclass_attribute_id' ) == $contentClassAttributeID and
00112                  $entrie->attribute( 'contentclass_id' ) == $contentClassID )
00113                 return;
00114         }
00115         $waitUntilDateValue = eZWaitUntilDateValue::create( $this->WorkflowEventID, $this->WorkflowEventVersion, $contentClassAttributeID, $contentClassID );
00116         $waitUntilDateValue->store();
00117         $this->Entries = eZWaitUntilDateValue::fetchAllElements( $this->WorkflowEventID, $this->WorkflowEventVersion );
00118     }
00119 
00120     function removeEntry( $workflowEventID, $id, $version )
00121     {
00122        eZWaitUntilDateValue::removeByID( $id, $version );
00123        $this->Entries = eZWaitUntilDateValue::fetchAllElements( $workflowEventID, $version );
00124     }
00125 
00126     function classAttributeIDList()
00127     {
00128         $attributeIDList = array();
00129         foreach ( $this->Entries as $entry )
00130         {
00131             $attributeIDList[] = $entry->attribute( 'contentclass_attribute_id' );
00132         }
00133         return $attributeIDList;
00134     }
00135 
00136     function setVersion( $version )
00137     {
00138         if ( $version == 1 && count( $this->Entries ) == 0 )
00139         {
00140             $this->Entries = eZWaitUntilDateValue::fetchAllElements( $this->WorkflowEventID, 0 );
00141             foreach( $this->Entries as $entry )
00142             {
00143                 $entry->setAttribute( "workflow_event_version", 1 );
00144                 $entry->store();
00145             }
00146         }
00147         if ( $version == 0 )
00148         {
00149             eZWaitUntilDateValue::removeAllElements( $this->WorkflowEventID, 0 );
00150             foreach( $this->Entries as $entry )
00151             {
00152                 $oldversion = $entry->attribute( "workflow_event_version" );
00153                 $id = $entry->attribute( "id" );
00154                 $workflowEventID = $entry->attribute( "workflow_event_id" );
00155                 $contentClassID = $entry->attribute( "contentclass_id" );
00156                 $contentClassAttributeID = $entry->attribute( "contentclass_attribute_id" );
00157                 $entryCopy = eZWaitUntilDateValue::createCopy( $id,
00158                                                                $workflowEventID,
00159                                                                0,
00160                                                                $contentClassID,
00161                                                                $contentClassAttributeID );
00162 
00163                 $entryCopy->store();
00164             }
00165         }
00166     }
00167 
00168 
00169     public $WorkflowEventID;
00170     public $WorkflowEventVersion;
00171     public $Entries;
00172 
00173 }
00174 
00175 
00176 ?>