Subversion Repositories addcollabrule

[/] [trunk/] [extension/] [addcollabrule/] [eventtypes/] [event/] [addcollabrule/] [addcollabruletype.php] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 cyberwolf
<?php
2
//
3
// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
4 2 Cyberwolf
// SOFTWARE NAME: eZ Publish addcollabrule extension
5
// SOFTWARE RELEASE: 2.x
6
// COPYRIGHT NOTICE: Copyright (C) 2007-2008 Kristof Coomans <http://blog.kristofcoomans.be>
7 1 cyberwolf
// SOFTWARE LICENSE: GNU General Public License v2.0
8
// NOTICE: >
9
//   This program is free software; you can redistribute it and/or
10
//   modify it under the terms of version 2.0  of the GNU General
11
//   Public License as published by the Free Software Foundation.
12
//
13
//   This program is distributed in the hope that it will be useful,
14
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
//   GNU General Public License for more details.
17
//
18
//   You should have received a copy of version 2.0 of the GNU General
19
//   Public License along with this program; if not, write to the Free
20
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
//   MA 02110-1301, USA.
22
//
23
//
24
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
25
//
26
 
27
class AddCollabRuleType extends eZWorkflowEventType
28
{
29 2 Cyberwolf
    function __construct()
30 1 cyberwolf
    {
31 5 nfrp
        $this->eZWorkflowEventType( 'addcollabrule', ezpI18n::tr( 'extension/projects', 'Add collaboration rule' ) );
32 1 cyberwolf
        // limit workflows which use this event to be used only on the post-publish trigger
33
        $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'after' ) ) ) );
34
    }
35
 
36
    function typeFunctionalAttributes()
37
    {
38
        return array( 'handler', 'selection' );
39
    }
40
 
41 2 Cyberwolf
    function attributeDecoder( $event, $attr )
42 1 cyberwolf
    {
43
        $retValue = null;
44
        switch( $attr )
45
        {
46
            case 'handler':
47
            {
48
                $retValue = new eZCollaborationNotificationHandler();
49
            } break;
50
 
51
            case 'selection':
52
            {
53
                $retValue = array();
54
                if ( trim( $event->attribute( 'data_text1' ) ) != '' )
55
                {
56
                    $retValue = explode( ',', $event->attribute( 'data_text1' ) );
57
                }
58
            } break;
59
 
60
            default:
61
            {
62
                eZDebug::writeNotice( 'unknown attribute:' . $attr, 'AddCollabRuleType' );
63
            }
64
        }
65
        return $retValue;
66
    }
67
 
68 2 Cyberwolf
    function fetchHTTPInput( $http, $base, $event )
69 1 cyberwolf
    {
70
        $selectionVar = 'CollaborationHandlerSelection_' . $event->attribute( 'id' );
71
        if ( $http->hasPostVariable( $selectionVar ) )
72
        {
73
            $selection = $http->postVariable( $selectionVar );
74
            $event->setAttribute( 'data_text1', implode( ',', $selection ) );
75
        }
76
    }
77
 
78 2 Cyberwolf
    function execute( $process, $event )
79 1 cyberwolf
    {
80
        $parameters = $process->attribute( 'parameter_list' );
81 2 Cyberwolf
        $object = eZContentObject::fetch( $parameters['object_id'] );
82 1 cyberwolf
 
83
        $collaborationIdentifierList = $event->attribute( 'selection' );
84
 
85
        foreach ( $collaborationIdentifierList as $collaborationIdentifier )
86
        {
87 2 Cyberwolf
            $existing = eZCollaborationNotificationRule::fetchItemTypeList( $collaborationIdentifier, array( $object->attribute( 'id' ) ) );
88 1 cyberwolf
 
89
            if ( count( $existing ) == 0 )
90
            {
91 2 Cyberwolf
                $rule = eZCollaborationNotificationRule::create( $collaborationIdentifier, $object->attribute( 'id' ) );
92 1 cyberwolf
                $rule->store( );
93
            }
94
        }
95
 
96 2 Cyberwolf
        return eZWorkflowType::STATUS_ACCEPTED;
97 1 cyberwolf
    }
98
}
99
 
100 2 Cyberwolf
eZWorkflowEventType::registerEventType( 'addcollabrule', 'AddCollabRuleType' );
101 1 cyberwolf
 
102 5 nfrp
?>