You are here

function pmexpense_install in Drupal PM (Project Management) 7

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

Implements hook_install().

File

pmexpense/pmexpense.install, line 10
Installation file for pmexpense module.

Code

function pmexpense_install() {
  variable_set('node_options_pmexpense', array(
    'status',
  ));
  variable_set('node_permissions_pmexpense', 0);

  // Expense date field.
  if (!field_info_field('pmexpense_date')) {
    field_create_field(array(
      'type' => 'datetime',
      'field_name' => 'pmexpense_date',
      'settings' => array(
        'granularity' => array(
          'year' => 'year',
          'month' => 'month',
          'day' => 'day',
          'hour' => 0,
          'minute' => 0,
          'second' => 0,
        ),
        'tz_handling' => '',
        'timezone_db' => '',
        'todate' => '',
      ),
      'cardinality' => '1',
    ));
  }
  if (!field_info_instance('node', 'pmexpense_date', 'pmexpense')) {
    field_create_instance(array(
      'field_name' => 'pmexpense_date',
      'bundle' => 'pmexpense',
      'label' => 'Expense Date',
      'required' => 1,
      'entity_type' => 'node',
      'widget' => array(
        'weight' => '-18',
        'type' => 'date_text',
        'active' => 1,
      ),
      'settings' => array(
        'default_value' => 'now',
      ),
    ));
  }

  // Set up instance of billing status field.
  if (!field_info_instance('node', 'pm_billing_status', 'pmexpense')) {
    field_create_instance(array(
      'field_name' => 'pm_billing_status',
      'label' => 'Billing status',
      'entity_type' => 'node',
      'bundle' => 'pmexpense',
      'widget' => array(
        'weight' => -17,
        'type' => 'options_select',
        'module' => 'options',
        'active' => 1,
        'settings' => array(),
      ),
      'required' => 1,
      'description' => '',
      'default_value' => array(
        array(
          'value' => variable_get('pmexpense_billable_default', 0) ? 'Billable' : 'Not billable',
        ),
      ),
    ));
  }
  $attributes = array();
  $attributes['Expense status'] = array(
    'outstanding' => 'Outstanding',
    'paid' => 'Paid',
  );
  $attributes['Expense status search'] = array(
    'outstanding' => 'Outstanding',
    'paid' => 'Paid',
  );
  $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;
  }
}