Exemplo n.º 1
0
 /**
  * Returns a template with the specified id or default template
  * if the template does not exist.
  * @param int id of the template to retrieve
  * @param bool defines whether the function should return the
  *        default template if it cannot find a template with the
  *        specified id
  * @return template object or NULL
  */
 public static function getTemplate($id, $fallback = TRUE)
 {
     $id = empty($id) ? -1 : $id;
     $params = array('id' => $id);
     $template = CRM_Core_BAO_MessageTemplate::retrieve($params, $_);
     if (!$template && $fallback) {
         // fallback to default
         return CRM_Donrec_Logic_Template::getDefaultTemplate();
     }
     return new self($template);
 }
Exemplo n.º 2
0
 /**
  * Make sure all the data structures are there when the module is enabled
  */
 public function enable()
 {
     // create snapshot database tables
     $this->executeSqlFile('sql/donrec.sql', true);
     // create/update custom groups
     CRM_Donrec_DataStructure::update();
     // rename the custom fields according to l10.
     // FIXME: this is a workaround: if you do this before, the table name change,
     //         BUT we should not be working with static table names
     CRM_Donrec_DataStructure::translateCustomGroups();
     // make sure the template is there
     CRM_Donrec_Logic_Template::getDefaultTemplateID();
 }
Exemplo n.º 3
0
 /**
  * get all eligable(?) templates
  *
  * @return array
  */
 public static function getAllTemplates()
 {
     $relevant_templates = array();
     $all_templates = civicrm_api3('MessageTemplate', 'get', array('is_active' => 1, 'option.limit' => 9999));
     foreach ($all_templates['values'] as $template) {
         // TODO: filter?
         $relevant_templates[$template['id']] = $template['msg_title'];
     }
     // add default, if not yet in there
     $default_template_id = CRM_Donrec_Logic_Template::getDefaultTemplateID();
     if (!empty($default_template_id) && empty($relevant_templates[$default_template_id])) {
         $default_template = civicrm_api3('MessageTemplate', 'getsingle', array('id' => $default_template_id));
         $relevant_templates[$default_template_id] = $default_template['msg_title'];
     }
     return $relevant_templates;
 }
Exemplo n.º 4
0
 /**
  * Test template pdf generator with invalid variables
  *
  * @author niko bochan
  */
 public function testTemplateCreateWithInvalid()
 {
     $templates = CRM_Donrec_Logic_Template::findAllTemplates();
     $this->assertNotNULL($templates, "No template found!");
     $values = array('contributor' => 'TEST CONTRIBUTOR', 'total' => 100, 'total_text' => 'ein hundert Euro');
     $params = array();
     foreach ($templates as $key => $value) {
         $t = CRM_Donrec_Logic_Template::create($key);
         $this->assertNotNULL($t);
         foreach ($values as $k => $v) {
             $values_copy = $values;
             unset($values_copy[$k]);
             $result = $t->generatePDF($values_copy, $params);
             // check result
             $failed = !$result && !empty($params['is_error']);
             $error_msg = empty($params['is_error']) ? '' : $params['is_error'];
             $this->assertEquals(FALSE, $failed, sprintf('PDF creation failed: %s', $error_msg));
             $this->assertEquals(TRUE, $result);
             $this->assertEquals(TRUE, file_exists($result));
             // delete pdf
             $this->assertEquals(TRUE, unlink($result));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * create a default profile data
  */
 public static function defaultProfileData()
 {
     return array('financial_types' => self::getAllDeductibleFinancialTypes(), 'store_original_pdf' => FALSE, 'template' => CRM_Donrec_Logic_Template::getDefaultTemplateID(), 'draft_text' => ts('DRAFT', array('domain' => 'de.systopia.donrec')), 'copy_text' => ts('COPY', array('domain' => 'de.systopia.donrec')), 'id_pattern' => '{issue_year}-{serial}', 'legal_address' => array('0'), 'postal_address' => array('0'), 'legal_address_fallback' => array('0'), 'postal_address_fallback' => array('0'));
 }