/[drupal]/contributions/modules/bitcache/bitcache.rules.inc
ViewVC logotype

Contents of /contributions/modules/bitcache/bitcache.rules.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Jul 1 08:55:37 2009 UTC (4 months, 4 weeks ago) by arto
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Implemented initial Rules module integration.
1 <?php
2 // $Id$
3
4 //////////////////////////////////////////////////////////////////////////////
5 // Rules API hooks (data types)
6
7 function bitcache_rules_data_type_info() {
8 return array(
9 'bitcache_stream' => array(
10 'module' => 'Bitcache',
11 'label' => t('Bitcache stream'),
12 'class' => 'bitcache_rules_data_type_stream',
13 'identifiable' => TRUE,
14 'savable' => FALSE,
15 'uses_input_form' => FALSE,
16 ),
17 );
18 }
19
20 class bitcache_rules_data_type_stream extends rules_data_type {
21 function load($id) {
22 return bitcache_get($id);
23 }
24
25 function get_identifier() {
26 $stream = &$this->get();
27 return $stream->id();
28 }
29 }
30
31 //////////////////////////////////////////////////////////////////////////////
32 // Rules API hooks (events)
33
34 /**
35 * Implementation of hook_rules_event_info().
36 */
37 function bitcache_rules_event_info() {
38 return array(
39 'bitcache_insert' => array(
40 'module' => 'Bitcache',
41 'label' => t('Bitstream created'),
42 'help' => t('This event is triggered after a new bitstream has been uploaded.'),
43 'arguments' => array(
44 'stream' => array('label' => t('Bitstream'), 'type' => 'bitcache_stream'),
45 ),
46 ),
47 'bitcache_delete' => array(
48 'module' => 'Bitcache',
49 'label' => t('Bitstream deleted'),
50 'help' => t('This event is triggered after a bitstream has been deleted.'),
51 'arguments' => array(
52 'stream' => array('label' => t('Bitstream'), 'type' => 'bitcache_stream'),
53 ),
54 ),
55 );
56 }
57
58 //////////////////////////////////////////////////////////////////////////////
59 // Rules API hooks (conditions)
60
61 /**
62 * Implementation of hook_rules_condition_info().
63 */
64 function bitcache_rules_condition_info() {
65 return array(
66 // TODO: Bitstream exists in repository
67 // TODO: Bitstream size is zero
68 // TODO: Bitstream size is...
69 // TODO: Bitstream MIME type is...
70 );
71 }
72
73 //////////////////////////////////////////////////////////////////////////////
74 // Rules API hooks (actions)
75
76 /**
77 * Implementation of hook_rules_action_info().
78 */
79 function bitcache_rules_action_info() {
80 return array(
81 'bitcache_rules_action_delete' => array(
82 'module' => 'Bitcache',
83 'label' => t('Delete bitstream'),
84 'help' => t(''),
85 'arguments' => array(
86 'stream' => array('label' => t('Bitstream to delete'), 'type' => 'bitcache_stream'),
87 ),
88 ),
89 'bitcache_rules_action_delete_from' => array(
90 'module' => 'Bitcache',
91 'label' => t('Delete bitstream from repository'),
92 'help' => t(''),
93 'arguments' => array(
94 'stream' => array('label' => t('Bitstream to delete'), 'type' => 'bitcache_stream'),
95 'repository' => array('label' => t('Repository name'), 'type' => 'string'),
96 ),
97 ),
98 'bitcache_rules_action_push_to' => array(
99 'module' => 'Bitcache',
100 'label' => t('Push bitstream to repository'),
101 'help' => t(''),
102 'arguments' => array(
103 'stream' => array('label' => t('Bitstream to copy'), 'type' => 'bitcache_stream'),
104 'repository' => array('label' => t('Repository name'), 'type' => 'string'),
105 ),
106 ),
107 // TODO: Delete all bitstreams in repository
108 // TODO: Synchronize two repositories
109 );
110 }
111
112 /**
113 * Action: Delete bitstream.
114 */
115 function bitcache_rules_action_delete($stream) {
116 bitcache_delete($stream->id());
117 }
118
119 /**
120 * Action: Delete bitstream from repository.
121 */
122 function bitcache_rules_action_delete_from($stream, $repository) {
123 if (($repo = bitcache_get_repository($repository))) {
124 $repo->delete($stream->id());
125 }
126 }
127
128 /**
129 * Action: Push bitstream to repository.
130 */
131 function bitcache_rules_action_push_to($stream, $repository) {
132 if (($repo = bitcache_get_repository($repository))) {
133 $repo->put($stream->id(), $stream->data());
134 }
135 }

  ViewVC Help
Powered by ViewVC 1.1.2