View source
<?php
function course_rules_condition_info() {
return array(
'course_enrollment_check' => array(
'label' => t('User is enrolled'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Node'),
),
'user' => array(
'type' => 'user',
'label' => t('User'),
),
),
'group' => t('Course'),
'base' => 'course_rules_condition_course_enrollment_check',
),
);
}
function course_rules_condition_course_enrollment_check($node, $user) {
$nid = $node->nid;
$uid = $user->uid;
return course_enrollment_check($nid, $uid);
}
function course_rules_action_info() {
$defaults = array(
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Node'),
),
'user' => array(
'type' => 'user',
'label' => t('User'),
),
),
'group' => t('Course'),
);
$actions['course_enroll'] = $defaults + array(
'label' => t('Enroll a user in a course'),
'base' => 'course_rules_action_course_enroll',
);
$actions['course_unenroll'] = $defaults + array(
'label' => t('Unenroll a user from a course'),
'base' => 'course_rules_action_course_unenroll',
);
return $actions;
}
function course_rules_action_course_enroll($node, $account, array $args, RulesState $state, RulesAction $action, $method) {
course_enroll($node, $account, 'rules');
}
function course_rules_action_course_unenroll($node, $account) {
course_unenroll($node, $account);
}