commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / drupal / modules / views / civicrm / civicrm_handler_field_address.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 * Generic field handler for address and location fields
28 *
29 * @ingroup civicrm_field_handlers
30 */
31 class civicrm_handler_field_address extends civicrm_handler_field_location {
32 static $_locationOps;
33 function construct() {
34 parent::construct();
35 if (!self::$_locationOps) {
36 if (!civicrm_initialize()) {
37 return;
38 }
39 self::$_locationOps = array(0 => 'AND', 1 => 'OR');
40 }
41 }
42
43 function option_definition() {
44 $options = parent::option_definition();
45 $options['is_billing'] = array('default' => '');
46 return $options;
47 }
48
49 function options_form(&$form, &$form_state) {
50 parent::options_form($form, $form_state);
51 $form['is_billing'] = array(
52 '#type' => 'checkbox',
53 '#title' => 'Show only Billing Address record?',
54 '#options' => array(0 => 'No', 1 => 'Yes'),
55 '#description' => t('Check above box if you want only the <strong>Billing Address</strong> record displayed.'),
56 '#default_value' => $this->options['is_billing'],
57 '#fieldset' => 'location_choices',
58 );
59 }
60
61 function ensure_my_table() {
62 if (!isset($this->table_alias)) {
63 if (!method_exists($this->query, 'ensure_table')) {
64 vpr_trace();
65 exit;
66 }
67 $extra = array();
68 $extra = parent::location_extras();
69 if (isset($this->options['is_billing']) && $this->options['is_billing']) {
70 $extra[] = array(
71 'value' => $this->options['is_billing'],
72 'numeric' => TRUE,
73 'field' => 'is_billing',
74 'operator' => '=',
75 );
76 }
77 if (isset($extra) && !empty($extra)) {
78 $join = $this->get_join();
79 $join->extra = $extra;
80 $join->extra_type = self::$_locationOps[$this->options['location_op']];
81 $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
82 }
83 else {
84 $this->table_alias = $this->query->ensure_table($this->table, $this->relationship);
85 }
86 }
87 return $this->table_alias;
88 }
89 }
90
91