{# /** * 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 2.0.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #} {% set annotations = DocBlock.buildTableAnnotations(associations, associationInfo, behaviors, entity, namespace) %} * Copyright 2016 Nicolas Goaziou * * This file is part of FAI Gestion forked from CHD Gestion. * * FAI 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. * * FAI 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 FAI Gestion. If not, see . * * Auto-generated code with CakePHP(tm) bake derived code. **/ namespace {{ namespace }}\Model\Table; {% set uses = ['use Cake\\ORM\\Query;', 'use Cake\\ORM\\RulesChecker;', 'use Cake\\ORM\\Table;', 'use Cake\\Validation\\Validator;'] %} {%- if BakeExtra.hasOrderOpts(name) or BakeExtra.hasOrderHooks(name) %} {% set uses = uses|merge(['use ArrayObject;', 'use Cake\\Event\\Event;']) %} {% endif %} {{ uses|join('\n')|raw }} {{ DocBlock.classDescription(name, 'Model', annotations)|raw }} class {{ name }}Table extends Table { /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ public function initialize(array $config) { parent::initialize($config); {% if table %} $this->setTable('{{ table }}'); {% endif %} {%- if displayField %} $this->setDisplayField('{{ displayField }}'); {% endif %} {%- if primaryKey %} {%- if primaryKey is iterable and primaryKey|length > 1 %} $this->setPrimaryKey([{{ Bake.stringifyList(primaryKey, {'indent': false})|raw }}]); {{- "\n" }} {%- else %} $this->setPrimaryKey('{{ primaryKey|as_array|first }}'); {{- "\n" }} {%- endif %} {% endif %} {%- if behaviors %} {% endif %} {%- for behavior, behaviorData in behaviors %} $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", [" ~ Bake.stringifyList(behaviorData, {'indent': 3, 'quotes': false})|raw ~ ']') : '')|raw }}); {% endfor %} {%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %} {% endif %} {%- for type, assocs in associations %} {%- for assoc in assocs %} {%- set assocData = [] %} {%- for key, val in assoc if key is not same as('alias') %} {%- set assocData = assocData|merge({(key): val}) %} {%- endfor %} $this->{{ type }}('{{ assoc.alias }}', [{{ Bake.stringifyList(assocData, {'indent': 3})|raw }}]); {{- "\n" }} {%- endfor %} {% endfor %} } {{- "\n" }} {%- if validation %} /** * Default validation rules. * * @param \Cake\Validation\Validator $validator Validator instance. * @return \Cake\Validation\Validator */ public function validationDefault(Validator $validator) { {% for field, rules in validation %} {% set validationMethods = Bake.getValidationMethods(field, rules) %} {% if validationMethods %} $validator {% for validationMethod in validationMethods %} {% if loop.last %} {% set validationMethod = validationMethod ~ ';' %} {% endif %} {{ validationMethod|raw }} {% endfor %} {% endif %} {% endfor %} return $validator; } {% endif %} {%- if rulesChecker %} /** * Returns a rules checker object that will be used for validating * application integrity. * * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. * @return \Cake\ORM\RulesChecker */ public function buildRules(RulesChecker $rules) { {% for field, rule in rulesChecker %} $rules->add($rules->{{ rule.name }}(['{{ field }}']{{ (rule.extra is defined and rule.extra ? (", '#{rule.extra}'") : '')|raw }})); {% endfor %} return $rules; } {% endif %} {%- if connection is not same as('default') %} /** * Returns the database connection name to use by default. * * @return string */ public static function defaultConnectionName() { return '{{ connection }}'; } {% endif %} {%- if BakeExtra.hasFilters(name) %} /** * @return \Search\Manager */ public function searchManager() { $searchManager = $this->behaviors()->Search->searchManager(); {% for k, filter in BakeExtra.getFilters(name) %} $searchManager->{{ filter.mode }}('{{ k }}', [ {{- BakeExtra.stringifySearchManagerConfig(filter)|raw -}} ]); {% endfor %} return $searchManager; } {% endif %} {%- if BakeExtra.hasOrderOpts(name) or BakeExtra.hasOrderHooks(name) %} /** * @return \Cake\ORM\Query */ public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) { {% if BakeExtra.hasOrderOpts(name) %} $order = $query->clause('order'); if ($order === null || !count($order)) { {% if BakeExtra.hasOrderContains(name) %} $query->contain([ {{- Bake.stringifyList(BakeExtra.getOrderContains(name), {'indent': 4})|raw -}} ]); {% endif %} $query->order([ {{- Bake.stringifyList(BakeExtra.getOrderOpts(name), {'indent': 4})|raw -}} ]); } {% endif %} {%- if BakeExtra.hasOrderHooks(name) %} $orderHooks = [ {{- Bake.stringifyList(BakeExtra.getOrderHooks(name), {'indent': 3})|raw -}} ]; $order = $query->clause('order'); if ($order !== null && count($order)) { $order->iterateParts(function ($rhs, &$lhs) use ($orderHooks) { if ( array_key_exists($lhs, $orderHooks) ) { $lhs = $orderHooks[$lhs]; } return $rhs; }); } {% endif %} } {% endif %} }