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_state.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 acess control for the state field (which is a lookup)
28 *
29 * @ingroup civicrm_field_handlers
30 */
31 class civicrm_handler_field_state extends civicrm_handler_field_address {
32 static $_states;
33 static $_states_full;
34 function construct() {
35 parent::construct();
36 if (!self::$_states || !self::$_states_full) {
37 if (!civicrm_initialize()) {
38 return;
39 }
40 require_once 'CRM/Core/PseudoConstant.php';
41 self::$_states = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
42 self::$_states_full = CRM_Core_PseudoConstant::stateProvince();
43 }
44 }
45
46 function render($values) {
47 $sid = $values->{$this->field_alias};
48 if (empty($sid) ||
49 (int ) $sid <= 0
50 ) {
51 return NULL;
52 }
53
54 if ($this->options['prov_display'] == 1) {
55 return self::$_states[$values->{$this->field_alias}];
56 }
57 else {
58 return self::$_states_full[$values->{$this->field_alias}];
59 }
60 }
61
62 function option_definition() {
63 $options = parent::option_definition();
64 $options['prov_display'] = array('default' => '');
65 return $options;
66 }
67
68 function options_form(&$form, &$form_state) {
69 parent::options_form($form, $form_state);
70 $form['prov_display'] = array(
71 '#type' => 'radios',
72 '#title' => 'Display complete name or abbreviation',
73 '#options' => array(1 => 'Display state/province abbreviations', 2 => 'Display full state/province name'),
74 '#description' => t('Display full or abbreviated province name'),
75 '#default_value' => $this->options['prov_display'],
76 );
77 }
78 }
79