You are here

function pmticket_install in Drupal PM (Project Management) 7

Same name and namespace in other branches
  1. 8 pmticket/pmticket.install \pmticket_install()
  2. 7.3 pmticket/pmticket.install \pmticket_install()
  3. 7.2 pmticket/pmticket.install \pmticket_install()

Implements hook_install().

File

pmticket/pmticket.install, line 10
Installation functions for the Project Management project module

Code

function pmticket_install() {
  variable_set('node_options_pmticket', array(
    'status',
  ));
  variable_set('node_permissions_pmticket', 0);

  // Uncache node types
  node_types_rebuild();

  // Fetch list of current node types and add body field to pmticket
  $types = node_type_get_types();
  node_add_body_field($types['pmticket'], 'Description');

  // Add instance of date field.
  field_create_instance(array(
    'field_name' => 'pm_date',
    'label' => 'Date',
    'widget' => array(
      'weight' => '-18',
      'type' => 'date_text',
      '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(),
      ),
    ),
    'settings' => array(
      'default_value' => 'now',
      'default_value_code' => '',
      'default_value2' => 'same',
      'default_value_code2' => '',
      'user_register_form' => FALSE,
    ),
    'display' => array(
      'default' => array(
        'label' => 'above',
        'type' => 'date_default',
        'settings' => array(
          'format_type' => 'long',
          'multiple_number' => '',
          'multiple_from' => '',
          'multiple_to' => '',
          'fromto' => 'both',
        ),
        'module' => 'date',
        'weight' => 1,
      ),
      'teaser' => array(
        'type' => 'hidden',
        'label' => 'above',
        'settings' => array(),
        'weight' => 0,
      ),
    ),
    'required' => 0,
    'entity_type' => 'node',
    'bundle' => 'pmticket',
  ));

  // Set up instance of billing status field.
  field_create_instance(array(
    'field_name' => 'pm_billing_status',
    'label' => 'Billing status',
    'entity_type' => 'node',
    'bundle' => 'pmticket',
    'widget' => array(
      'weight' => -13,
      'type' => 'options_select',
      'module' => 'options',
      'active' => 1,
      'settings' => array(),
    ),
    'required' => 1,
    'description' => '',
    'default_value' => array(
      array(
        'value' => variable_get('pmticket_billable_default', 0) ? 'Billable' : 'Not billable',
      ),
    ),
  ));
  $attributes = array();
  $attributes['Ticket status'] = array(
    'inserted' => 'inserted',
    'in progress' => 'in progress',
    'on hold' => 'on hold',
    'completed' => 'completed',
  );
  $attributes['Ticket status search'] = array(
    '-' => 'all',
    'inserted,in progress,on hold' => 'open',
    'inserted' => '-- inserted',
    'in progress' => '-- in progress',
    'on hold' => '-- on hold',
    'completed' => 'completed',
  );
  $attributes['Ticket category'] = array(
    'estimate' => 'estimate',
    'bug' => 'bug',
    'feature request' => 'feature request',
    'support' => 'support',
    'task' => 'task',
  );
  $attributes['Ticket category search'] = array(
    '-' => 'all',
    'estimate' => 'estimate',
    'bug' => 'bug',
    'feature request' => 'feature request',
    'support' => 'support',
    'task' => 'task',
  );
  $attributes['Ticket priority'] = array(
    '1-low' => 'low',
    '2-normal' => 'normal',
    '3-high' => 'high',
    '4-urgent' => 'urgent',
  );
  $attributes['Ticket priority search'] = array(
    '-' => 'all',
    '1-low' => 'low',
    '2-normal' => 'normal',
    '3-high' => 'high',
    '4-urgent' => 'urgent',
  );
  $s = "INSERT INTO {pmattribute} (domain, akey, avalue, weight) VALUES ('%s', '%s', '%s', %d)";
  $prevdomain = '';
  $weight = 0;
  foreach ($attributes as $domain => $attribute) {
    if ($domain != $prevdomain) {
      $weight = 0;
    }
    foreach ($attribute as $key => $value) {
      db_insert('pmattribute')
        ->fields(array(
        'domain' => $domain,
        'akey' => $key,
        'avalue' => $value,
        'weight' => $weight,
      ))
        ->execute();
      $weight++;
    }
    $prevdomain = $domain;
  }
}