Skip to content

Commit

Permalink
refs #41211, centralize pcp image url fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Aug 15, 2024
1 parent bd515e1 commit 661bb71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions CRM/Contribute/BAO/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,23 @@ static function getPcpContributionPageTitle($pcpId) {
return CRM_Core_DAO::singleValueQuery($query, $params);
}

/**
* Get image urls
*
* @param int $pcpId
* @return array
*/
public static function getPcpImages($pcpId) {
$dao = CRM_Core_DAO::executeQuery("SELECT file_id FROM civicrm_entity_file WHERE entity_table = 'civicrm_pcp' AND entity_id = %1", array(
1 => array($pcpId, 'Integer'),
));
$files = array();
while($dao->fetch()) {
$files[] = CRM_Core_BAO_File::url($dao->file_id, $pcpId, 'civicrm_pcp');
}
return $files;
}

/**
* Function to get pcp block & entity id given pcp id
*
Expand Down
6 changes: 4 additions & 2 deletions CRM/Contribute/Page/PCPInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ function run() {

$honor = CRM_Contribute_BAO_PCP::honorRoll($this->_id);

if ($file_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $this->_id, 'file_id', 'entity_id')) {
list($src) = CRM_Core_BAO_File::url($file_id, $this->_id, 'civicrm_pcp');
$images = CRM_Contribute_BAO_PCP::getPcpImages($this->_id);
if (!empty($images)) {
$img = reset($images);
$src = $img[0];
if ($src) {
$bgFile = basename($src);
$encodedSrc = str_replace($bgFile, urlencode($bgFile), $src);
Expand Down

0 comments on commit 661bb71

Please sign in to comment.