1

I have a function that lists score for a dog:

<h3>Your Dog's Scores</h3>
{crmButton href="#" class="button-name" title="Download CSV" icon="icon-class-name"}Download CSV{/crmButton}
<table border='1' cellpadding='5' cellspacing='5'><tr class="crm-entity" id="Scores" style='border-bottom: 1px solid black'><th>Registered Name</th><th>Event</th><th>Level</th><th>Stream</th><th>Score</th><th>Max Points</th><th>Pass</th></td></tr>
{*{crmAPI var='dogs' entity='RegisteredDogs' action='get' contact_id = $contactid} *}
{foreach from=$scores key=arrayIndex item=score}
  <tr>
  <td>{$score->DogName}</td>
  <td>{$score->Event}</td>
  <td>{$score->LevelDescript}</td>
  <td>{$score->Stream}</td>
  <td>{$score->Score}</td>
  <td>{$score->MaxPoints}</td>
  <td>{$score->Pass}</td>
  </tr>
{/foreach} 

</table>

This works really well. The pop-up window shows the scores and lists them out. The issue is I'm being asked if I can export the displayed data as a CSV file. I see on the top bar that there is a 'print' icon - is there a 'Download' option available? My second option was to use a separate button (as you can see the crmButton on the second line).

The array $scores has the results from a SQL query in the PHP (above is the smarty template code).
Is there an easy way to add the csv download option? Can I call a function with the href in the button? Perhaps I just need to write a php function to do this? Any help would be appreciated.

2
  • I'm intrigued by these tests; do the dogs write essays or is it multiple-choice? How do the dogs hold their pencils? And how can you read their handwriting? Or is the test administered via computer? Can the dogs touch-type or is there bark-to-text recognition software? Perhaps you could recruit the dogs with the highest scores to write code for you?
    – Coleman
    Commented Oct 30, 2023 at 19:14
  • 1
    LOL that made my day. We are the largest scent detection association in Canada. We are a non-profit that sanctions sport scent detection events :) So we register dogs and handlers and keep track of their scores, awarding titles when they achieve certain levels. Commented Oct 30, 2023 at 19:28

1 Answer 1

2

I hope I'm not barking up the wrong tree, but could you pawsibly try SearchKit? It's a doggone helpful tool that can render your table without any of that custom Smarty code (which can be ruff to maintain), and it has a built-in "Download Spreadsheet" action to fetch and retrieve CSV, XLSX, or ODS.

Bone Appétit!

5
  • I did look at it but the SQL is too complex for it (I think). It has a couple of joins to other custom entities created by my custom extensions. Commented Oct 30, 2023 at 19:57
  • ... from civicrm_dog_scores inner join civicrm_registered_dogs ON civicrm_dog_scores.DogId = civicrm_registered_dogs.id inner join civicrm_contact ON civicrm_contact.id = civicrm_registered_dogs.contact_id inner join civicrm_trial_levels ON civicrm_dog_scores.Rules = civicrm_trial_levels.Id where DogId=".$this->_id." ORDER by Event Commented Oct 30, 2023 at 19:58
  • I also didn't find a SAVE CSV for the results pulled in from the Search. Commented Oct 30, 2023 at 20:00
  • 1
    If you retrofit xml for those tables then you can generate BAO/DAO and you get all the magic of API4 and SearchKit. docs.civicrm.org/dev/en/latest/framework/database/… docs.civicrm.org/dev/en/latest/extensions/civix/…
    – Aidan
    Commented Oct 30, 2023 at 20:06
  • Right, SearchKit can easily handle a query like that as long as you've got up-to-date metadata describing all the field specs and FKs. The download action is available in the "Actions" dropdown just above the results table in SearchKit.
    – Coleman
    Commented Oct 30, 2023 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.