Merge pull request #12031 from mukeshcompucorp/fix-template-structure-issues
[civicrm-core.git] / CRM / Utils / Check / Component / PriceFields.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2018 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2018
33 */
34 class CRM_Utils_Check_Component_PriceFields extends CRM_Utils_Check_Component {
35
36 /**
37 * Display warning about invalid priceFields
38 *
39 */
40 public function checkPriceFields() {
41 $sql = "SELECT DISTINCT ps.title as ps_title, ps.id as ps_id, psf.label as psf_label
42 FROM civicrm_price_set ps
43 INNER JOIN civicrm_price_field psf ON psf.price_set_id = ps.id
44 INNER JOIN civicrm_price_field_value pfv ON pfv.price_field_id = psf.id
45 LEFT JOIN civicrm_financial_type cft ON cft.id = pfv.financial_type_id
46 WHERE cft.id IS NULL OR cft.is_active = 0";
47 $dao = CRM_Core_DAO::executeQuery($sql);
48 $count = 0;
49 $html = '';
50 $messages = array();
51 while ($dao->fetch()) {
52 $count++;
53 $url = CRM_Utils_System::url('civicrm/admin/price/field', array(
54 'reset' => 1,
55 'action' => 'browse',
56 'sid' => $dao->ps_id));
57 $html .= "<tr><td>$dao->ps_title</td><td>$dao->psf_label</td><td><a href='$url'>View Price Set Fields</a></td></tr>";
58 }
59 if ($count > 0) {
60 $msg = "<p>the following Price Set Fields use disabled or invalid financial types and need to be fixed if they are to still be used.<p>
61 <p><table><thead><tr><th>Price Set</th><th>Price Set Field</th><th>Action Link</th>
62 </tr></thead><tbody>
63 $html
64 </tbody></table></p>";
65 $messages[] = new CRM_Utils_Check_Message(
66 __FUNCTION__,
67 ts($msg),
68 ts('Invalid Price Fields'),
69 \Psr\Log\LogLevel::WARNING,
70 'fa-lock'
71 );
72 }
73 return $messages;
74 }
75
76 }