commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / drupal / modules / views / civicrm / civicrm_handler_field_money.inc
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24 */
25
26 /**
27 * Field handler to provide a formatted monetary string
28 *
29 * @ingroup civicrm_field_handlers
30 */
31 class civicrm_handler_field_money extends views_handler_field {
32 function construct() {
33 parent::construct();
34 if (!civicrm_initialize()) {
35 return;
36 }
37 require_once 'CRM/Utils/Money.php';
38
39 if ($this->definition['currency field']) {
40 $this->additional_fields['currency'] = array('field' => $this->definition['currency field']);
41 }
42 }
43
44 function render($values) {
45 $value = $this->get_value($values);
46 $currency = $this->get_value($values, 'currency');
47
48 switch ($this->options ['display_format']) {
49 case 'formatted':
50 return CRM_Utils_Money::format($value, $currency);
51
52 case 'raw':
53 return $value;
54 }
55 }
56
57 function option_definition() {
58 $options = parent::option_definition();
59
60 $options ['display_format'] = array('default' => 'formatted');
61
62 return $options;
63 }
64
65 function options_form(&$form, &$form_state) {
66 parent::options_form($form, $form_state);
67 $form ['display_format'] = array(
68 '#type' => 'select',
69 '#title' => t('Display format'),
70 '#options' => array(
71 'formatted' => t('Currency formatted amount ($123.45)'),
72 'raw' => t('Raw amount (123.45)'),
73 ),
74 '#default_value' => $this->options ['display_format'],
75 );
76 }
77 }