You are here

function course_uc_node_insert in Course 8.2

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.module \course_uc_node_insert()
  2. 7.2 modules/course_uc/course_uc.module \course_uc_node_insert()
  3. 7 modules/course_uc/course_uc.module \course_uc_node_insert()
  4. 3.x modules/course_uc/course_uc.module \course_uc_node_insert()

Implements hook_node_insert().

1 call to course_uc_node_insert()
course_uc_node_update in modules/course_uc/course_uc.module
Implements hook_node_update().

File

modules/course_uc/course_uc.module, line 112

Code

function course_uc_node_insert($node) {
  if (course_node_is_course($node) && isset($node->sell_price) && $node->sell_price > 0) {

    // Course has a sell price.
    $course = course_get_course($node);
    foreach ($course
      ->getObjects() as $courseObject) {
      if ($courseObject
        ->getComponent() == 'payment') {
        return;
      }
    }

    // If we are here, the course did not have a payment object.
    $newObject = course_get_course_object('payment');
    $newObject
      ->setCourse($course);
    $newObject
      ->setCourse($node
      ->id());
    $newObject
      ->setModule('course_uc');
    $newObject
      ->setComponent('payment');
    $newObject
      ->setInstanceId($node
      ->id());
    $newObject
      ->setOption('title', 'Payment required');
    $newObject
      ->setOption('required', TRUE);
    $newObject
      ->setOption('enabled', TRUE);
    $newObject
      ->setOption('hidden', TRUE);
    $newObject
      ->setOption('weight', -9999);
    $newObject
      ->save();
  }
}