eZ Publish  [4.0]
ezworkflowevent.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZWorkflowEvent class
00004 //
00005 // Created on: <16-Apr-2002 11:08:14 amos>
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 //!! eZKernel
00032 //! The class eZWorkflowEvent does
00033 /*!
00034 
00035 */
00036 
00037 //include_once( "lib/ezdb/classes/ezdb.php" );
00038 //include_once( "kernel/classes/ezpersistentobject.php" );
00039 //include_once( "kernel/classes/ezworkflowtype.php" );
00040 
00041 class eZWorkflowEvent extends eZPersistentObject
00042 {
00043     function eZWorkflowEvent( $row )
00044     {
00045         $this->eZPersistentObject( $row );
00046         $this->Content = null;
00047     }
00048 
00049     static function definition()
00050     {
00051         return array( "fields" => array( "id" => array( 'name' => 'ID',
00052                                                         'datatype' => 'integer',
00053                                                         'default' => 0,
00054                                                         'required' => true ),
00055                                          "version" => array( 'name' => "Version",
00056                                                              'datatype' => 'integer',
00057                                                              'default' => 0,
00058                                                              'required' => true ),
00059                                          "workflow_id" => array( 'name' => "WorkflowID",
00060                                                                  'datatype' => 'integer',
00061                                                                  'default' => 0,
00062                                                                  'required' => true,
00063                                                                  'foreign_class' => 'eZWorkflow',
00064                                                                  'foreign_attribute' => 'id',
00065                                                                  'multiplicity' => '1..*' ),
00066                                          "workflow_type_string" => array( 'name' => "TypeString",
00067                                                                           'datatype' => 'string',
00068                                                                           'default' => '',
00069                                                                           'required' => true,
00070                                                                           'max_length' => 50 ),
00071                                          "description" => array( 'name' => "Description",
00072                                                                  'datatype' => 'string',
00073                                                                  'default' => '',
00074                                                                  'required' => true,
00075                                                                  'max_length' => 50 ),
00076                                          "data_int1" => array( 'name' => "DataInt1",
00077                                                                'datatype' => 'integer',
00078                                                                'default' => 0,
00079                                                                'required' => true ),
00080                                          "data_int2" => array( 'name' => "DataInt2",
00081                                                                'datatype' => 'integer',
00082                                                                'default' => 0,
00083                                                                'required' => true ),
00084                                          "data_int3" => array( 'name' => "DataInt3",
00085                                                                'datatype' => 'integer',
00086                                                                'default' => 0,
00087                                                                'required' => true ),
00088                                          "data_int4" => array( 'name' => "DataInt4",
00089                                                                'datatype' => 'integer',
00090                                                                'default' => 0,
00091                                                                'required' => true ),
00092                                          "data_text1" => array( 'name' => "DataText1",
00093                                                                 'datatype' => 'text',
00094                                                                 'default' => '',
00095                                                                 'required' => true,
00096                                                                 'max_length' => 50 ),
00097                                          "data_text2" => array( 'name' => "DataText2",
00098                                                                 'datatype' => 'text',
00099                                                                 'default' => '',
00100                                                                 'required' => true,
00101                                                                 'max_length' => 50 ),
00102                                          "data_text3" => array( 'name' => "DataText3",
00103                                                                 'datatype' => 'text',
00104                                                                 'default' => '',
00105                                                                 'required' => true,
00106                                                                 'max_length' => 50 ),
00107                                          "data_text4" => array( 'name' => "DataText4",
00108                                                                 'datatype' => 'text',
00109                                                                 'default' => '',
00110                                                                 'required' => true,
00111                                                                 'max_length' => 50 ),
00112                                          "placement" => array( 'name' => "Placement",
00113                                                                'datatype' => 'integer',
00114                                                                'default' => 0,
00115                                                                'required' => true ) ),
00116                       "keys" => array( "id", "version" ),
00117                       "function_attributes" => array( 'content' => 'content',
00118                                                       'workflow_type' => 'eventType' ),
00119                       "increment_key" => "id",
00120                       "sort" => array( "placement" => "asc" ),
00121                       "class_name" => "eZWorkflowEvent",
00122                       "name" => "ezworkflow_event" );
00123     }
00124 
00125     static function create( $workflow_id, $type_string )
00126     {
00127         $row = array(
00128             "id" => null,
00129             "version" => 1,
00130             "workflow_id" => $workflow_id,
00131             "workflow_type_string" => $type_string,
00132             "description" => "",
00133             "placement" => eZPersistentObject::newObjectOrder( eZWorkflowEvent::definition(),
00134                                                                "placement",
00135                                                                array( "version" => 1,
00136                                                                       "workflow_id" => $workflow_id ) ) );
00137         return new eZWorkflowEvent( $row );
00138     }
00139 
00140     static function fetch( $id, $asObject = true, $version = 0, $field_filters = null )
00141     {
00142         return eZPersistentObject::fetchObject( eZWorkflowEvent::definition(),
00143                                                 $field_filters,
00144                                                 array( "id" => $id,
00145                                                        "version" => $version ),
00146                                                 $asObject );
00147     }
00148 
00149     static function fetchList( $asObject = true )
00150     {
00151         return eZPersistentObject::fetchObjectList( eZWorkflowEvent::definition(),
00152                                                     null, null, null, null,
00153                                                     $asObject );
00154     }
00155 
00156     static function fetchFilteredList( $cond, $asObject = true )
00157     {
00158         return eZPersistentObject::fetchObjectList( eZWorkflowEvent::definition(),
00159                                                     null, $cond, null, null,
00160                                                     $asObject );
00161     }
00162 
00163     /*!
00164      Moves the object down if $down is true, otherwise up.
00165      If object is at either top or bottom it is wrapped around.
00166     */
00167     function move( $down, $params = null )
00168     {
00169         if ( is_array( $params ) )
00170         {
00171             $pos = $params["placement"];
00172             $wid = $params["workflow_id"];
00173             $version = $params["version"];
00174         }
00175         else
00176         {
00177             $pos = $this->Placement;
00178             $wid = $this->WorkflowID;
00179             $version = $this->Version;
00180         }
00181         eZPersistentObject::reorderObject( eZWorkflowEvent::definition(),
00182                                            array( "placement" => $pos ),
00183                                            array( "workflow_id" => $wid,
00184                                                   "version" => $version ),
00185                                            $down );
00186     }
00187 
00188     function attributes()
00189     {
00190         return array_merge( eZPersistentObject::attributes(), $this->eventType()->typeFunctionalAttributes() );
00191     }
00192 
00193     function hasAttribute( $attr )
00194     {
00195         $eventType = $this->eventType();
00196         return eZPersistentObject::hasAttribute( $attr ) or
00197                in_array( $attr, $eventType->typeFunctionalAttributes() );
00198     }
00199 
00200     function attribute( $attr, $noFunction = false )
00201     {
00202         $eventType = $this->eventType();
00203         if ( is_object( $eventType ) and in_array( $attr, $eventType->typeFunctionalAttributes( ) ) )
00204         {
00205             return $eventType->attributeDecoder( $this, $attr );
00206         }
00207 
00208         return eZPersistentObject::attribute( $attr );
00209     }
00210 
00211     function eventType()
00212     {
00213         if ( ! isset( $this->EventType ) )
00214         {
00215             $this->EventType = eZWorkflowType::createType( $this->TypeString );
00216         }
00217         return $this->EventType;
00218     }
00219 
00220     /*!
00221      Returns the content for this event.
00222     */
00223     function content()
00224     {
00225         if ( $this->Content === null )
00226         {
00227             $eventType = $this->eventType();
00228             $this->Content = $eventType->workflowEventContent( $this );
00229         }
00230 
00231         return $this->Content;
00232     }
00233 
00234     /*!
00235      Sets the content for the current event
00236     */
00237     function setContent( $content )
00238     {
00239         $this->Content = $content;
00240     }
00241 
00242 
00243     /*!
00244      Executes the custom HTTP action
00245     */
00246     function customHTTPAction( $http, $action )
00247     {
00248         $eventType = $this->eventType();
00249         $eventType->customWorkflowEventHTTPAction( $http, $action, $this );
00250     }
00251 
00252     /*!
00253      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00254      the calls within a db transaction; thus within db->begin and db->commit.
00255      */
00256     function store( $fieldFilters = null )
00257     {
00258         $db = eZDB::instance();
00259         $db->begin();
00260         $stored = eZPersistentObject::store( $fieldFilters );
00261 
00262         $eventType = $this->eventType();
00263         $eventType->storeEventData( $this, $this->attribute( 'version' ) );
00264         $db->commit();
00265 
00266         return $stored;
00267     }
00268 
00269     /*!
00270      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00271      the calls within a db transaction; thus within db->begin and db->commit.
00272      */
00273     function storeDefined( $fieldFilters = null )
00274     {
00275         $db = eZDB::instance();
00276         $db->begin();
00277         $stored = eZPersistentObject::store( $fieldFilters );
00278 
00279         $eventType = $this->eventType();
00280         $eventType->storeDefinedEventData( $this );
00281         $db->commit();
00282 
00283         return $stored;
00284     }
00285 
00286     /// \privatesection
00287     public $ID;
00288     public $Version;
00289     public $WorkflowID;
00290     public $TypeString;
00291     public $Description;
00292     public $Placement;
00293     public $DataInt1;
00294     public $DataInt2;
00295     public $DataInt3;
00296     public $DataInt4;
00297     public $DataText1;
00298     public $DataText2;
00299     public $DataText3;
00300     public $DataText4;
00301     public $Content;
00302 }
00303 
00304 ?>