Commit f63efd96 authored by Jonathan.Wage's avatar Jonathan.Wage

Removed.

parent 0d056d77
Copyright (c) 2004-2006 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfDoctrine symfony plugin
=========================
Overview
--------
The sfDoctrine plugin allows you to totally replace propel with doctrine (http://www.phpdoctrine.com/) which is a powerful and easy-to-use ORM.
Contents
--------
This plugin contains:
- necessary tools to use doctrine: the main tool is sfDoctrine::getTable() which will allow you to send queries
- pake tasks that convert between doctrine and propel schema formats and build doctrine model classes automatically
- an admin generator: to use it just specify sfDoctrineAdmin as the main class in your generator.yml config
You will find more information in the wiki page dedicated to sfDoctrine: http://www.symfony-project.com/trac/wiki/sfDoctrine.
License
-------
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
<?php
/*
* This file is part of the sfDoctrine package.
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony.plugins
* @subpackage sfDoctrine
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: sfDoctrineDatabaseSchema.class.php 3455 2007-02-14 16:17:48Z chtito $
*/
/*
- class: contains a bunch of columns, toMany relationships, inheritance
information, i18n information
- table: a special class that is actually a table
- column: contains the doctrine properties (name, type, size) and the toOne relation information
*/
class sfDoctrineDatabaseSchema
{
// the class descriptions
protected $classes = array();
// a subset of the array above: classes which are also tables
protected $tables = array();
public function getClasses()
{
return $this->classes;
}
protected function getClass($className)
{
if (isset($this->classes[$className]))
return $this->classes[$className];
throw new sfDoctrineSchemaException(sprintf('The class "%s" has no description', $className));
}
// retrieves a class object from its table name
protected function findClassByTableName($tableName)
{
foreach ($this->tables as $table)
if ($table->getName() == $tableName)
{
$tableClasses = $table->getClasses();
if (count($tableClasses) != 1)
throw new sfDoctrineSchemaException(sprintf('No unique class is associated to table "%s"', $tableName));
return array_pop($tableClasses);
}
throw new sfDoctrineSchemaException(sprintf('Table "%s" not found', $tableName));
}
// set the one to many and many to many relationships
// finds out what are the foreign classes or foreign tables
protected function fixRelationships()
{
foreach ($this->classes as $className => $class)
{
foreach ($class->getColumns() as $relCol)
if ($relation = $relCol->getRelation())
{
// if no foreignClass was specified (import from propel) we find it out
if (!$relation->get('foreignClass'))
{
$foreignClass = $this->findClassByTableName($relation->get('foreignTable'));
$relation->set('foreignClass', $foreignClass->getPhpName());
}
// if foreignTable was not set (only used for export to propel)
// we figure it out
if (!$relation->get('foreignTable'))
{
$className = $relation->get('foreignClass');
$relation->set('foreignTable', $this->getClass($className)->getTableName());
}
// the relation is a many2many
if ($relation->get('counterpart'))
{
$counterpartRel = $class->getRelation($relation->get('counterpart'));
$relation->set('otherClass', $counterpartRel->get('foreignClass'));
}
// we copy all the toOne relations to the corresponding
// foreign class
$rel = $relCol->getRelation();
$this->getClass($rel->get('foreignClass'))->addToMany($rel); // FIXME: don't copy here
}
}
}
// exports the current schema as a propel xml file
public function asPropelXml()
{
$xml = new SimpleXmlElement(sprintf('<?xml version="1.0" encoding="UTF-8" ?>
<database name="%s" defaultIdMethod="native"></database>', 'connection'));
foreach ($this->tables as $table)
{
$table->addPropelXmlClasses($xml);
}
return array('source'=>$xml->asXml());
}
// exports the current schema in a sfDoctrine yml file
public function asDoctrineYml()
{
$ymlClasses = array();
foreach ($this->classes as $class)
{
$ymlClasses[$class->getPhpName()] = $class->asDoctrineYml();
}
return array('source'=>sfYaml::dump($ymlClasses));
}
public function debug()
{
$debug = array();
foreach ($this->classes as $class)
{
$debug[$class->getPhpName()] = $class->debug();
}
return $debug;
}
}
class sfDoctrineSchemaException extends sfException
{
public function __construct($message = null, $code = 0)
{
$this->setName('sfDoctrineSchemaException');
parent::__construct($message, $code);
}
}
\ No newline at end of file
<?php
/*
* This file is part of the sfDoctrine package.
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony.plugins
* @subpackage sfDoctrine
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: sfDoctrineRelationSchema.class.php 4705 2007-07-24 20:45:46Z Jonathan.Wage $
*/
class sfDoctrineRelationSchema
{
protected $relationInfo = array();
public function __construct($relationInfo)
{
foreach ($relationInfo as $key => $value)
{
$this->set($key, $value);
}
}
public function set($key, $value)
{
// we set the default foreign name
if ($key == 'foreignClass')
{
if (!isset($this->relationInfo['foreignName']))
{
$this->relationInfo['foreignName'] = $value;
}
}
$this->relationInfo[$key] = $value;
}
public function get($key)
{
if (isset($this->relationInfo[$key]))
{
return $this->relationInfo[$key];
}
else if (isset($this->relationInfo['options']))
{
if ($option = $this->relationInfo['options']->get($key))
{
return $option;
}
}
return null;
}
public function asDoctrineYml()
{
$output = array();
foreach(array('foreignClass', 'foreignReference', 'localName', 'foreignName', 'cascadeDelete', 'unique') as $key)
{
if ($value = $this->get($key))
{
$output[$key] = $value;
}
}
// FIXME: this is clumsy: change the schema syntax?
if ($verb == 'owns')
{
$output['cascadeDelete'] = true;
}
return $output;
}
public function asPhpArray($array)
{
$phpArray = 'array(';
if( !empty($array) )
{
foreach($array AS $key => $value)
{
$phpArray .= "'{$key}' => '{$value}', ";
}
$phpArray = substr($phpArray, 0, strlen($phpArray) - 2);
}
$phpArray .= ')';
return $phpArray;
}
public function asOnePhp()
{
// special behaviour for xref tables with cascade delete
$verb = ($this->get('cascadeDelete') && ($this->get('counterpart') || $this->get('unique'))) ? 'owns' : 'has';
$options['local'] = $this->get('localReference');
$options['foreign'] = $this->get('foreignReference');
//support old and new cascade declarations
if ($verb == 'owns' || $this->get('cascadeDelete') === true)
{
$options['onDelete'] = 'CASCADE';
}
if ($this->get('onDelete'))
{
$options['onDelete'] = strtoupper($this->get('onDelete'));
}
$phpOptions = $this->asPhpArray($options);
return "\$this->$verb"."One('{$this->get('foreignClass')} as {$this->get('foreignName')}', $phpOptions);";
}
public function asManyPhp()
{
$quantity = $this->get('unique') ? 'One':'Many';
// using "owns" for cascade delete except in xref table
$verb = ($this->get('cascadeDelete') && !$this->get('counterpart')) ? 'has':'has';
$otherClass = $this->get('localClass');
if ($quantity == 'Many' && $this->get('counterpart'))
{
$localReference = $this->relationInfo['localReference'];
$foreignReference = $this->relationInfo['options']->get('counterpart');
$otherClass = $this->get('otherClass');
} else {
$localReference = $this->get('foreignReference');
$foreignReference = $this->get('localReference');
}
$localClass = $this->get('localClass');
// Set refClass to localClass if it is a Many-Many relationship
if ($quantity == 'Many' && $this->get('counterpart'))
{
$refClass = $this->get('localClass');
}
if (isset($refClass) && $refClass)
{
$options['refClass'] = $refClass;
}
if ($localReference)
{
$options['local'] = $localReference;
}
if ($foreignReference)
{
$options['foreign'] = $foreignReference;
}
$phpOptions = $this->asPhpArray($options);
return "\$this->$verb$quantity('$otherClass as {$this->get('localName')}', $phpOptions);";
}
public function debug()
{
return $this->relationInfo;
}
}
\ No newline at end of file
<?php
/*
* This file is part of the sfDoctrine package.
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony.plugins
* @subpackage sfDoctrine
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: sfDoctrineSchemaDoctrineLoader.class.php 3455 2007-02-14 16:17:48Z chtito $
*/
class sfDoctrineSchemaDoctrineLoader extends sfDoctrineDatabaseSchema
{
// recursively finds out what a class table is
// FIXME: check for infinite loop?
protected function parentTable($class)
{
if ($class->hasTable())
return $class->getTable();
return $this->parentTable($this->getClass($class->getParentClassName()));
}
// associate a table to each class
protected function fixTables()
{
foreach ($this->classes as $className => $class)
{
$table = $this->parentTable($class);
$table->addClass($class);
}
}
// set up the necessary fields in the i18n table: culture, id
protected function addI18nFields()
{
foreach ($this->classes as $className => $class)
{
if (!$class->hasI18n())
continue;
$i18nClass = $this->getClass($class->getI18n('class'));
$cultureColumn = new sfDoctrineColumnSchema($class->getI18n('cultureField'), array('type'=> 'string', 'size'=> 100, 'primary'=> true));
$i18nClass->addColumn($cultureColumn);
// add the foreign key to the main table
$idDesc = array('foreignClass'=>$className, 'localName'=>$i18nClass->getPhpName(), 'onDelete'=>'cascade', 'primary'=>true);
$i18nClass->addColumn(new sfDoctrineColumnSchema('id', $idDesc));
}
}
// adds the class key fields
protected function addInheritanceFields()
{
foreach ($this->classes as $className => $class)
if ($class->hasOneTableInheritance())
{
$inh = $class->getInheritance();
$class->getTable()->addColumn(new sfDoctrineColumnSchema($inh['keyField'], array('type'=>'integer')));
}
}
public function load($file, $package = null)
{
$schema = sfYaml::load($file);
foreach ($schema as $className => $cd)
{
if (!isset($cd['tableName']) && !isset($cd['inheritance']))
throw new sfDoctrineSchemaException(sprintf('Class "%s" must have either a table or a parent', $className));
$class = new sfDoctrineClassSchema($className, $cd);
// add a table if necessary
if (isset($cd['tableName']))
{
// this top class is actually a table
$table = new sfDoctrineTableSchema($cd['tableName'], $package);
$table->addClass($class);
$this->tables[$cd['tableName']] = $table;
}
$this->classes[$className] = $class;
}
}
public function process()
{
$this->fixTables();
$this->addI18nFields();
$this->fixRelationships();
$this->addInheritanceFields();
}
}
\ No newline at end of file
<?php
/*
* This file is part of the sfDoctrine package.
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony.plugins
* @subpackage sfDoctrine
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: sfDoctrineSchemaPropelLoader.class.php 3455 2007-02-14 16:17:48Z chtito $
*/
class sfDoctrineSchemaPropelLoader extends sfDoctrineDatabaseSchema
{
// get the attributes parsed by the sfPropelDatabaseSchema class
protected function getAttribute($tag, $attribute)
{
return isset($tag['_attributes'][$attribute]) ? $tag['_attributes'][$attribute] : null;
}
public function load($file, $package = null)
{
// we figure out what kind of file we are given
$type = array_pop(explode('.', $file));
$type2method = array('yml'=>'loadYAML', 'xml'=>'loadXML');
if (isset($type2method[$type]))
$method = $type2method[$type];
else
throw new sfDoctrineSchemaException(sprintf('Unkwnown method for extension "%s"', $type));
$propelDatabaseSchema = new sfPropelDatabaseSchema();
$propelDatabaseSchema->$method($file);
$data = $propelDatabaseSchema->asArray();
foreach ($propelDatabaseSchema->getTables() as $tb_name => $tableDesc)
{
// special table class
// propel has only such classes (no inheritance support)
$table = new sfDoctrineTableSchema($tb_name, $package);
$this->tables[$tb_name] = $table;
if (!($className = $this->getAttribute($tableDesc, 'phpName')))
$className = sfInflector::camelize($tb_name); // wild guess
$class = new sfDoctrineClassSchema($className);
$table->addClass($class);
// columns
foreach ($propelDatabaseSchema->getChildren($tableDesc) as $col_name => $columnDescription)
{
if (($col_name == 'id')) // id is automatically generated in doctrine
continue;
$docCol = new sfDoctrineColumnSchema($col_name, $columnDescription, true);
$class->addColumn($docCol);
}
$this->classes[$class->getPhpName()] = $class;
}
}
public function process()
{
$this->fixRelationships();
}
}
\ No newline at end of file
<?php
/*
* This file is part of the sfDoctrine package.
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony.plugins
* @subpackage sfDoctrine
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: sfDoctrineTableSchema.class.php 3455 2007-02-14 16:17:48Z chtito $
*/
class sfDoctrineTableSchema extends sfDoctrineClassSchema
{
// the classes associated to that table
protected $classes;
// table name
protected $name;
// package of that table (usually either a plugin name, or a propel schema name)
protected $package;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function __construct($tableName, $package)
{
$this->setName($tableName);
$this->package = $package;
}
public function addClass($class)
{
// we add the class and try to avoid duplication
$this->classes[$class->getPhpName()] = $class;
$class->setTable($this);
}
public function getClasses()
{
return $this->classes;
}
// exports this table in propel xml format
public function addPropelXmlClasses(&$node)
{
$t = $node->addChild('table');
$t->addAttribute('name', $this->getName());
$t->addAttribute('phpName', $this->getPhpName());
foreach($this->classes as $class)
{
$class->addPropelXmlColumns($t);
}
}
public function getPackage()
{
return $this->package;
}
}
autoload:
# Doctrine:
# name: Doctrine classes
# ext: .php
# path: %SF_PLUGINS_DIR%/sfDoctrine/doctrine
# recursive: on
doctrine_model_classes:
name: Doctrine model classes
ext: .class.php
path: %SF_LIB_DIR%/model/doctrine
\ No newline at end of file
config/doctrine.yml:
class: sfDoctrineConfigHandler
config/schemas.yml:
class: sfDoctrineSchemasConfigHandler
all:
#doctrine attributes
attributes:
#automatic table creation (none, tables, constraints, all)
export: all
#default fetch mode (immediate, batch, lazy, offset, lazy_offset)
fetchmode: immediate
#collection limit (integer 1+)
coll_limit: 5
#global event listener
# listener: sfDoctrineEventListener
#locking (optimistic, pessimistic)
lockmode: pessimistic
#enable doctrine side validation (true, false)
vld: false
# enable quoting
quote_identifier: false
all:
orm: doctrine
# default_database: <your default connection here>
\ No newline at end of file
<?php
/**
* ##MODULE_NAME## actions.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: actions.class.php,v 1.1 2006/12/08 18:49:35 nathanael Exp $
*/
class ##MODULE_NAME##Actions extends auto##MODULE_NAME##Actions
{
}
generator:
class: sfDoctrineAdminGenerator
param:
model_class: ##MODEL_CLASS##
theme: crud
[?php
/**
* <?php echo $this->getGeneratedModuleName() ?> actions.
*
* @package ##PROJECT_NAME##
* @subpackage <?php echo $this->getGeneratedModuleName() ?>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
* @version SVN: $Id: actions.class.php 3923 2007-05-03 19:42:33Z gnat $
*/
class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions
{
public function executeIndex ()
{
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
}
public function executeList ()
{
$this-><?php echo $this->getPluralName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->findAll();
}
public function executeShow ()
{
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
}
public function executeCreate ()
{
$this-><?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();
$this->setTemplate('edit');
}
public function executeEdit ()
{
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
}
public function executeDelete ()
{
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
try
{
$this-><?php echo $this->getSingularName() ?>->delete();
$this->redirect('<?php echo $this->getModuleName() ?>/list');
}
catch (Doctrine_Exception $e)
{
$this->getRequest()->setError('delete', 'Could not delete the selected <?php echo sfInflector::humanize($this->getSingularName()) ?>. Make sure it does not have any associated items.');
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
}
}
public function executeUpdate ()
{
if (<?php echo $this->getTestPksForGetOrCreate(false) ?>)
{
$<?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();
}
else
{
$<?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
$this->forward404Unless($<?php echo $this->getSingularName() ?>);
}
$formData = $this->getRequestParameter('<?php echo $this->getSingularName() ?>');
<?php foreach ($this->getColumns('') as $index => $column):
$type = $column->getDoctrineType();
$name = $column->getName(); ?>
<?php if($column->isPrimaryKey()) continue ?>
<?php if ($name == 'created_at' || $name == 'updated_at') continue ?>
<?php if ($type == 'boolean'): ?>
<?php $boolVar = "\$formData['$name']";
echo $this->getColumnSetter($column, "isset($boolVar) ? $boolVar : 0", false, '')?>;
<?php continue; ?>
<?php endif; // boolean case ?>
if ($newValue = $formData['<?php echo $name ?>'])
{
<?php if ($type == 'date' || $type == 'timestamp'): ?>
<?php $inputPattern = ($type == 'date' ? 'd' : 'g');
$outputPattern = ($type == 'date' ? 'i' : 'I'); ?>
$dateFormat = new sfDateFormat($this->getUser()->getCulture());
<?php echo $this->getColumnSetter($column, sprintf('$dateFormat->format($newValue, \'%s\', $dateFormat->getInputPattern(\'%s\'))', $outputPattern, $inputPattern), false, '');?>;
<?php elseif ($column->isForeignKey()): ?>
$<?php echo $this->getSingularName()?>->set('<?php echo $column->getColumnName()?>', (empty($newValue) ? null : $newValue));
<?php else: ?>
<?php echo $this->getColumnSetter($column, '$newValue', false, '');?>;
<?php endif; ?>
}
<?php endforeach; ?>
$<?php echo $this->getSingularName() ?>->save();
return $this->redirect('<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>);
<?php //' ?>
}
}
[?php use_helper('ObjectDoctrineAdmin', 'Object', 'Date') ?]
[?php echo form_tag('<?php echo $this->getModuleName() ?>/update', 'multipart=true') ?]
<?php foreach ($this->getPrimaryKey() as $pk): ?>
[?php echo object_input_hidden_tag($<?php echo $this->getSingularName() ?>, 'get<?php echo $pk->getPhpName() ?>') ?]
<?php endforeach; ?>
<table>
<tbody>
<?php foreach ($this->getColumns('') as $index => $column): ?>
<?php if ($column->isPrimaryKey()) continue ?>
<?php if ($column->getName() == 'created_at' || $column->getName() == 'updated_at') continue ?>
<tr>
<th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>: </th>
<td>[?php echo <?php echo $this->getColumnEditTag($column) ?> ?]</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<hr />
[?php echo submit_tag('save') ?]
[?php if (<?php echo $this->getPrimaryKeyIsSet() ?>): ?]
&nbsp;[?php echo link_to('delete', '<?php echo $this->getModuleName() ?>/delete?<?php echo $this->getPrimaryKeyUrlParams() ?>, 'post=true&confirm=Are you sure?') ?]
&nbsp;[?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
[?php else: ?]
&nbsp;[?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/list') ?]
[?php endif; ?]
</form>
<h1><?php echo $this->getModuleName() ?></h1>
<table>
<thead>
<tr>
<?php foreach ($this->getColumns('') as $column): ?>
<th><?php echo sfInflector::humanize($column->getName()) ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
[?php foreach ($<?php echo $this->getPluralName() ?> as $<?php echo $this->getSingularName() ?>): ?]
<tr>
<?php foreach ($this->getColumns('') as $column): ?>
<?php if ($column->isPrimaryKey()): ?>
<td>[?php echo link_to($<?php echo $this->getSingularName() ?>->get('<?php echo $column->getPhpName() ?>'), '<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>); ?]</td>
<?php else: ?>
<td>[?php echo $<?php echo $this->getSingularName() ?>->get('<?php echo $column->getPhpName() ?>'); ?]</td>
<?php endif; ?>
<?php endforeach; ?>
</tr>
[?php endforeach; ?]
<tr><td>Number of <?php echo $this->getPluralName() ?>: [?php echo count($<?php echo $this->getPluralName()?>) ?]</td></tr>
</tbody>
</table>
[?php echo link_to ('create', '<?php echo $this->getModuleName() ?>/create') ?]
<table>
<tbody>
<?php foreach ($this->getAllColumns() as $column): ?>
<tr>
<th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>: </th>
<td>[?= $<?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>() ?]</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<hr />
[?php echo link_to('edit', '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
&nbsp;[?php echo link_to('list', '<?php echo $this->getModuleName() ?>/list') ?]
<?php
/**
* ##MODULE_NAME## actions.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author Your name here
* @version SVN: $Id: actions.class.php 1415 2006-06-11 08:33:51Z fabien $
*/
class ##MODULE_NAME##Actions extends auto##MODULE_NAME##Actions
{
}
generator:
class: sfDoctrineAdminGenerator
param:
model_class: ##MODEL_CLASS##
theme: default
<ul class="sf_admin_actions">
<?php $editActions = $this->getParameterValue('edit.actions') ?>
<?php if (null !== $editActions): ?>
<?php foreach ((array) $editActions as $actionName => $params): ?>
<?php if ($actionName == '_delete') continue ?>
<?php echo $this->addCredentialCondition($this->getButtonToAction($actionName, $params, true), $params) ?>
<?php endforeach; ?>
<?php else: ?>
<?php echo $this->getButtonToAction('_list', array(), true) ?>
<?php echo $this->getButtonToAction('_save', array(), true) ?>
<?php echo $this->getButtonToAction('_save_and_add', array(), true) ?>
<?php endif; ?>
</ul>
[?php echo form_tag('<?php echo $this->getModuleName() ?>/save', array(
'id' => 'sf_admin_edit_form',
'name' => 'sf_admin_edit_form',
'multipart' => true,
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
<?php if (false !== strpos($this->getParameterValue('edit.fields.'.$column->getName().'.type'), 'admin_double_list')): ?>
'onsubmit' => 'double_list_submit(); return true;'
<?php break 2; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
)) ?]
<?php foreach ($this->getPrimaryKey() as $pk): ?>
[?php echo object_input_hidden_tag($<?php echo $this->getSingularName() ?>, 'get<?php echo $pk->getPhpName() ?>') ?]
<?php endforeach; ?>
<?php $first = true ?>
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
<?php
if ($category[0] == '-')
{
$category_name = substr($category, 1);
$collapse = true;
if ($first)
{
$first = false;
echo "[?php use_javascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype') ?]\n";
echo "[?php use_javascript(sfConfig::get('sf_admin_web_dir').'/js/collapse') ?]\n";
}
}
else
{
$category_name = $category;
$collapse = false;
}
?>
<fieldset id="sf_fieldset_<?php echo preg_replace('/[^a-z0-9_]/', '_', strtolower($category_name)) ?>" class="<?php if ($collapse): ?> collapse<?php endif; ?>">
<?php if ($category != 'NONE'): ?><h2>[?php echo __('<?php echo $category_name ?>') ?]</h2>
<?php endif; ?>
<?php $hides = $this->getParameterValue('edit.hide', array()) ?>
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
<?php if (in_array($column->getName(), $hides)) continue ?>
<?php if ($column->isPrimaryKey()) continue ?>
<?php $credentials = $this->getParameterValue('edit.fields.'.$column->getName().'.credentials') ?>
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
<?php endif; ?>
<div class="form-row">
[?php echo label_for('<?php echo $this->getParameterValue("edit.fields.".$column->getName().".label_for", $this->getSingularName()."[".$column->getName()."]") ?>', __($labels['<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}']), '<?php if ($column->isNotNull()): ?>class="required" <?php endif; ?>') ?]
<div class="content[?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?] form-error[?php endif; ?]">
[?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?]
[?php echo form_error('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}', array('class' => 'form-error-msg')) ?]
[?php endif; ?]
[?php $value = <?php echo $this->getColumnEditTag($column); ?>; echo $value ? $value : '&nbsp;' ?]
<?php echo $this->getHelp($column, 'edit') ?>
</div>
</div>
<?php if ($credentials): ?>
[?php endif; ?]
<?php endif; ?>
<?php endforeach; ?>
</fieldset>
<?php endforeach; ?>
[?php include_partial('edit_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
</form>
<ul class="sf_admin_actions">
<?php
/*
* WARNING: delete is a form, it must be outside the main form
*/
$editActions = $this->getParameterValue('edit.actions');
?>
<?php if (null === $editActions || (null !== $editActions && array_key_exists('_delete', $editActions))): ?>
<?php echo $this->addCredentialCondition($this->getButtonToAction('_delete', $editActions['_delete'], true), $editActions['_delete']) ?>
<?php endif; ?>
</ul>
[?php if ($sf_request->hasErrors()): ?]
<div class="form-errors">
<h2>[?php echo __('There are some errors that prevent the form to validate') ?]</h2>
<dl>
[?php foreach ($sf_request->getErrorNames() as $name): ?]
<dt>[?php echo __($labels[$name]) ?]</dt>
<dd>[?php echo $sf_request->getError($name) ?]</dd>
[?php endforeach; ?]
</dl>
</div>
[?php elseif ($sf_flash->has('notice')): ?]
<div class="save-ok">
<h2>[?php echo __($sf_flash->get('notice')) ?]</h2>
</div>
[?php endif; ?]
[?php use_helper('Object') ?]
<?php if ($this->getParameterValue('list.filters')): ?>
<div class="sf_admin_filters">
[?php echo form_tag('<?php echo $this->getModuleName() ?>/list', array('method' => 'get')) ?]
<fieldset>
<h2>[?php echo __('filters') ?]</h2>
<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?>
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
<?php endif; ?>
<div class="form-row">
<label for="<?php echo $column->getName() ?>">[?php echo __('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>:') ?]</label>
<div class="content">
[?php echo <?php echo $this->getColumnFilterTag($column) ?> ?]
<?php if ($this->getParameterValue('list.fields.'.$column->getName().'.filter_is_empty')): ?>
<div>[?php echo checkbox_tag('filters[<?php echo $column->getName() ?>_is_empty]', 1, isset($filters['<?php echo $column->getName() ?>_is_empty']) ? $filters['<?php echo $column->getName() ?>_is_empty'] : null) ?]&nbsp;<label for="filters[<?php echo $column->getName() ?>_is_empty]">[?php echo __('is empty') ?]</label></div>
<?php endif; ?>
</div>
</div>
<?php if ($credentials): ?>
[?php endif; ?]
<?php endif; ?>
<?php endforeach; ?>
</fieldset>
<ul class="sf_admin_actions">
<li>[?php echo button_to(__('reset'), '<?php echo $this->getModuleName() ?>/list?filter=filter', 'class=sf_admin_action_reset_filter') ?]</li>
<li>[?php echo submit_tag(__('filter'), 'name=filter class=sf_admin_action_filter') ?]</li>
</ul>
</form>
</div>
<?php endif; ?>
<table cellspacing="0" class="sf_admin_list">
<thead>
<tr>
[?php include_partial('list_th_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>') ?]
<?php if ($this->getParameterValue('list.object_actions')): ?>
<th id="sf_admin_list_th_sf_actions">[?php echo __('Actions') ?]</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
[?php $i = 1; foreach ($pager->getResults() as $<?php echo $this->getSingularName() ?>): $odd = fmod(++$i, 2) ?]
<tr class="sf_admin_row_[?php echo $odd ?]">
[?php include_partial('list_td_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
[?php include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
</tr>
[?php endforeach; ?]
</tbody>
<tfoot>
<tr><th colspan="<?php echo $this->getParameterValue('list.object_actions') ? count($this->getColumns('list.display')) + 1 : count($this->getColumns('list.display')) ?>">
<div class="float-right">
[?php if ($pager->haveToPaginate()): ?]
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/first.png', array('align' => 'absmiddle', 'alt' => __('First'), 'title' => __('First'))), '<?php echo $this->getModuleName() ?>/list?page=1') ?]
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', array('align' => 'absmiddle', 'alt' => __('Previous'), 'title' => __('Previous'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getPreviousPage()) ?]
[?php foreach ($pager->getLinks() as $page): ?]
[?php echo link_to_unless($page == $pager->getPage(), $page, '<?php echo $this->getModuleName() ?>/list?page='.$page) ?]
[?php endforeach; ?]
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', array('align' => 'absmiddle', 'alt' => __('Next'), 'title' => __('Next'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getNextPage()) ?]
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/last.png', array('align' => 'absmiddle', 'alt' => __('Last'), 'title' => __('Last'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getLastPage()) ?]
[?php endif; ?]
</div>
[?php echo format_number_choice('[0] no result|[1] 1 result|(1,+Inf] %1% results', array('%1%' => $pager->getNbResults()), $pager->getNbResults()) ?]
</th></tr>
</tfoot>
</table>
<ul class="sf_admin_actions">
<?php $listActions = $this->getParameterValue('list.actions') ?>
<?php if (null !== $listActions): ?>
<?php foreach ((array) $listActions as $actionName => $params): ?>
<?php echo $this->addCredentialCondition($this->getButtonToAction($actionName, $params, false), $params) ?>
<?php endforeach; ?>
<?php else: ?>
<?php echo $this->getButtonToAction('_create', array(), false) ?>
<?php endif; ?>
</ul>
[?php if ($sf_request->getError('delete')): ?]
<div class="form-errors">
<h2>[?php echo __('Could not delete the selected %name%', array('%name%' => '<?php echo sfInflector::humanize($this->getSingularName()) ?>')) ?]</h2>
<ul>
<li>[?php echo $sf_request->getError('delete') ?]</li>
</ul>
</div>
[?php endif; ?]
<?php if ($this->getParameterValue('list.object_actions')): ?>
<td>
<ul class="sf_admin_td_actions">
<?php foreach ($this->getParameterValue('list.object_actions') as $actionName => $params): ?>
<?php echo $this->addCredentialCondition($this->getLinkToAction($actionName, $params, true), $params) ?>
<?php endforeach; ?>
</ul>
</td>
<?php endif; ?>
<td colspan="<?php echo count($this->getColumns('list.display')) ?>">
<?php if ($this->getParameterValue('list.params')): ?>
<?php echo $this->getI18NString('list.params') ?>
<?php else: ?>
<?php $hides = $this->getParameterValue('list.hide', array()) ?>
<?php foreach ($this->getColumns('list.display') as $column): ?>
<?php if (in_array($column->getName(), $hides)) continue ?>
<?php if ($column->isLink()): ?>
[?php echo link_to(<?php echo $this->getColumnListTag($column) ?> ? <?php echo $this->getColumnListTag($column) ?> : __('-'), '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
<?php else: ?>
[?php echo <?php echo $this->getColumnListTag($column) ?> ?]
<?php endif; ?>
-
<?php endforeach; ?>
<?php endif; ?>
</td>
\ No newline at end of file
<?php $hs = $this->getParameterValue('list.hide', array()) ?>
<?php foreach ($this->getColumns('list.display') as $column): ?>
<?php if (in_array($column->getName(), $hs)) continue ?>
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
<?php endif; ?>
<?php if ($column->isLink()): ?>
<td>[?php echo link_to(<?php echo $this->getColumnListTag($column) ?> ? <?php echo $this->getColumnListTag($column) ?> : __('-'), '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]</td>
<?php else: ?>
<td>[?php echo <?php echo $this->getColumnListTag($column) ?> ?]</td>
<?php endif; ?>
<?php if ($credentials): ?>
[?php endif; ?]
<?php endif; ?>
<?php endforeach; ?>
<?php $hides = $this->getParameterValue('list.hide', array()) ?>
<?php foreach ($this->getColumns('list.display') as $column): ?>
<?php if (in_array($column->getName(), $hides)) continue ?>
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
<?php endif; ?>
<th id="sf_admin_list_th_<?php echo $column->getName() ?>">
<?php if ($column->isReal()): ?>
[?php if ($sf_user->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == '<?php echo $column->getName() ?>'): ?]
[?php echo link_to(__('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>'), '<?php echo $this->getModuleName() ?>/list?sort=<?php echo $column->getName() ?>&type='.($sf_user->getAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == 'asc' ? 'desc' : 'asc')) ?]
([?php echo __($sf_user->getAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort')) ?])
[?php else: ?]
[?php echo link_to(__('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>'), '<?php echo $this->getModuleName() ?>/list?sort=<?php echo $column->getName() ?>&type=asc') ?]
[?php endif; ?]
<?php else: ?>
[?php echo __('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>') ?]
<?php endif; ?>
<?php echo $this->getHelpAsIcon($column, 'list') ?>
</th>
<?php if ($credentials): ?>
[?php endif; ?]
<?php endif; ?>
<?php endforeach; ?>
[?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?]
[?php use_stylesheet('<?php echo $this->getParameterValue('css', sfConfig::get('sf_admin_web_dir').'/css/main') ?>') ?]
<div id="sf_admin_container">
<h1><?php echo $this->getI18NString('edit.title', 'edit '.$this->getModuleName()) ?></h1>
<div id="sf_admin_header">
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_header', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
</div>
<div id="sf_admin_content">
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_messages', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'labels' => $labels)) ?]
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_form', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'labels' => $labels)) ?]
</div>
<div id="sf_admin_footer">
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_footer', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
</div>
</div>
[?php use_helper('I18N', 'Date') ?]
[?php use_stylesheet('<?php echo $this->getParameterValue('css', sfConfig::get('sf_admin_web_dir').'/css/main') ?>') ?]
<div id="sf_admin_container">
<h1><?php echo $this->getI18NString('list.title', $this->getModuleName().' list') ?></h1>
<div id="sf_admin_header">
[?php include_partial('<?php echo $this->getModuleName() ?>/list_header', array('pager' => $pager)) ?]
[?php include_partial('<?php echo $this->getModuleName() ?>/list_messages', array('pager' => $pager)) ?]
</div>
<div id="sf_admin_bar">
<?php if ($this->getParameterValue('list.filters')): ?>
[?php include_partial('filters', array('filters' => $filters)) ?]
<?php endif; ?>
</div>
<div id="sf_admin_content">
[?php if (!$pager->getNbResults()): ?]
[?php echo __('no result') ?]
[?php else: ?]
[?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager)) ?]
[?php endif; ?]
[?php include_partial('list_actions') ?]
</div>
<div id="sf_admin_footer">
[?php include_partial('<?php echo $this->getModuleName() ?>/list_footer', array('pager' => $pager)) ?]
</div>
</div>
<?php
/*
* $Id: Access.php 1604 2007-06-08 19:07:32Z zYne $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Access
*
* the purpose of Doctrine_Access is to provice array access
* and property overload interface for subclasses
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1604 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract class Doctrine_Access extends Doctrine_Object implements ArrayAccess
{
/**
* setArray
*
* @param array $array an array of key => value pairs
* @since 1.0
* @return Doctrine_Access
*/
public function setArray(array $array)
{
foreach ($array as $k=>$v) {
$this->set($k,$v);
}
return $this;
}
/**
* __set an alias of set()
*
* @see set, offsetSet
* @param $name
* @param $value
* @since 1.0
* @return void
*/
public function __set($name,$value)
{
$this->set($name,$value);
}
/**
* __get -- an alias of get()
*
* @see get, offsetGet
* @param mixed $name
* @since 1.0
* @return mixed
*/
public function __get($name)
{
return $this->get($name);
}
/**
* __isset()
*
* @param string $name
* @since 1.0
* @return boolean whether or not this object contains $name
*/
public function __isset($name)
{
return $this->contains($name);
}
/**
* __unset()
*
* @param string $name
* @since 1.0
* @return void
*/
public function __unset($name)
{
return $this->remove($name);
}
/**
* @param mixed $offset
* @return boolean whether or not this object contains $offset
*/
public function offsetExists($offset)
{
return $this->contains($offset);
}
/**
* offsetGet an alias of get()
* @see get, __get
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->get($offset);
}
/**
* sets $offset to $value
* @see set, __set
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
if ( ! isset($offset)) {
$this->add($value);
} else {
$this->set($offset, $value);
}
}
/**
* unset a given offset
* @see set, offsetSet, __set
* @param mixed $offset
*/
public function offsetUnset($offset)
{
return $this->remove($offset);
}
}
<?php
/*
* $Id: Adapter.php 1080 2007-02-10 18:17:08Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
*
* Doctrine_Adapter
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Adapter
{
const ATTR_AUTOCOMMIT = 0;
const ATTR_CASE = 8;
const ATTR_CLIENT_VERSION = 5;
const ATTR_CONNECTION_STATUS = 7;
const ATTR_CURSOR = 10;
const ATTR_CURSOR_NAME = 9;
const ATTR_DRIVER_NAME = 16;
const ATTR_ERRMODE = 3;
const ATTR_FETCH_CATALOG_NAMES = 15;
const ATTR_FETCH_TABLE_NAMES = 14;
const ATTR_MAX_COLUMN_LEN = 18;
const ATTR_ORACLE_NULLS = 11;
const ATTR_PERSISTENT = 12;
const ATTR_PREFETCH = 1;
const ATTR_SERVER_INFO = 6;
const ATTR_SERVER_VERSION = 4;
const ATTR_STATEMENT_CLASS = 13;
const ATTR_STRINGIFY_FETCHES = 17;
const ATTR_TIMEOUT = 2;
const CASE_LOWER = 2;
const CASE_NATURAL = 0;
const CASE_UPPER = 1;
const CURSOR_FWDONLY = 0;
const CURSOR_SCROLL = 1;
const ERR_ALREADY_EXISTS = NULL;
const ERR_CANT_MAP = NULL;
const ERR_CONSTRAINT = NULL;
const ERR_DISCONNECTED = NULL;
const ERR_MISMATCH = NULL;
const ERR_NO_PERM = NULL;
const ERR_NONE = '00000';
const ERR_NOT_FOUND = NULL;
const ERR_NOT_IMPLEMENTED = NULL;
const ERR_SYNTAX = NULL;
const ERR_TRUNCATED = NULL;
const ERRMODE_EXCEPTION = 2;
const ERRMODE_SILENT = 0;
const ERRMODE_WARNING = 1;
const FETCH_ASSOC = 2;
const FETCH_BOTH = 4;
const FETCH_BOUND = 6;
const FETCH_CLASS = 8;
const FETCH_CLASSTYPE = 262144;
const FETCH_COLUMN = 7;
const FETCH_FUNC = 10;
const FETCH_GROUP = 65536;
const FETCH_INTO = 9;
const FETCH_LAZY = 1;
const FETCH_NAMED = 11;
const FETCH_NUM = 3;
const FETCH_OBJ = 5;
const FETCH_ORI_ABS = 4;
const FETCH_ORI_FIRST = 2;
const FETCH_ORI_LAST = 3;
const FETCH_ORI_NEXT = 0;
const FETCH_ORI_PRIOR = 1;
const FETCH_ORI_REL = 5;
const FETCH_SERIALIZE = 524288;
const FETCH_UNIQUE = 196608;
const NULL_EMPTY_STRING = 1;
const NULL_NATURAL = 0;
const NULL_TO_STRING = NULL;
const PARAM_BOOL = 5;
const PARAM_INPUT_OUTPUT = -2147483648;
const PARAM_INT = 1;
const PARAM_LOB = 3;
const PARAM_NULL = 0;
const PARAM_STMT = 4;
const PARAM_STR = 2;
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Adapter_Exception');
/**
* Doctrine_Adapter_Db2_Exception
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Adapter_Db2_Exception extends Doctrine_Adapter_Exception
{ }
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Exception');
/**
* Doctrine_Adapter_Exception
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Adapter_Exception extends Doctrine_Exception
{ }
<?php
/*
* $Id: Interface.php 1080 2007-02-10 18:17:08Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Adapter_Interface
* This adapter interface should be implemented by all custom adapters
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
interface Doctrine_Adapter_Interface {
public function prepare($prepareString);
public function query($queryString);
public function quote($input);
public function exec($statement);
public function lastInsertId();
public function beginTransaction();
public function commit();
public function rollBack();
public function errorCode();
public function errorInfo();
}
<?php
/*
* $Id: Mock.php 1819 2007-06-25 17:48:44Z subzero2000 $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Adapter_Mock
* This class is used for special testing purposes.
*
* @package Doctrine
* @subpackage Doctrine_Adapter
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1819 $
*/
class Doctrine_Adapter_Mock implements Doctrine_Adapter_Interface, Countable
{
private $name;
private $queries = array();
private $exception = array();
private $lastInsertIdFail = false;
public function __construct($name = null)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function pop()
{
return array_pop($this->queries);
}
public function forceException($name, $message = '', $code = 0)
{
$this->exception = array($name, $message, $code);
}
public function prepare($query)
{
$mock = new Doctrine_Adapter_Statement_Mock($this, $query);
$mock->queryString = $query;
return $mock;
}
public function addQuery($query)
{
$this->queries[] = $query;
}
public function query($query)
{
$this->queries[] = $query;
$e = $this->exception;
if( ! empty($e)) {
$name = $e[0];
$this->exception = array();
throw new $name($e[1], $e[2]);
}
$stmt = new Doctrine_Adapter_Statement_Mock($this, $query);
$stmt->queryString = $query;
return $stmt;
}
public function getAll()
{
return $this->queries;
}
public function quote($input)
{
return "'" . addslashes($input) . "'";
}
public function exec($statement)
{
$this->queries[] = $statement;
$e = $this->exception;
if( ! empty($e)) {
$name = $e[0];
$this->exception = array();
throw new $name($e[1], $e[2]);
}
return 0;
}
public function forceLastInsertIdFail($fail = true)
{
if ($fail) {
$this->lastInsertIdFail = true;
} else {
$this->lastInsertIdFail = false;
}
}
public function lastInsertId()
{
$this->queries[] = 'LAST_INSERT_ID()';
if ($this->lastInsertIdFail) {
return null;
} else {
return 1;
}
}
public function count()
{
return count($this->queries);
}
public function beginTransaction()
{
$this->queries[] = 'BEGIN TRANSACTION';
}
public function commit()
{
$this->queries[] = 'COMMIT';
}
public function rollBack()
{
$this->queries[] = 'ROLLBACK';
}
public function errorCode()
{ }
public function errorInfo()
{ }
public function getAttribute($attribute)
{
if($attribute == Doctrine::ATTR_DRIVER_NAME)
return strtolower($this->name);
}
public function setAttribute($attribute, $value)
{
}
public function sqliteCreateFunction()
{ }
}
<?php
/*
* $Id: Mock.php 1080 2007-02-10 18:17:08Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Adapter_Mysqli
* This class is used for special testing purposes.
*
* @package Doctrine
* @subpackage Doctrine_Adapter
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
*/
class Doctrine_Adapter_Mysqli extends Doctrine_Adapter
{
/**
* Creates a connection to the database.
*
* @return void
* @throws Doctrine_Adapter_Mysqli_Exception
*/
protected function _connect()
{
if ($this->_connection) {
return;
}
// Suppress connection warnings here.
// Throw an exception instead.
@$this->_connection = new mysqli(
$this->_config['host'],
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname']
);
if ($this->_connection === false || mysqli_connect_errno()) {
throw new Doctrine_Adapter_Mysqli_Exception(mysqli_connect_error());
}
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
$this->_connection->close();
$this->_connection = null;
}
/**
* Prepare a statement and return a PDOStatement-like object.
*
* @param string $sql SQL query
* @return Doctrine_Statement_Mysqli
*/
public function prepare($sql)
{
$this->_connect();
$stmt = new Doctrine_Statement_Mysqli($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* MySQL does not support sequences, so $tableName and $primaryKey are ignored.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return integer
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$mysqli = $this->_connection;
return $mysqli->insert_id;
}
/**
* Begin a transaction.
*
* @return void
*/
protected function _beginTransaction()
{
$this->_connect();
$this->_connection->autocommit(false);
}
/**
* Commit a transaction.
*
* @return void
*/
protected function _commit()
{
$this->_connect();
$this->_connection->commit();
$this->_connection->autocommit(true);
}
/**
* Roll-back a transaction.
*
* @return void
*/
protected function _rollBack()
{
$this->_connect();
$this->_connection->rollback();
$this->_connection->autocommit(true);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Record_Listener');
/**
* Doctrine_AuditLog_Listener
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
{
protected $_auditLog;
public function __construct(Doctrine_AuditLog $auditLog) {
$this->_auditLog = $auditLog;
}
public function preInsert(Doctrine_Event $event)
{
$versionColumn = $this->_auditLog->getOption('versionColumn');
$event->getInvoker()->set($versionColumn, 1);
}
public function preDelete(Doctrine_Event $event)
{
$class = $this->_auditLog->getOption('className');
$record = $event->getInvoker();
$version = new $class();
$version->merge($record->toArray());
$version->save();
$versionColumn = $this->_auditLog->getOption('versionColumn');
$version = $record->get($versionColumn);
$record->set($versionColumn, ++$version);
}
public function preUpdate(Doctrine_Event $event)
{
$class = $this->_auditLog->getOption('className');
$record = $event->getInvoker();
$version = new $class();
$version->merge($record->toArray());
$version->save();
$versionColumn = $this->_auditLog->getOption('versionColumn');
$version = $record->get($versionColumn);
$record->set($versionColumn, ++$version);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment