123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- /**
- * @file
- * Contains rules integration for the node module needed during evaluation.
- *
- * @addtogroup rules
- *
- * @{
- */
- /**
- * Base class providing node condition defaults.
- */
- abstract class RulesNodeConditionBase extends RulesConditionHandlerBase {
- public static function defaults() {
- return array(
- 'parameter' => array(
- 'node' => array('type' => 'node', 'label' => t('Content')),
- ),
- 'category' => 'node',
- 'access callback' => 'rules_node_integration_access',
- );
- }
- }
- /**
- * Condition: Check for selected content types.
- */
- class RulesNodeConditionType extends RulesNodeConditionBase {
- /**
- * Defines the condition.
- */
- public static function getInfo() {
- $info = self::defaults() + array(
- 'name' => 'node_is_of_type',
- 'label' => t('Content is of type'),
- 'help' => t('Evaluates to TRUE if the given content is of one of the selected content types.'),
- );
- $info['parameter']['type'] = array(
- 'type' => 'list<text>',
- 'label' => t('Content types'),
- 'options list' => 'node_type_get_names',
- 'description' => t('The content type(s) to check for.'),
- 'restriction' => 'input',
- );
- return $info;
- }
- /**
- * Executes the condition.
- */
- public function execute($node, $types) {
- return in_array($node->type, $types);
- }
- /**
- * Provides the content type of a node as asserted metadata.
- */
- public function assertions() {
- return array('node' => array('bundle' => $this->element->settings['type']));
- }
- }
- /**
- * Condition: Check if the node is published.
- */
- class RulesNodeConditionPublished extends RulesNodeConditionBase {
- /**
- * Defines the condition.
- */
- public static function getInfo() {
- return self::defaults() + array(
- 'name' => 'node_is_published',
- 'label' => t('Content is published'),
- );
- }
- /**
- * Executes the condition.
- */
- public function execute($node) {
- return $node->status == 1;
- }
- }
- /**
- * Condition: Check if the node is sticky.
- */
- class RulesNodeConditionSticky extends RulesNodeConditionBase {
- /**
- * Defines the condition.
- */
- public static function getInfo() {
- return self::defaults() + array(
- 'name' => 'node_is_sticky',
- 'label' => t('Content is sticky'),
- );
- }
- /**
- * Executes the condition.
- */
- public function execute($node) {
- return $node->sticky == 1;
- }
- }
- /**
- * Condition: Check if the node is promoted to the frontpage.
- */
- class RulesNodeConditionPromoted extends RulesNodeConditionBase {
- /**
- * Defines the condition.
- */
- public static function getInfo() {
- return self::defaults() + array(
- 'name' => 'node_is_promoted',
- 'label' => t('Content is promoted to frontpage'),
- );
- }
- /**
- * Executes the condition.
- */
- public function execute($node) {
- return $node->promote == 1;
- }
- }
- /**
- * @}
- */
|