Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Template.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
22  public function __construct(
23  \Magento\Framework\Model\ResourceModel\Db\Context $context,
24  $connectionName = null
25  ) {
26  parent::__construct($context, $connectionName);
27  }
28 
34  protected function _construct()
35  {
36  $this->_init('email_template', 'template_id');
37  }
38 
45  public function checkCodeUsage(\Magento\Email\Model\Template $template)
46  {
47  if ($template->getTemplateActual() != 0 || $template->getTemplateActual() === null) {
48  $select = $this->getConnection()->select()->from(
49  $this->getMainTable(),
50  'COUNT(*)'
51  )->where(
52  'template_code = :template_code'
53  );
54  $bind = ['template_code' => $template->getTemplateCode()];
55 
56  $templateId = $template->getId();
57  if ($templateId) {
58  $select->where('template_id != :template_id');
59  $bind['template_id'] = $templateId;
60  }
61 
62  $result = $this->getConnection()->fetchOne($select, $bind);
63  if ($result) {
64  return true;
65  }
66  }
67  return false;
68  }
69 
76  protected function _beforeSave(AbstractModel $object)
77  {
78  $object->setTemplateType((int)$object->getTemplateType());
79  return parent::_beforeSave($object);
80  }
81 
90  {
91  $orWhere = [];
92  $pathsCounter = 1;
93  $bind = [];
94  foreach ($paths as $path) {
95  $pathAlias = 'path_' . $pathsCounter;
96  $orWhere[] = 'path = :' . $pathAlias;
97  $bind[$pathAlias] = $path;
98  $pathsCounter++;
99  }
100  $bind['template_id'] = $templateId;
101  $select = $this->getConnection()->select()->from(
102  $this->getTable('core_config_data'),
103  ['scope', 'scope_id', 'path']
104  )->where(
105  'value LIKE :template_id'
106  )->where(
107  join(' OR ', $orWhere)
108  );
109 
110  return $this->getConnection()->fetchAll($select, $bind);
111  }
112 }
$templateId
Definition: queue.php:15
_beforeSave(AbstractModel $object)
Definition: Template.php:76
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, $connectionName=null)
Definition: Template.php:22
getSystemConfigByPathsAndTemplateId($paths, $templateId)
Definition: Template.php:89
$paths
Definition: _bootstrap.php:83
checkCodeUsage(\Magento\Email\Model\Template $template)
Definition: Template.php:45
$template
Definition: export.php:12