. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * @file * Install, update and uninstall functions for the Mica Studies module. */ /** * Implements hook_install(). */ function mica_studies_install() { _mica_import_custom_name_format(); _mica_node_reference_block(); _mica_studies_create_date_format(); mica_core_configure_feeds_tamper('mica_studies'); } /** * * Updates the mapping of field_data_sources. Values will be changed from-to:
* 'cross_sectional_questionnaires' = 'questionnaires'
* 'longitudinal_questionnaires' = 'questionnaires'
* 'cross_sectional_physical_measures' = 'physical_measures'
* 'longitudinal_physical_measures' = 'physical_measures'
* 'cross_sectional_biological_samples' = 'biological_samples'
* 'longitudinal_biological_samples' = 'biological_samples'

* Updates field_dataset_studies from viewreference to node_reference * @param $sandbox * @throws DrupalUpdateException * @return message */ function mica_studies_update_7120(&$sandbox) { try { _mica_studies_configure_field_bundle_settings(); mica_core_configure_feeds_tamper('mica_studies'); if (db_table_exists('field_data_field_data_sources')) { $mappings = array('questionnaires', 'physical_measures', 'biological_samples'); foreach ($mappings as $mapping) { db_update('field_data_field_data_sources') ->fields(array('field_data_sources_value' => $mapping)) ->condition('field_data_sources_value', '%_' . $mapping, 'LIKE') ->execute(); } } features_revert(array('mica_studies' => array('field', 'field_group', 'variable', 'views_view'))); return st('The field_data_sources mapping update is completed and the field field_dataset_studies has been updated.'); } catch (Exception $e) { throw new DrupalUpdateException('Failed to update mica_studies: ' . $e->getMessage()); } } /** * * Migrate data from recruitment_procedures to recruitment_sources field.
* Apply new permissions. */ function mica_studies_update_7130(&$sandbox) { features_revert(array('mica_studies' => array('field', 'field_group', 'search_api_index', 'user_permission'))); // $base_path = drupal_get_path('module', 'mica_studies') . '/taxonomies/'; _mica_studies_create_source_of_recruitment_taxonomy(); // map values from recruitment_procedures to recruitment_sources _mica_studies_migrate_field_recruitment_procedures(); // configure facet blocks require_once 'mica_studies.facet_blocks.inc'; // configure facets $theme_default = variable_get('theme_default', 'mica_samara'); $page = 'variable-search'; $facet_order_by_region = array( 'sidebar_second' => array( 'field_recruitment_sources' => COLLAPSIBLOCK_TYPE_COLLAPSED_BY_DEFAULT, ) ); mica_studies_configure_facets($facet_order_by_region, $page, $theme_default); } /** * Create custom date format because Features does not support date_formats yet * @see http://drupal.org/node/1279928 */ function _mica_studies_create_date_format() { $pattern = 'M Y'; $format = array(); $format['format'] = $pattern; $format['type'] = 'custom'; $format['locked'] = 0; $format['is_new'] = 1; system_date_format_save($format); $machine_name = 'month_year'; $format_type = array(); $format_type['title'] = 'Month year'; $format_type['type'] = $machine_name; $format_type['locked'] = 0; $format_type['is_new'] = 1; system_date_format_type_save($format_type); variable_set('date_format_' . $machine_name, $pattern); } function _mica_import_custom_name_format() { // add custom field format for name until next release of views $custom_format = array( 'name' => 'Title', 'machine_name' => 'title', 'format' => 't', ); drupal_write_record('name_custom_format', $custom_format); } function _mica_node_reference_block() { db_delete('block_node_type') ->condition('module', 'node_reference_block') ->condition('delta', 'related-content') ->condition('type', 'study%', 'LIKE') ->execute(); $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta')); foreach (array('study', 'contact') as $type) { $query->values(array( 'type' => $type, 'module' => 'node_reference_block', 'delta' => 'related-content', )); } $query->execute(); } /** * Manually configure field_bundle_settings variable because it is exported via strongarms * so it cannot be configured in several modules */ function _mica_studies_configure_field_bundle_settings() { $study_settings = array( 'view_modes' => array( 'teaser' => array('custom_settings' => TRUE), 'banner_area' => array('custom_settings' => TRUE), 'left_area' => array('custom_settings' => TRUE), 'right_area' => array('custom_settings' => TRUE), 'center_area' => array('custom_settings' => TRUE), 'footer_area' => array('custom_settings' => TRUE), 'summary_banner_area' => array('custom_settings' => TRUE), 'summary_left_area' => array('custom_settings' => TRUE), 'summary_right_area' => array('custom_settings' => TRUE), ), 'extra_fields' => array( 'form' => array( 'title' => array('weight' => '12'), 'path' => array('weight' => '1'), ), 'display' => array(), ), ); field_bundle_settings('node', 'study', $study_settings); $contact_settings = array( 'view_modes' => array( 'teaser' => array('custom_settings' => TRUE), ), 'extra_fields' => array( 'form' => array( 'title' => array('weight' => '0'), 'path' => array('weight' => '1'), ), 'display' => array(), ), ); field_bundle_settings('node', 'contact', $contact_settings); $documents_settings = array( 'view_modes' => array(), 'extra_fields' => array( 'form' => array( 'title' => array('weight' => '-5'), ), 'display' => array(), ), ); field_bundle_settings('node', 'documents', $documents_settings); } function _mica_studies_create_source_of_recruitment_taxonomy(){ $vocabulary = _mica_core_taxonomy_create('sources_of_recruitment.csv', 'Source of Recruitment'); $vid = $vocabulary->vid; $term = mica_core_taxonomy_term_save($vid, 'General population'); mica_core_taxonomy_term_save($vid, 'Volunteer enrolment', $term->tid, 40); mica_core_taxonomy_term_save($vid, 'Selected sample (e.g.: from governmental databases)', $term->tid, 50); mica_core_taxonomy_term_save($vid, 'Participants from existing studies'); $term = mica_core_taxonomy_term_save($vid, 'Specific population'); mica_core_taxonomy_term_save($vid, 'Clinic patients', $term->tid, 30); mica_core_taxonomy_term_save($vid, 'Members of specific association (professional association, patients network, etc)', $term->tid, 40); mica_core_taxonomy_term_save($vid, 'Other source', $term->tid, 50); } function _mica_studies_migrate_field_recruitment_procedures(){ // Move data from field_recruitment_procedures to taxonomy field_recruitment_source $result = db_select('field_data_field_recruitment_procedures', 'r') ->fields('r', array('entity_id', 'field_recruitment_procedures_value')) ->execute(); while($record = $result->fetchAssoc()) { $value = $record['field_recruitment_procedures_value']; // insert taxonomy data $study = node_load((int)$record['entity_id']); $wrapper = entity_metadata_wrapper('node', $study); $sources = $wrapper->field_recruitment_sources->value(); $terms = array(); switch ($value) { case 'general_population' : $terms = taxonomy_get_term_by_name('General population', 'sources_of_recruitment'); break; case 'legacy_studies' : $terms = taxonomy_get_term_by_name('Participants from existing studies', 'sources_of_recruitment'); break; case 'specific_population' : $terms = taxonomy_get_term_by_name('Specific population', 'sources_of_recruitment'); break; case 'other' : $terms = taxonomy_get_term_by_name('Other source', 'sources_of_recruitment'); break; } if (!empty($terms)){ $k = array_keys($terms); $tids = array(); if (!empty($sources)){ foreach($sources as $source){ $tids[] = $source->tid; } } array_push($tids, $k[0]); $wrapper->field_recruitment_sources->set($tids); $wrapper->save(); } } spl_autoload_register('_search_api_solr_autoload'); field_delete_field('field_recruitment_procedures'); }