Merge pull request #11986 from eileenmcnaughton/test
[civicrm-core.git] / CRM / Utils / Check / Component / OptionGroups.php
CommitLineData
24877581
SL
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
24877581
SL
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
24877581
SL
32 */
33class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component {
34
35 /**
36 * @return array
37 */
38 public function checkOptionGroupValues() {
39 $messages = array();
40 $problemValues = array();
41 $optionGroups = civicrm_api3('OptionGroup', 'get', array(
42 'sequential' => 1,
43 'data_type' => array('IS NOT NULL' => 1),
89c05afc 44 'options' => array('limit' => 0),
24877581
SL
45 ));
46 if ($optionGroups['count'] > 0) {
47 foreach ($optionGroups['values'] as $optionGroup) {
89c05afc
SL
48 $values = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroup['id']);
49 if (count($values) > 0) {
50 foreach ($values as $value) {
24877581
SL
51 $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE);
52 if (!$validate) {
53 $problemValues[] = array(
c62c37c7 54 'group_name' => $optionGroup['title'],
24877581
SL
55 'value_name' => $value['label'],
56 );
57 }
58 }
59 }
60 }
61 }
62 if (!empty($problemValues)) {
a37e4e6c 63 $strings = '';
24877581 64 foreach ($problemValues as $problemValue) {
a37e4e6c 65 $strings .= ts('<tr><td> "%1" </td><td> "%2" </td></tr>', array(
24877581
SL
66 1 => $problemValue['group_name'],
67 2 => $problemValue['value_name'],
68 ));
69 }
70
71 $messages[] = new CRM_Utils_Check_Message(
72 __FUNCTION__,
73 ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p>
74 <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') .
a37e4e6c 75 $strings . ts('</tbody></table></p>'),
24877581
SL
76 ts('Option Values with problematic Values'),
77 \Psr\Log\LogLevel::NOTICE,
78 'fa-server'
79 );
80 }
81
82 return $messages;
83 }
84
85}