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