Skip to content

Commit

Permalink
CiviGrant PDF Letters
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaphoneJon committed Jun 4, 2024
1 parent 5306c89 commit d42d511
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ext/civigrant/CRM/Grant/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Grant;

/**
* Class for grant form task actions.
* FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
Expand Down Expand Up @@ -111,4 +113,36 @@ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back'
]);
}

/**
* Get the rows form the search, keyed to make the token processor happy.
*
* @throws \CRM_Core_Exception
*/
protected function getRows(): array {
if (empty($this->rows)) {
// checkPermissions set to false - in case form is bypassing in some way.
$grants = Grant::get(FALSE)
->addWhere('id', 'IN', $this->_grantIds)
->setSelect(['id', 'contact_id'])->execute();
foreach ($grants as $grant) {
$this->rows[] = [
'contact_id' => $grant['contact_id'],
'grant_id' => $grant['id'],
'schema' => [
'contactId' => $grant['contact_id'],
'grantId' => $grant['id'],
],
];
}
}
return $this->rows;
}

/**
* Get the token processor schema required to list any tokens for this task.
*/
public function getTokenSchema(): array {
return ['grantId', 'contactId'];
}

}
55 changes: 55 additions & 0 deletions ext/civigrant/CRM/Grant/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* This class provides the functionality to create PDF letter for grants.
*/
class CRM_Grant_Form_Task_PDF extends CRM_Grant_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* All the existing templates in the system.
*
* @var array
*/
public $_templates = NULL;

public $_single = NULL;

public $_cid = NULL;

/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->preProcessPDF();
parent::preProcess();
$this->setContactIDs();
}

/**
* List available tokens for this form.
*
* @return array
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
return $tokens;
}

}
5 changes: 5 additions & 0 deletions ext/civigrant/CRM/Grant/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public static function tasks() {
'class' => 'CRM_Grant_Form_Task_Update',
'result' => FALSE,
],
self::PDF_LETTER => [
'title' => ts('Print/merge document'),
'class' => 'CRM_Grant_Form_Task_PDF',
'result' => FALSE,
],
];

if (!CRM_Core_Permission::check('delete in CiviGrant')) {
Expand Down
14 changes: 14 additions & 0 deletions ext/civigrant/templates/CRM/Grant/Form/Task/PDF.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
<div class="crm-form-block crm-block crm-contact-task-pdf-form-block">
<div class="messages status no-popup">{include file="CRM/Grant/Form/Task.tpl"}</div>
{include file="CRM/Contact/Form/Task/PDFLetterCommon.tpl"}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>

0 comments on commit d42d511

Please sign in to comment.