/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['mosaico_msg_template'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
static function copyTemplate() { $msgTplId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); $mosaicoMsgTplId = CRM_Mosaico_Utils::getMosaicoMsgTplIdFromMsgTplId($msgTplId); // get the message template which is going to be copied. $messageTemplate = new CRM_Core_DAO_MessageTemplate(); $messageTemplate->id = $msgTplId; if ($messageTemplate->find(TRUE)) { $buildNewMsgTemplate = array(); $buildNewMsgTemplate['msg_title'] = 'Copy of ' . $messageTemplate->msg_title; $buildNewMsgTemplate['msg_subject'] = 'Copy of ' . $messageTemplate->msg_subject; $buildNewMsgTemplate['msg_html'] = $messageTemplate->msg_html; $newMessageTemplate = new CRM_Core_DAO_MessageTemplate(); $newMessageTemplate->copyValues($buildNewMsgTemplate); $newMessageTemplate->save(); $copiedMsgTplId = $newMessageTemplate->id; $copiedMsgTplName = $newMessageTemplate->msg_title; // Build mosaico message template params to create new mosaico msg template $mosaicoTemplate = CRM_Mosaico_Utils::getMosaicoMsgTemplate($mosaicoMsgTplId); $mosaicoTemplate['msg_tpl_id'] = $copiedMsgTplId; $mosaicoTemplate['name'] = $copiedMsgTplName; $mosTpl = new CRM_Mosaico_DAO_MessageTemplate(); $mosTpl->copyValues($mosaicoTemplate); $mosTpl->save(); $result = array('newMosaicoTplId' => $mosTpl->id, 'from_hash_key' => $mosTpl->hash_key, 'name' => $mosTpl->name); CRM_Utils_JSON::output($result); } }