appointment_calendar.install in Appointment Calendar 7
Same filename and directory in other branches
Install and uninstall functions for the Appointment Calendar module.
File
appointment_calendar.installView source
<?php
/**
* @file
* Install and uninstall functions for the Appointment Calendar module.
*/
/**
* Implements hook_install().
*/
function appointment_calendar_install() {
node_types_rebuild();
node_type_get_types();
appointment_calendar_add_custom_fields();
appointment_calendar_add_template_page();
}
/**
* Implements intalled fields.
*/
function appointment_calendar_productcustomtype_installed_fields() {
$t = get_t();
return array(
'appointment_date' => array(
'field_name' => 'appointment_date',
'label' => $t('Appointment Date'),
'type' => 'date',
'settings' => array(
'granularity' => array(
'day' => 'day',
'hour' => 'hour',
'minute' => 'minute',
'month' => 'month',
'year' => 'year',
),
'repeat' => 0,
'timezone_db' => '',
'todate' => '',
'tz_handling' => 'none',
),
),
'appointment_slot' => array(
'field_name' => 'appointment_slot',
'label' => $t('Appointment Slot '),
'type' => 'list_text',
),
);
}
/**
* Implements installed instances.
*/
function appointment_calendar_productcustomtype_installed_instances() {
$t = get_t();
return array(
'appointment_date' => array(
'field_name' => 'appointment_date',
'type' => 'text',
'label' => $t('Appointment Date'),
'widget' => array(
'type' => 'date_popup',
'settings' => array(
'input_format' => 'Y-m-d H:i:s',
'year_range' => '-0:+5',
'tz_handling' => 'none',
),
),
'display' => array(
'default' => array(
'label' => $t('Appointment Date'),
'type' => 'date_popup',
),
),
),
'appointment_slot' => array(
'field_name' => 'appointment_slot',
'type' => 'text',
'label' => $t('Appointment Slot'),
'widget' => array(
'type' => 'list_text',
),
'display' => array(
'default' => array(
'label' => $t('Appointment Slot'),
'type' => 'list_text',
),
),
),
);
}
/**
* Adds fields in content type.
*/
function appointment_calendar_add_custom_fields() {
foreach (appointment_calendar_productcustomtype_installed_fields() as $field) {
field_create_field($field);
}
foreach (appointment_calendar_productcustomtype_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'appointment_calendar';
field_create_instance($fieldinstance);
}
}
/**
* Implements hook_unistall().
*/
function appointment_calendar_uninstall() {
$ournewtype = 'appointment_calendar';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(
':type' => $ournewtype,
));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
appointment_calendar_delete_custom_fields();
node_type_delete($ournewtype);
field_purge_batch(500);
// Unlink file.
appointment_calendar_delete_template_page();
}
/**
* Delete fileds in unistall module.
*/
function appointment_calendar_delete_custom_fields() {
foreach (array_keys(appointment_calendar_productcustomtype_installed_fields()) as $field) {
field_delete_field($field);
}
$instances = field_info_instances('node', 'appointment_calendar');
$instance_values = array_values($instances);
foreach ($instance_values as $fieldinstance) {
field_delete_instance($fieldinstance);
}
}
/**
* Implements hook_schema().
*/
function appointment_calendar_schema() {
$schema['appointment_date'] = array(
'description' => 'The base table for Appointment Calendar Dates.',
'fields' => array(
'date' => array(
'description' => 'Appointment Date',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'no_slots' => array(
'description' => 'No of Time Slots for particular Day.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'slot_values' => array(
'description' => 'Time Slots values for particular Day.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
'slot_capacity' => array(
'description' => 'Time Slots Capacity for particular Day.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
),
);
return $schema;
}
/**
* Implements function to copy template in themes that are enabled.
*/
function appointment_calendar_add_template_page() {
$query = db_select('system', 'sy');
$query
->fields('sy', array(
'name',
));
$query
->condition('status', 1);
$query
->condition('type', 'theme', '=');
$query
->condition('name', array(
'seven',
'garland',
'engine',
), 'NOT IN');
$result = $query
->execute()
->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $res) {
$path = drupal_get_path('theme', $res['name']);
chmod($path, 0777);
if (file_prepare_directory($path)) {
$source = drupal_get_path('module', 'appointment_calendar') . '/templates/page--appointcal.tpl.php';
$destination = $path . '/templates/page--appointcal.tpl.php';
file_unmanaged_copy($source, $destination);
}
}
}
/**
* Implements function to delete template that copied in theme folders.
*/
function appointment_calendar_delete_template_page() {
$query = db_select('system', 'sy');
$query
->fields('sy', array(
'name',
));
$query
->condition('status', 1);
$query
->condition('type', 'theme', '=');
$query
->condition('name', array(
'seven',
'garland',
'engine',
), 'NOT IN');
$result = $query
->execute()
->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $res) {
$path = drupal_get_path('theme', $res['name']);
chmod($path, 0777);
$destination = $path . '/templates/page--appointcal.tpl.php';
if (file_exists($destination)) {
file_unmanaged_delete($destination);
}
}
}
Functions
Name | Description |
---|---|
appointment_calendar_add_custom_fields | Adds fields in content type. |
appointment_calendar_add_template_page | Implements function to copy template in themes that are enabled. |
appointment_calendar_delete_custom_fields | Delete fileds in unistall module. |
appointment_calendar_delete_template_page | Implements function to delete template that copied in theme folders. |
appointment_calendar_install | Implements hook_install(). |
appointment_calendar_productcustomtype_installed_fields | Implements intalled fields. |
appointment_calendar_productcustomtype_installed_instances | Implements installed instances. |
appointment_calendar_schema | Implements hook_schema(). |
appointment_calendar_uninstall | Implements hook_unistall(). |