Skip to content

Commit

Permalink
Merge pull request #609 from colemanw/baseOptions
Browse files Browse the repository at this point in the history
Add pseudoconstant for base template and regenerate DAOs
  • Loading branch information
mattwire authored Aug 24, 2023
2 parents bb7f1d6 + 54c093a commit 5b9ac20
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 98 deletions.
40 changes: 20 additions & 20 deletions CRM/Mosaico/BAO/MosaicoTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

class CRM_Mosaico_BAO_MosaicoTemplate extends CRM_Mosaico_DAO_MosaicoTemplate {

/**
* Create a new MosaicoTemplate based on array-data
*
* @param array $params key-value pairs
* @return CRM_Mosaico_DAO_MosaicoTemplate|NULL
*
public static function create($params) {
$className = 'CRM_Mosaico_DAO_MosaicoTemplate';
$entityName = 'MosaicoTemplate';
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
$instance = new $className();
$instance->copyValues($params);
$instance->save();
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
return $instance;
} */

/**
* Helps updating the URLs in templates so they can be reused
* after restoring a dump database in a new server.
Expand Down Expand Up @@ -158,4 +138,24 @@ public static function findBaseTemplates($ignoreCache = FALSE, $dispatchHooks =
return Civi::$statics[__CLASS__]['bases'];
}

public static function getBaseTemplateOptions(): array {
$suffixMap = [
'id' => 'name',
'name' => 'name',
'label' => 'title',
'url' => 'thumbnail',
];
$options = [];
foreach (self::findBaseTemplates() as $template) {
$option = [];
if (empty($template['is_hidden'])) {
foreach ($suffixMap as $suffix => $key) {
$option[$suffix] = $template[$key];
}
$options[] = $option;
}
}
return $options;
}

}
69 changes: 63 additions & 6 deletions CRM/Mosaico/DAO/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from uk.co.vedaconsulting.mosaico/xml/schema/CRM/Mosaico/MessageTemplate.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:295340b4f197a752729e0cbd22579979)
* (GenCodeChecksum:c3ea3729ff2c5399cdaffa9045c47aaa)
*/
use CRM_Mosaico_ExtensionUtil as E;

Expand Down Expand Up @@ -34,47 +34,61 @@ class CRM_Mosaico_DAO_MessageTemplate extends CRM_Core_DAO {
/**
* Unique Settings ID
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $id;

/**
* FK to civicrm_msg_template.
*
* @var int
* @var int|string
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $msg_tpl_id;

/**
* @var string
* (SQL type: varchar(32))
* Note that values will be retrieved from the database as a string.
*/
public $hash_key;

/**
* name
*
* @var string
* (SQL type: varchar(32))
* Note that values will be retrieved from the database as a string.
*/
public $name;

/**
* HTML
*
* @var longtext
* @var string
* (SQL type: longtext)
* Note that values will be retrieved from the database as a string.
*/
public $html;

/**
* metadata
*
* @var longtext
* @var string
* (SQL type: longtext)
* Note that values will be retrieved from the database as a string.
*/
public $metadata;

/**
* template
*
* @var longtext
* @var string
* (SQL type: longtext)
* Note that values will be retrieved from the database as a string.
*/
public $template;

Expand Down Expand Up @@ -122,8 +136,15 @@ public static function &fields() {
'id' => [
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => E::ts('ID'),
'description' => E::ts('Unique Settings ID'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.id',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -138,6 +159,12 @@ public static function &fields() {
'title' => E::ts('message template ID'),
'description' => E::ts('FK to civicrm_msg_template.'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.msg_tpl_id',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -161,6 +188,12 @@ public static function &fields() {
'required' => TRUE,
'maxlength' => 32,
'size' => CRM_Utils_Type::MEDIUM,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.hash_key',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -176,6 +209,12 @@ public static function &fields() {
'required' => TRUE,
'maxlength' => 32,
'size' => CRM_Utils_Type::MEDIUM,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.name',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -189,6 +228,12 @@ public static function &fields() {
'title' => E::ts('HTML'),
'description' => E::ts('HTML'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.html',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -205,6 +250,12 @@ public static function &fields() {
'title' => E::ts('metadata'),
'description' => E::ts('metadata'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.metadata',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand All @@ -221,6 +272,12 @@ public static function &fields() {
'title' => E::ts('template'),
'description' => E::ts('template'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_mosaico_msg_template.template',
'table_name' => 'civicrm_mosaico_msg_template',
'entity' => 'MessageTemplate',
Expand Down
Loading

0 comments on commit 5b9ac20

Please sign in to comment.