Commit | Line | Data |
---|---|---|
24877581 SL |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2016 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2016 | |
32 | */ | |
33 | class 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), | |
44 | )); | |
45 | if ($optionGroups['count'] > 0) { | |
46 | foreach ($optionGroups['values'] as $optionGroup) { | |
47 | $values = civicrm_api3('OptionValue', 'get', array( | |
48 | 'sequential' => 1, | |
49 | 'option_group_id' => $optionGroup['name'], | |
50 | )); | |
51 | if ($values['count'] > 0) { | |
52 | foreach ($values['values'] as $value) { | |
53 | $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE); | |
54 | if (!$validate) { | |
55 | $problemValues[] = array( | |
56 | 'group_name' => $optionGroup['label'], | |
57 | 'value_name' => $value['label'], | |
58 | ); | |
59 | } | |
60 | } | |
61 | } | |
62 | } | |
63 | } | |
64 | if (!empty($problemValues)) { | |
65 | $strings = array(); | |
66 | foreach ($problemValues as $problemValue) { | |
67 | $strings[] = ts('<tr><td> "%1" </td><td> "%2" </td></tr>', array( | |
68 | 1 => $problemValue['group_name'], | |
69 | 2 => $problemValue['value_name'], | |
70 | )); | |
71 | } | |
72 | ||
73 | $messages[] = new CRM_Utils_Check_Message( | |
74 | __FUNCTION__, | |
75 | ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p> | |
76 | <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') . | |
9e48be79 | 77 | explode('\n', $strings) . ts('</tbody></table></p>'), |
24877581 SL |
78 | ts('Option Values with problematic Values'), |
79 | \Psr\Log\LogLevel::NOTICE, | |
80 | 'fa-server' | |
81 | ); | |
82 | } | |
83 | ||
84 | return $messages; | |
85 | } | |
86 | ||
87 | } |