You are here

function opigno_class_app_install in Opigno Class App 7

Implements hook_install()

File

./opigno_class_app.install, line 11
Contains install instructions and logic

Code

function opigno_class_app_install() {
  $type = node_type_load("class");

  //Check if content type exists
  if (empty($type)) {
    $type = node_type_set_defaults(array(
      'type' => 'class',
      'name' => st('Class'),
      'base' => 'node_content',
      'description' => st('A Class, og group collection of users, courses, and a teacher'),
      'has_title' => '1',
      'title_label' => st('Title'),
      'help' => '',
    ));
    node_type_save($type);
    node_add_body_field($type);
  }
  if (module_exists('comment')) {
    variable_set('comment_class', COMMENT_NODE_CLOSED);
  }
  if (function_exists('og_ui_node_type_save')) {
    variable_set('og_group_type_class', TRUE);
    og_create_field(OG_GROUP_FIELD, 'node', "class");
  }
  if (module_exists('og_access')) {
    og_create_field(OG_ACCESS_FIELD, 'node', 'class');
  }
  $field = field_info_field('opigno_class_courses');
  if (empty($field)) {
    field_create_field(array(
      'active' => 1,
      'cardinality' => -1,
      'deleted' => 0,
      'entity_types' => array(),
      'field_name' => 'opigno_class_courses',
      'foreign keys' => array(
        'node' => array(
          'columns' => array(
            'target_id' => 'nid',
          ),
          'table' => 'node',
        ),
      ),
      'indexes' => array(
        'target_id' => array(
          0 => 'target_id',
        ),
      ),
      'locked' => 0,
      'module' => 'entityreference',
      'settings' => array(
        'handler' => 'base',
        'handler_settings' => array(
          'behaviors' => array(
            'views-select-list' => array(
              'status' => 0,
            ),
          ),
          'sort' => array(
            'type' => 'none',
          ),
          'target_bundles' => array(
            'course' => 'course',
          ),
        ),
        'target_type' => 'node',
      ),
      'translatable' => 0,
      'type' => 'entityreference',
    ));
  }
  $field = field_info_field('opigno_class_expiration');
  if (empty($field)) {
    field_create_field(array(
      'active' => 1,
      'cardinality' => 1,
      'deleted' => 0,
      'entity_types' => array(),
      'field_name' => 'opigno_class_expiration',
      'foreign keys' => array(),
      'indexes' => array(),
      'locked' => 0,
      'module' => 'date',
      'settings' => array(
        'cache_count' => 4,
        'cache_enabled' => 0,
        'granularity' => array(
          'day' => 'day',
          'hour' => 'hour',
          'minute' => 'minute',
          'month' => 'month',
          'second' => 0,
          'year' => 'year',
        ),
        'timezone_db' => 'UTC',
        'todate' => '',
        'tz_handling' => 'site',
      ),
      'translatable' => 0,
      'type' => 'date',
    ));
  }
  $instance = field_info_instance('node', 'opigno_class_courses', 'class');
  if (empty($instance)) {
    field_create_instance(array(
      'bundle' => 'class',
      'default_value' => NULL,
      'deleted' => 0,
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'above',
          'module' => 'entityreference',
          'settings' => array(
            'link' => FALSE,
          ),
          'type' => 'entityreference_label',
          'weight' => 6,
        ),
        'teaser' => array(
          'label' => 'above',
          'settings' => array(),
          'type' => 'hidden',
          'weight' => 0,
        ),
      ),
      'entity_type' => 'node',
      'field_name' => 'opigno_class_courses',
      'label' => 'Courses',
      'required' => 0,
      'settings' => array(
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'active' => 1,
        'module' => 'options',
        'settings' => array(),
        'type' => 'options_select',
        'weight' => 4,
      ),
    ));
  }
  $instance = field_info_instance('node', 'opigno_class_expiration', 'class');
  if (empty($instance)) {
    field_create_instance(array(
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'above',
          'module' => 'date',
          'settings' => array(
            'format_type' => 'long',
            'fromto' => 'both',
            'multiple_from' => '',
            'multiple_number' => '',
            'multiple_to' => '',
          ),
          'type' => 'date_default',
          'weight' => 7,
        ),
        'teaser' => array(
          'label' => 'above',
          'settings' => array(),
          'type' => 'hidden',
          'weight' => 0,
        ),
      ),
      'label' => 'Expiration',
      'required' => 0,
      'settings' => array(
        'default_value' => 'blank',
        'default_value_code' => '',
        'default_value2' => 'same',
        'default_value_code2' => '',
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'weight' => 5,
        'type' => 'date_popup',
        'module' => 'date',
        'active' => 1,
        'settings' => array(
          'input_format' => 'm/d/Y - H:i:s',
          'input_format_custom' => '',
          'year_range' => '-3:+3',
          'increment' => '15',
          'label_position' => 'above',
          'text_parts' => array(),
        ),
      ),
      'field_name' => 'opigno_class_expiration',
      'entity_type' => 'node',
      'bundle' => 'class',
      'deleted' => '0',
    ));
  }

  // Add the image field for class
  opigno_class_app_update_7102();
  $student_role = og_role_create('student', 'node', 0, 'class');
  $teacher_role = og_role_create('coach', 'node', 0, 'class');
  drupal_write_record('og_role', $student_role);
  drupal_write_record('og_role', $teacher_role);
  variable_set('class_app_course_studentid', '7');
  variable_set('class_app_course_coachid', '12');
  variable_set('class_app_class_studentid', $student_role->rid);
  variable_set('class_app_class_coachid', $teacher_role->rid);
}