From: Eileen McNaughton Date: Tue, 21 Nov 2023 04:55:36 +0000 (+1300) Subject: Fix notices on manage premiums page X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8fa984856905311d3fd04414272abebda3b8cae4;p=civicrm-core.git Fix notices on manage premiums page This addresses notices at https://dmaster.localhost:32353/civicrm/admin/contribute/managePremiums?reset=1 These are probably also addressed by the admin ui / sk conversion but note that this also covers the tab on the contribution page Note that combined with https://github.com/civicrm/civicrm-core/pull/28238 this fixes most of the issues I encountered trying to configure a premimum but there are still a bunch of notices when I attempt to use one. Also, having switched to using apiv4 I have added some tpl escaping --- diff --git a/CRM/Contribute/Page/ManagePremiums.php b/CRM/Contribute/Page/ManagePremiums.php index 0c08a37687..9e7a453341 100644 --- a/CRM/Contribute/Page/ManagePremiums.php +++ b/CRM/Contribute/Page/ManagePremiums.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Product; + /** * Page for displaying list of Premiums. */ @@ -27,7 +29,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * * @var array */ - public static $_links = NULL; + public static $_links; /** * Get BAO Name. @@ -35,7 +37,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * @return string * Classname of BAO. */ - public function getBAOName() { + public function getBAOName(): string { return 'CRM_Contribute_BAO_Product'; } @@ -45,7 +47,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * @return array * (reference) of action links */ - public function &links() { + public function &links(): array { if (!(self::$_links)) { self::$_links = [ CRM_Core_Action::UPDATE => [ @@ -92,8 +94,10 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. + * + * @throws \CRM_Core_Exception */ - public function run() { + public function run(): void { $id = $this->getIdAndAction(); // what action to take ? @@ -104,45 +108,42 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { $this->browse(); // parent run - return CRM_Core_Page::run(); + CRM_Core_Page::run(); } /** * Browse all custom data groups. + * + * @throws \CRM_Core_Exception */ - public function browse() { - // get all custom groups sorted by weight - $premiums = []; - $dao = new CRM_Contribute_DAO_Product(); - $dao->orderBy('name'); - $dao->find(); - - while ($dao->fetch()) { - $premiums[$dao->id] = []; - CRM_Core_DAO::storeValues($dao, $premiums[$dao->id]); - // form all action links + public function browse(): void { + // We could probably use checkPermissions here but historically didn't + // so have set it to FALSE to be safe while converting to api use. + $premiums = Product::get(FALSE)->addOrderBy('name') + ->addSelect('*', 'financial_type_id:name') + ->execute(); + + foreach ($premiums as $index => $premium) { $action = array_sum(array_keys($this->links())); - if ($dao->is_active) { + if ($premium['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } - $premiums[$dao->id]['action'] = CRM_Core_Action::formLink($this->links(), + $premiums[$index]['action'] = CRM_Core_Action::formLink($this->links(), $action, - ['id' => $dao->id], + ['id' => $premium['id']], ts('more'), FALSE, 'premium.manage.row', 'Premium', - $dao->id + $premium['id'] ); - // Financial Type - if (!empty($dao->financial_type_id)) { - $premiums[$dao->id]['financial_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Product', 'financial_type_id', $dao->financial_type_id); - } + $premiums[$index]['financial_type'] = $premium['financial_type_id:name']; + $premiums[$index]['class'] = ''; } $this->assign('rows', $premiums); } @@ -153,7 +154,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * @return string * Classname of edit form. */ - public function editForm() { + public function editForm(): string { return 'CRM_Contribute_Form_ManagePremiums'; } @@ -163,7 +164,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * @return string * name of this page. */ - public function editName() { + public function editName(): string { return 'Manage Premiums'; } @@ -175,7 +176,7 @@ class CRM_Contribute_Page_ManagePremiums extends CRM_Core_Page_Basic { * @return string * user context. */ - public function userContext($mode = NULL) { + public function userContext($mode = NULL): string { return 'civicrm/admin/contribute/managePremiums'; } diff --git a/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl b/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl index 309ced9349..9ad512c6e2 100644 --- a/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl @@ -51,15 +51,15 @@ {foreach from=$products item=row}
- {if $row.thumbnail}
{$row.name|escape}
{/if} -
{$row.name}
+ {if $row.thumbnail}
{$row.name|escape}
{/if} +
{$row.name|escape}
-
{if $row.image}{$row.name|escape}{/if}
+
{if $row.image}{$row.name|escape}{/if}
-
{$row.name}
+
{$row.name|escape}
{ts 1=$row.min_contribution|crmMoney}You must contribute at least %1 to get this item{/ts}
- {$row.description} + {$row.description|escape}
{if $showSelectOptions} {assign var="pid" value="options_"|cat:$row.id} @@ -78,7 +78,7 @@ {/if} {else}
-

{$row.options}

+

{$row.options|purify}

{/if} {if (($premiumBlock.premiums_display_min_contribution AND $context EQ "makeContribution") OR $preview EQ 1) AND $row.min_contribution GT 0} diff --git a/templates/CRM/Contribute/Page/ManagePremiums.tpl b/templates/CRM/Contribute/Page/ManagePremiums.tpl index 9760a62a99..e73c541c65 100644 --- a/templates/CRM/Contribute/Page/ManagePremiums.tpl +++ b/templates/CRM/Contribute/Page/ManagePremiums.tpl @@ -43,13 +43,13 @@ {foreach from=$rows item=row} - - {$row.name} - {$row.sku} + + {$row.name|escape} + {$row.sku|escape} {$row.price|crmMoney} {$row.min_contribution|crmMoney} {$row.cost|crmMoney} - {$row.financial_type} + {$row.financial_type|escape} {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {$row.action|smarty:nodefaults|replace:'xx':$row.id} diff --git a/templates/CRM/Contribute/Page/Premium.tpl b/templates/CRM/Contribute/Page/Premium.tpl index 377ff12a2f..2899564840 100644 --- a/templates/CRM/Contribute/Page/Premium.tpl +++ b/templates/CRM/Contribute/Page/Premium.tpl @@ -28,14 +28,14 @@ {foreach from=$rows item=row} - {$row.product_name} - {$row.sku} + {$row.product_name|escape} + {$row.sku|escape} {$row.price|crmMoney} {$row.min_contribution|crmMoney} {$row.cost|crmMoney} - {$row.financial_type} + {$row.financial_type|escape} {$row.weight|smarty:nodefaults} - {$row.action} + {$row.action|smarty:nodefaults} {/foreach}