You are here

commerce_pricelist_user.module in Commerce Pricelist 7

Summary

Description

File

commerce_pricelist_user/commerce_pricelist_user.module
View source
<?php

/**
* @file
* Summary
*
* Description
*/

/**
 * Filter out lists not tagged with current user
 *
 * @param $pricelists
 */
function commerce_pricelist_user_commerce_pricelists_alter(&$pricelists, $user) {
  commerce_pricelist_filter_pricelists($pricelists, array(
    'user' => array(
      $user->uid,
    ),
  ));
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function commerce_pricelist_user_form_commerce_pricelist_list_form_alter(&$form, $form_state) {
  $entity = $form['entity']['#value'];
  $form['#validate'][] = 'commerce_pricelist_user_form_validate';
  $default = commerce_pricelist_list_filter_get($entity, 'user');

  // @todo: implement as user reference field or something
  $form['commerce_pricelist_user'] = array(
    '#type' => 'textarea',
    '#title' => t('User IDs'),
    '#default_value' => implode(', ', $default),
  );
}
function commerce_pricelist_user_form_validate($form, &$form_state) {
  if ($form_state['triggering_element']['#id'] !== 'edit-delete') {
    $entity =& $form_state['values']['entity'];
    preg_match_all('!\\d+!', $form_state['values']['commerce_pricelist_user'], $matches);
    commerce_pricelist_list_filter_set($entity, 'user', $matches[0]);
  }
}

/**
 * Add info to pricelist overview
 *
 * @param $info
 * @param $entity
 */
function commerce_pricelist_user_commerce_pricelists_list_info_alter(&$info, $entity) {
  $filter = commerce_pricelist_list_filter_get($entity, 'user');
  $count = count($filter);
  $info['user'] = $count . ' ' . t('users') . '<br>';
}