You are here

opigno_class_app.install in Opigno Class App 7

Contains install instructions and logic

File

opigno_class_app.install
View source
<?php

/**
 * @file
 * Contains install instructions and logic
 */

/**
 * Implements hook_install()
 */
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);
}

/**
 * Enable the sort groups by default
 */
function opigno_class_app_update_7101() {
  module_enable(array(
    'opigno_sort_groups',
  ), TRUE);
}

/**
 * Add default image for classes
 */
function opigno_class_app_update_7102() {
  $type = node_type_load('class');
  if (!empty($type)) {
    $field = field_info_field('opigno_class_image');
    if (empty($field)) {
      field_create_field(array(
        'active' => 1,
        'cardinality' => 1,
        'deleted' => 0,
        'entity_types' => array(),
        'field_name' => 'opigno_class_image',
        'foreign keys' => array(
          'fid' => array(
            'columns' => array(
              'fid' => 'fid',
            ),
            'table' => 'file_managed',
          ),
        ),
        'indexes' => array(
          'fid' => array(
            0 => 'fid',
          ),
        ),
        'locked' => 0,
        'module' => 'image',
        'settings' => array(
          'default_image' => 47,
          'uri_scheme' => 'public',
        ),
        'translatable' => 0,
        'type' => 'image',
      ));
    }
    $instance = field_info_instance('node', 'opigno_class_image', 'class');
    if (empty($instance)) {
      field_create_instance(array(
        'bundle' => 'class',
        'deleted' => 0,
        'description' => '',
        'display' => array(
          'default' => array(
            'label' => 'above',
            'module' => 'image',
            'settings' => array(
              'image_link' => '',
              'image_style' => 'thumbnail',
            ),
            'type' => 'image',
            'weight' => 19,
          ),
          'teaser' => array(
            'label' => 'above',
            'settings' => array(),
            'type' => 'hidden',
            'weight' => 0,
          ),
        ),
        'entity_type' => 'node',
        'field_name' => 'opigno_class_image',
        'label' => 'Image',
        'required' => 0,
        'settings' => array(
          'alt_field' => 0,
          'default_image' => 0,
          'file_directory' => '',
          'file_extensions' => 'png gif jpg jpeg',
          'max_filesize' => '',
          'max_resolution' => '',
          'min_resolution' => '',
          'title_field' => 0,
          'user_register_form' => FALSE,
        ),
        'widget' => array(
          'active' => 1,
          'module' => 'image',
          'settings' => array(
            'preview_image_style' => 'apps_logo_small',
            'progress_indicator' => 'throbber',
          ),
          'type' => 'image_image',
          'weight' => 42,
        ),
      ));
    }
    $source_dir = drupal_get_path('module', 'opigno_class_app') . '/img';
    $filename = 'opigno_class_default.jpg';
    $source = $source_dir . '/' . $filename;
    $field = field_info_field('opigno_class_image');
    opigno_content_set_default_image($field, $filename, $source);
  }
}

Functions

Namesort descending Description
opigno_class_app_install Implements hook_install()
opigno_class_app_update_7101 Enable the sort groups by default
opigno_class_app_update_7102 Add default image for classes