Projet

Général

Profil

Paste
Télécharger (2,85 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / modules / node.eval.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains rules integration for the node module needed during evaluation.
6
 *
7
 * @addtogroup rules
8
 *
9
 * @{
10
 */
11

    
12
/**
13
 * Base class providing node condition defaults.
14
 */
15
abstract class RulesNodeConditionBase extends RulesConditionHandlerBase {
16

    
17
  public static function defaults() {
18
    return array(
19
      'parameter' => array(
20
        'node' => array('type' => 'node', 'label' => t('Content')),
21
      ),
22
      'category' => 'node',
23
      'access callback' => 'rules_node_integration_access',
24
    );
25
  }
26

    
27
}
28

    
29
/**
30
 * Condition: Check for selected content types.
31
 */
32
class RulesNodeConditionType extends RulesNodeConditionBase {
33

    
34
  /**
35
   * Defines the condition.
36
   */
37
  public static function getInfo() {
38
    $info = self::defaults() + array(
39
      'name' => 'node_is_of_type',
40
      'label' => t('Content is of type'),
41
      'help' => t('Evaluates to TRUE if the given content is of one of the selected content types.'),
42
    );
43
    $info['parameter']['type'] = array(
44
      'type' => 'list<text>',
45
      'label' => t('Content types'),
46
      'options list' => 'node_type_get_names',
47
      'description' => t('The content type(s) to check for.'),
48
      'restriction' => 'input',
49
    );
50
    return $info;
51
  }
52

    
53
  /**
54
   * Executes the condition.
55
   */
56
  public function execute($node, $types) {
57
    return in_array($node->type, $types);
58
  }
59

    
60
  /**
61
   * Provides the content type of a node as asserted metadata.
62
   */
63
  public function assertions() {
64
    return array('node' => array('bundle' => $this->element->settings['type']));
65
  }
66

    
67
}
68

    
69
/**
70
 * Condition: Check if the node is published.
71
 */
72
class RulesNodeConditionPublished extends RulesNodeConditionBase {
73

    
74
  /**
75
   * Defines the condition.
76
   */
77
  public static function getInfo() {
78
    return self::defaults() + array(
79
      'name' => 'node_is_published',
80
      'label' => t('Content is published'),
81
    );
82
  }
83

    
84
  /**
85
   * Executes the condition.
86
   */
87
  public function execute($node) {
88
    return $node->status == 1;
89
  }
90

    
91
}
92

    
93
/**
94
 * Condition: Check if the node is sticky.
95
 */
96
class RulesNodeConditionSticky extends RulesNodeConditionBase {
97

    
98
  /**
99
   * Defines the condition.
100
   */
101
  public static function getInfo() {
102
    return self::defaults() + array(
103
      'name' => 'node_is_sticky',
104
      'label' => t('Content is sticky'),
105
    );
106
  }
107

    
108
  /**
109
   * Executes the condition.
110
   */
111
  public function execute($node) {
112
    return $node->sticky == 1;
113
  }
114

    
115
}
116

    
117
/**
118
 * Condition: Check if the node is promoted to the frontpage.
119
 */
120
class RulesNodeConditionPromoted extends RulesNodeConditionBase {
121

    
122
  /**
123
   * Defines the condition.
124
   */
125
  public static function getInfo() {
126
    return self::defaults() + array(
127
      'name' => 'node_is_promoted',
128
      'label' => t('Content is promoted to frontpage'),
129
    );
130
  }
131

    
132
  /**
133
   * Executes the condition.
134
   */
135
  public function execute($node) {
136
    return $node->promote == 1;
137
  }
138

    
139
}
140

    
141
/**
142
 * @}
143
 */