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_file.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 / * Unchanged anonymous code contribution. No claim.
28 *
29 * civicrm_handler_field_custom_file.inc
30 * Displays File field uri instead of id.
31 *
32 */
33
34 /**
35 * Field handler to provide acess control for the File field
36 *
37 * @ingroup civicrm_field_handlers
38 */
39 class civicrm_handler_field_custom_file extends views_handler_field {
40 function construct() {
41 parent::construct();
42 civicrm_initialize();
43 $this->additional_fields['entity_id'] = 'entity_id';
44 }
45
46 function render($values) {
47 $value = $values->{$this->field_alias};
48 if (!is_null($value)) {
49 $path = 'civicrm/file';
50 $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
51 $value,
52 'mime_type'
53 );
54
55 if ($fileType && in_array($fileType, array(
56 "image/jpeg", "image/pjpeg", "image/gif", "image/x-png", "image/png"))) {
57 $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
58 $value,
59 'uri'
60 );
61
62 $path = sprintf('%s/imagefile',$path);
63 }
64 $entityField = $this->aliases['entity_id'];
65 $url = CRM_Utils_System::url($path,
66 "id={$value}&eid={$values->$entityField}",
67 TRUE, FALSE, FALSE, TRUE
68 );
69 return CRM_Utils_System::url($path,
70 "id={$value}&eid={$values->$entityField}",
71 TRUE, FALSE, FALSE, TRUE
72 );
73 }
74 return NULL;
75 }
76 }
77
78