00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 include_once( 'kernel/classes/notification/eznotificationcollectionitem.php' );
00040
00041 class eZNotificationCollection extends eZPersistentObject
00042 {
00043
00044
00045
00046 function eZNotificationCollection( $row = array() )
00047 {
00048 $this->eZPersistentObject( $row );
00049 }
00050
00051 function definition()
00052 {
00053 return array( "fields" => array( "id" => array( 'name' => 'ID',
00054 'datatype' => 'integer',
00055 'default' => 0,
00056 'required' => true ),
00057 "event_id" => array( 'name' => "EventID",
00058 'datatype' => 'integer',
00059 'default' => 0,
00060 'required' => true,
00061 'foreign_class' => 'eZNotificationEvent',
00062 'foreign_attribute' => 'id',
00063 'multiplicity' => '1..*' ),
00064 "handler" => array( 'name' => "Handler",
00065 'datatype' => 'string',
00066 'default' => '',
00067 'required' => true ),
00068 "transport" => array( 'name' => "Transport",
00069 'datatype' => 'string',
00070 'default' => '',
00071 'required' => true ),
00072 "data_subject" => array( 'name' => "DataText1",
00073 'datatype' => 'text',
00074 'default' => '',
00075 'required' => true ),
00076 "data_text" => array( 'name' => "DataText2",
00077 'datatype' => 'text',
00078 'default' => '',
00079 'required' => true ) ),
00080 "keys" => array( "id" ),
00081 "function_attributes" => array( 'items' => 'items',
00082 'items_to_send' => 'itemsToSend',
00083 'item_count' => 'itemCount' ),
00084 "increment_key" => "id",
00085 "sort" => array( "id" => "asc" ),
00086 "class_name" => "eZNotificationCollection",
00087 "name" => "eznotificationcollection" );
00088 }
00089
00090
00091 function create( $eventID, $handler, $transport )
00092 {
00093 return new eZNotificationCollection( array( 'event_id' => $eventID,
00094 'handler' => $handler,
00095 'transport' => $transport ) );
00096 }
00097
00098 function addItem( $address, $sendDate = 0 )
00099 {
00100 $item = eZNotificationCollectionItem::create( $this->attribute( 'id' ), $this->attribute( 'event_id' ), $address, $sendDate = 0 );
00101 $item->store();
00102 return $item;
00103 }
00104
00105 function &items()
00106 {
00107 $items = eZPersistentObject::fetchObjectList( eZNotificationCollectionItem::definition(),
00108 null, array( 'collection_id' => $this->attribute( 'id' ) ), null,null,
00109 true );
00110 return $items;
00111 }
00112
00113 function &itemCount()
00114 {
00115 $result = eZPersistentObject::fetchObjectList( eZNotificationCollectionItem::definition(),
00116 array(),
00117 array( 'collection_id' => $this->attribute( 'id' ) ),
00118 false,
00119 null,
00120 false,
00121 false,
00122 array( array( 'operation' => 'count( * )',
00123 'name' => 'count' ) ) );
00124 return $result[0]['count'];
00125 }
00126
00127 function &itemsToSend()
00128 {
00129 $items = eZPersistentObject::fetchObjectList( eZNotificationCollectionItem::definition(),
00130 null, array( 'collection_id' => $this->attribute( 'id' ),
00131 'send_date' => 0 ),
00132 null, null, true );
00133 return $items;
00134 }
00135
00136 function fetchForHandler( $handler, $eventID, $transport )
00137 {
00138 return eZPersistentObject::fetchObject( eZNotificationCollection::definition(), null,
00139 array( 'event_id' => $eventID,
00140 'handler'=> $handler,
00141 'transport' => $transport ) );
00142 }
00143
00144 function fetchListForHandler( $handler, $eventID, $transport )
00145 {
00146 return eZPersistentObject::fetchObjectList( eZNotificationCollection::definition(), null,
00147 array( 'event_id' => $eventID,
00148 'handler'=> $handler,
00149 'transport' => $transport ) );
00150 }
00151
00152
00153
00154
00155
00156 function removeEmpty()
00157 {
00158 $db =& eZDB::instance();
00159 if ( $db->databaseName() == 'oracle' )
00160 $query = 'SELECT eznotificationcollection.id FROM eznotificationcollection, eznotificationcollection_item
00161 WHERE eznotificationcollection.id = eznotificationcollection_item.collection_id(+) AND
00162 eznotificationcollection_item.collection_id IS NULL';
00163 else
00164 $query = 'SELECT eznotificationcollection.id FROM eznotificationcollection
00165 LEFT JOIN eznotificationcollection_item ON eznotificationcollection.id=eznotificationcollection_item.collection_id
00166 WHERE eznotificationcollection_item.collection_id IS NULL';
00167
00168 $idArray = $db->arrayQuery( $query );
00169
00170 $db->begin();
00171 foreach ( $idArray as $id )
00172 {
00173 eZPersistentObject::removeObject( eZNotificationCollection::definition(), array( 'id' => $id['id'] ) );
00174 }
00175 $db->commit();
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 function cleanup()
00185 {
00186 $db =& eZDB::instance();
00187 $db->begin();
00188 eZNotificationCollectionItem::cleanup();
00189 $db->query( "DELETE FROM eznotificationcollection" );
00190 $db->commit();
00191 }
00192 }
00193
00194 ?>