2009-07-01 04:24:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Model template file.
|
|
|
|
*
|
|
|
|
* Used by bake to create new Model files.
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-07-01 04:24:20 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-07-01 04:24:20 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-10-15 18:26:48 +00:00
|
|
|
* @package Cake.Console.Templates.default.classes
|
2009-07-01 04:24:20 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-07-01 04:24:20 +00:00
|
|
|
*/
|
|
|
|
|
2011-09-10 00:32:01 +00:00
|
|
|
echo "<?php\n";
|
|
|
|
echo "App::uses('{$plugin}AppModel', '{$pluginPath}Model');\n";
|
|
|
|
?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* <?php echo $name ?> Model
|
|
|
|
*
|
2011-08-01 00:28:35 +00:00
|
|
|
<?php
|
|
|
|
foreach (array('hasOne', 'belongsTo', 'hasMany', 'hasAndBelongsToMany') as $assocType) {
|
|
|
|
if (!empty($associations[$assocType])) {
|
|
|
|
foreach ($associations[$assocType] as $relation) {
|
|
|
|
echo " * @property {$relation['className']} \${$relation['alias']}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
2011-01-20 00:22:50 +00:00
|
|
|
*/
|
2009-07-01 04:24:20 +00:00
|
|
|
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
|
2012-04-30 14:44:46 +00:00
|
|
|
|
2013-02-12 02:38:08 +00:00
|
|
|
<?php if ($useDbConfig !== 'default'): ?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* Use database config
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public $useDbConfig = '<?php echo $useDbConfig; ?>';
|
2012-04-30 14:44:46 +00:00
|
|
|
|
2012-05-09 22:35:51 +00:00
|
|
|
<?php endif;
|
|
|
|
|
|
|
|
if ($useTable && $useTable !== Inflector::tableize($name)):
|
2012-07-18 01:24:55 +00:00
|
|
|
$table = "'$useTable'";
|
|
|
|
echo "/**\n * Use table\n *\n * @var mixed False or table name\n */\n";
|
|
|
|
echo "\tpublic \$useTable = $table;\n\n";
|
2009-07-01 04:24:20 +00:00
|
|
|
endif;
|
2012-05-09 22:35:51 +00:00
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
if ($primaryKey !== 'id'): ?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* Primary key field
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public $primaryKey = '<?php echo $primaryKey; ?>';
|
2012-04-30 14:44:46 +00:00
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php endif;
|
2012-05-09 22:35:51 +00:00
|
|
|
|
2009-07-09 02:06:42 +00:00
|
|
|
if ($displayField): ?>
|
2011-01-20 00:22:50 +00:00
|
|
|
/**
|
|
|
|
* Display field
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:46:01 +00:00
|
|
|
public $displayField = '<?php echo $displayField; ?>';
|
2012-04-30 14:44:46 +00:00
|
|
|
|
2009-07-09 02:06:42 +00:00
|
|
|
<?php endif;
|
2009-07-01 04:24:20 +00:00
|
|
|
|
2013-03-15 11:14:06 +00:00
|
|
|
if (!empty($actsAs)): ?>
|
|
|
|
/**
|
|
|
|
* Behaviors
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $actsAs = array(<?php echo "\n\t"; foreach ($actsAs as $behavior): echo "\t"; var_export($behavior); echo ",\n\t"; endforeach; ?>);
|
|
|
|
|
|
|
|
<?php endif;
|
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
if (!empty($validate)):
|
2011-01-20 00:22:50 +00:00
|
|
|
echo "/**\n * Validation rules\n *\n * @var array\n */\n";
|
2010-04-04 06:46:01 +00:00
|
|
|
echo "\tpublic \$validate = array(\n";
|
2009-07-01 04:24:20 +00:00
|
|
|
foreach ($validate as $field => $validations):
|
|
|
|
echo "\t\t'$field' => array(\n";
|
|
|
|
foreach ($validations as $key => $validator):
|
2010-01-01 06:28:05 +00:00
|
|
|
echo "\t\t\t'$key' => array(\n";
|
|
|
|
echo "\t\t\t\t'rule' => array('$validator'),\n";
|
|
|
|
echo "\t\t\t\t//'message' => 'Your custom message here',\n";
|
|
|
|
echo "\t\t\t\t//'allowEmpty' => false,\n";
|
|
|
|
echo "\t\t\t\t//'required' => false,\n";
|
|
|
|
echo "\t\t\t\t//'last' => false, // Stop validation after this rule\n";
|
|
|
|
echo "\t\t\t\t//'on' => 'create', // Limit validation to 'create' or 'update' operations\n";
|
|
|
|
echo "\t\t\t),\n";
|
2009-07-01 04:24:20 +00:00
|
|
|
endforeach;
|
|
|
|
echo "\t\t),\n";
|
|
|
|
endforeach;
|
|
|
|
echo "\t);\n";
|
|
|
|
endif;
|
|
|
|
|
2010-02-25 03:23:09 +00:00
|
|
|
foreach ($associations as $assoc):
|
|
|
|
if (!empty($assoc)):
|
2009-07-01 04:24:20 +00:00
|
|
|
?>
|
2011-01-20 00:22:50 +00:00
|
|
|
|
2015-09-25 15:11:20 +00:00
|
|
|
// The Associations below have been created with all possible keys, those that are not needed can be removed
|
2009-07-01 04:24:20 +00:00
|
|
|
<?php
|
2010-02-25 03:23:09 +00:00
|
|
|
break;
|
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
foreach (array('hasOne', 'belongsTo') as $assocType):
|
|
|
|
if (!empty($associations[$assocType])):
|
|
|
|
$typeCount = count($associations[$assocType]);
|
2011-01-20 00:22:50 +00:00
|
|
|
echo "\n/**\n * $assocType associations\n *\n * @var array\n */";
|
2010-04-04 06:46:01 +00:00
|
|
|
echo "\n\tpublic \$$assocType = array(";
|
2009-07-01 04:24:20 +00:00
|
|
|
foreach ($associations[$assocType] as $i => $relation):
|
|
|
|
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
|
|
|
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
|
|
|
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
|
|
|
$out .= "\t\t\t'conditions' => '',\n";
|
|
|
|
$out .= "\t\t\t'fields' => '',\n";
|
|
|
|
$out .= "\t\t\t'order' => ''\n";
|
|
|
|
$out .= "\t\t)";
|
|
|
|
if ($i + 1 < $typeCount) {
|
|
|
|
$out .= ",";
|
|
|
|
}
|
|
|
|
echo $out;
|
|
|
|
endforeach;
|
|
|
|
echo "\n\t);\n";
|
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
|
|
|
|
if (!empty($associations['hasMany'])):
|
|
|
|
$belongsToCount = count($associations['hasMany']);
|
2011-01-20 00:22:50 +00:00
|
|
|
echo "\n/**\n * hasMany associations\n *\n * @var array\n */";
|
2010-04-04 06:46:01 +00:00
|
|
|
echo "\n\tpublic \$hasMany = array(";
|
2009-07-01 04:24:20 +00:00
|
|
|
foreach ($associations['hasMany'] as $i => $relation):
|
|
|
|
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
|
|
|
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
|
|
|
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
|
|
|
$out .= "\t\t\t'dependent' => false,\n";
|
|
|
|
$out .= "\t\t\t'conditions' => '',\n";
|
|
|
|
$out .= "\t\t\t'fields' => '',\n";
|
|
|
|
$out .= "\t\t\t'order' => '',\n";
|
|
|
|
$out .= "\t\t\t'limit' => '',\n";
|
|
|
|
$out .= "\t\t\t'offset' => '',\n";
|
|
|
|
$out .= "\t\t\t'exclusive' => '',\n";
|
|
|
|
$out .= "\t\t\t'finderQuery' => '',\n";
|
|
|
|
$out .= "\t\t\t'counterQuery' => ''\n";
|
|
|
|
$out .= "\t\t)";
|
|
|
|
if ($i + 1 < $belongsToCount) {
|
|
|
|
$out .= ",";
|
|
|
|
}
|
|
|
|
echo $out;
|
|
|
|
endforeach;
|
|
|
|
echo "\n\t);\n\n";
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if (!empty($associations['hasAndBelongsToMany'])):
|
|
|
|
$habtmCount = count($associations['hasAndBelongsToMany']);
|
2011-01-20 00:22:50 +00:00
|
|
|
echo "\n/**\n * hasAndBelongsToMany associations\n *\n * @var array\n */";
|
2010-04-04 06:46:01 +00:00
|
|
|
echo "\n\tpublic \$hasAndBelongsToMany = array(";
|
2009-07-01 04:24:20 +00:00
|
|
|
foreach ($associations['hasAndBelongsToMany'] as $i => $relation):
|
|
|
|
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
|
|
|
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
|
|
|
$out .= "\t\t\t'joinTable' => '{$relation['joinTable']}',\n";
|
|
|
|
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
|
|
|
$out .= "\t\t\t'associationForeignKey' => '{$relation['associationForeignKey']}',\n";
|
2011-05-23 06:50:59 +00:00
|
|
|
$out .= "\t\t\t'unique' => 'keepExisting',\n";
|
2009-07-01 04:24:20 +00:00
|
|
|
$out .= "\t\t\t'conditions' => '',\n";
|
|
|
|
$out .= "\t\t\t'fields' => '',\n";
|
|
|
|
$out .= "\t\t\t'order' => '',\n";
|
|
|
|
$out .= "\t\t\t'limit' => '',\n";
|
|
|
|
$out .= "\t\t\t'offset' => '',\n";
|
|
|
|
$out .= "\t\t\t'finderQuery' => '',\n";
|
|
|
|
$out .= "\t\t)";
|
|
|
|
if ($i + 1 < $habtmCount) {
|
|
|
|
$out .= ",";
|
|
|
|
}
|
|
|
|
echo $out;
|
|
|
|
endforeach;
|
|
|
|
echo "\n\t);\n\n";
|
|
|
|
endif;
|
|
|
|
?>
|
|
|
|
}
|