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_phone.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 for phone field
28 *
29 * @ingroup civicrm_field_handlers
30 */
31 class civicrm_handler_field_phone extends civicrm_handler_field_location {
32 static $_phoneType;
33 function construct() {
34 parent::construct();
35 if (!self::$_phoneType) {
36 if (!civicrm_initialize()) {
37 return;
38 }
39 self::$_phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
40 }
41 }
42
43 function option_definition() {
44 $options = parent::option_definition();
45 $options['phone_type'] = array('default' => 0);
46 return $options;
47 }
48
49 function options_form(&$form, &$form_state) {
50 parent::options_form($form, $form_state);
51 $phoneOptions = array(0 => 'Any');
52 foreach (self::$_phoneType as $id => $type) {
53 $phoneOptions[$id] = $type;
54 }
55 $form['phone_type'] = array(
56 '#type' => 'radios',
57 '#title' => 'Phone type for this field',
58 '#options' => $phoneOptions,
59 '#description' => t('Phone type to be displayed for this field'),
60 '#default_value' => $this->options['phone_type'],
61 '#fieldset' => 'location_choices',
62 );
63 }
64
65 function ensure_my_table() {
66 if (!isset($this->table_alias)) {
67 if (!method_exists($this->query, 'ensure_table')) {
68 vpr_trace();
69 exit;
70 }
71 if (isset($this->options['phone_type']) && $this->options['phone_type']) {
72 $join = $this->get_join();
73 $extra = parent::location_extras();
74 $extra[] = array(
75 'value' => $this->options['phone_type'],
76 'numeric' => TRUE,
77 'field' => 'phone_type_id',
78 'operator' => '=',
79 );
80 $join->extra = $extra;
81 $join->extra_type = self::$_locationOps[$this->options['location_op']];
82 $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
83 }
84 else {
85 $join = $this->get_join();
86 $join->extra = parent::location_extras();
87 $join->extra_type = self::$_locationOps[$this->options['location_op']];
88 $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
89 }
90 }
91 return $this->table_alias;
92 }
93 }
94