summaryrefslogtreecommitdiff
path: root/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp')
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp127
1 files changed, 127 insertions, 0 deletions
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp
new file mode 100644
index 0000000..5d1cb28
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp
@@ -0,0 +1,127 @@
+<%
+/**
+ * Copyright 2016 Ludovic Pouzenc <ludovic@pouzenc.fr>
+ * Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr>
+ *
+ * This file is part of CHD Gestion.
+ *
+ * CHD Gestion is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CHD Gestion is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CHD Gestion. If not, see <http://www.gnu.org/licenses/>.
+**/
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @since 0.1.0
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+use Cake\Utility\Inflector;
+$title = $this->BakeExtra->getTitleOpts(Inflector::camelize($table));
+
+$propertyHintMap = null;
+if (!empty($propertySchema)) {
+ $propertyHintMap = $this->DocBlock->buildEntityPropertyHintTypeMap($propertySchema);
+}
+
+$accessible = [];
+if (!isset($fields) || $fields !== false) {
+ if (!empty($fields)) {
+ foreach ($fields as $field) {
+ $accessible[$field] = 'true';
+ }
+ } elseif (!empty($primaryKey)) {
+ $accessible['*'] = 'true';
+ foreach ($primaryKey as $field) {
+ $accessible[$field] = 'false';
+ }
+ }
+}
+%>
+<?php
+namespace <%= $namespace %>\Model\Entity;
+
+use Cake\ORM\Entity;
+
+/**
+ * <%= $name %> Entity.
+<% if ($propertyHintMap): %>
+ *
+<% foreach ($propertyHintMap as $property => $type): %>
+<% if ($type): %>
+ * @property <%= $type %> $<%= $property %>
+<% else: %>
+ * @property $<%= $property %>
+<% endif; %>
+<% endforeach; %>
+<% endif; %>
+ */
+class <%= $name %> extends Entity
+{
+<% if (!empty($accessible)): %>
+
+ /**
+ * Fields that can be mass assigned using newEntity() or patchEntity().
+ *
+ * Note that when '*' is set to true, this allows all unspecified fields to
+ * be mass assigned. For security purposes, it is advised to set '*' to false
+ * (or remove it), and explicitly make individual fields accessible as needed.
+ *
+ * @var array
+ */
+ protected $_accessible = [
+<% foreach ($accessible as $field => $value): %>
+ '<%= $field %>' => <%= $value %>,
+<% endforeach; %>
+ ];
+<% endif %>
+<% if (!empty($hidden)): %>
+
+ /**
+ * Fields that are excluded from JSON an array versions of the entity.
+ *
+ * @var array
+ */
+ protected $_hidden = [<%= $this->Bake->stringifyList($hidden) %>];
+<% endif %>
+<% if (!empty($title)): %>
+
+ /**
+ * Virtual field for pretty print in related table's views
+ *
+ * @return String
+ */
+ protected function _getTitle()
+ {
+<% if (array_key_exists('custom_code', $title)) {
+ echo "return " . $title['custom_code'] . ";\n";
+ } else {
+ echo "return implode('" . $title['glue'] . "', array_filter([\n";
+ if (array_key_exists('prefix', $title)) {
+ echo "\t\t\t'" . $title['prefix'] . "',\n";
+ }
+ foreach ($title['pieces'] as $piece) {
+ echo "\t\t\t\$this->_properties['" . $piece . "'],\n";
+ }
+ echo "], 'strlen'));\n";
+ }
+%>
+ }
+<% endif; %>
+}