eZ Publish  [trunk]
ezpendingactions.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZPendingActions 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 class eZPendingActions extends eZPersistentObject
00012 {
00013     /**
00014      * Schema definition
00015      * eZPersistentObject implementation for ezpending_actions table
00016      * @see kernel/classes/ezpersistentobject.php
00017      * @return array
00018      */
00019     public static function definition()
00020     {
00021         return array(
00022             'fields' => array(
00023                 'id' => array(
00024                     'name' => 'id',
00025                     'datatype' => 'integer',
00026                     'default' => 0,
00027                     'required' => true
00028                 ),
00029                 'action' => array(
00030                     'name' => 'action',
00031                     'datatype' => 'string',
00032                     'default' => null,
00033                     'required' => true
00034                 ),
00035                 'created' => array(
00036                     'name' => 'created',
00037                     'datatype' => 'integer',
00038                     'default' => null,
00039                     'required' => false
00040                 ),
00041                 'param' => array(
00042                     'name' => 'param',
00043                     'datatype' => 'string',
00044                     'default' => null,
00045                     'required' => false
00046                 )
00047             ),
00048             'keys' => array( 'id' ),
00049             'class_name' => 'eZPendingActions',
00050             'name' => 'ezpending_actions',
00051             'function_attributes' => array()
00052         );
00053     }
00054 
00055     /**
00056      * Fetches a pending actions list by action name
00057      * @param string $action
00058      * @param array $aCreationDateFilter Created date filter array (default is empty array). Must be a 2 entries array.
00059      *                                   First entry is the filter token (can be '=', '<', '<=', '>', '>=')
00060      *                                   Second entry is the filter value (timestamp)
00061      * @return array|null Array of eZPendingActions or null if no entry has been found
00062      */
00063     public static function fetchByAction( $action, array $aCreationDateFilter = array() )
00064     {
00065         $filterConds = array( 'action' => $action );
00066 
00067         // Handle creation date filter
00068         if( !empty( $aCreationDateFilter ) )
00069         {
00070             if( count( $aCreationDateFilter ) != 2 )
00071             {
00072                 eZDebug::writeError( __CLASS__.'::'.__METHOD__.' : Wrong number of entries for Creation date filter array' );
00073                 return null;
00074             }
00075 
00076             list( $filterToken, $filterValue ) = $aCreationDateFilter;
00077             $aAuthorizedFilterTokens = array( '=', '<', '>', '<=', '>=' );
00078             if( !is_string( $filterToken ) || !in_array( $filterToken, $aAuthorizedFilterTokens ) )
00079             {
00080                 eZDebug::writeError( __CLASS__.'::'.__METHOD__.' : Wrong filter type for creation date filter' );
00081                 return null;
00082             }
00083 
00084             $filterConds['created'] = array( $filterToken, $filterValue );
00085         }
00086 
00087         $result = parent::fetchObjectList( self::definition(), null, $filterConds );
00088 
00089         return $result;
00090     }
00091 
00092     /**
00093      * Remove entries by action
00094      * @param string $action
00095      * @param array $filterConds Additional filter conditions, as supported by {@link eZPersistentObject::fetchObjectList()} ($conds param).
00096      *                           For consistency sake, if an 'action' key is set here, it won't be taken into account
00097      */
00098     public static function removeByAction( $action, array $filterConds = array() )
00099     {
00100         parent::removeObject( self::definition(), array( 'action' => $action ) + $filterConds );
00101     }
00102 }
00103 
00104 ?>