<?php
/**
 * @file
 * Code for the DIY Tools feature.
 */

include_once 'diy_tools.features.inc';

/**
 * Implements hook_entity_info_alter().
 */
function diy_tools_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['embed_tools'] = array(
    'label' => t('Tools embed'),
    'custom settings' => TRUE,
  );
}

/**
 * Implements hook_preprocess_node().
 */
function diy_tools_preprocess_node(&$vars) {
  if($vars['view_mode'] == 'embed_tools') {
    $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__embed_tools';
    $vars['classes_array'][] = 'node-embed-tools';
  }
} 

/** 
 * Helper function for retrieving avg price for tools
 */
function diy_tools_get_price($values) {
  if(!empty($values)) {
    $price = array_sum($values) / count($values);
    $sum = number_format($price, 2, ',', '.');
    
    return $sum;
  }
  
  return FALSE;
}