本文整理汇总了PHP中Doctrine_Record::getTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Record::getTable方法的具体用法?PHP Doctrine_Record::getTable怎么用?PHP Doctrine_Record::getTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Record
的用法示例。
在下文中一共展示了Doctrine_Record::getTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchRelatedFor
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = $record->getIncremented();
if (empty($id) || !$this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
return Doctrine_Collection::create($this->getTable());
} else {
$q = new Doctrine_RawSql($this->getTable()->getConnection());
$assocTable = $this->getAssociationFactory()->getTableName();
$tableName = $record->getTable()->getTableName();
$identifierColumnNames = $record->getTable()->getIdentifierColumnNames();
$identifier = array_pop($identifierColumnNames);
$sub = 'SELECT ' . $this->getForeignRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocalRefColumnName() . ' = ?';
$condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')';
$joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeignRefColumnName();
if ($this->definition['equal']) {
$sub2 = 'SELECT ' . $this->getLocalRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeignRefColumnName() . ' = ?';
$condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')';
$joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocalRefColumnName();
}
$q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))->where(implode(' OR ', $condition))->orderBy($tableName . '.' . $identifier . ' ASC');
if ($orderBy = $this->getOrderByStatement($tableName, true)) {
$q->addOrderBy($orderBy);
}
$q->addComponent($tableName, $this->getClass());
$path = $this->getClass() . '.' . $this->getAssociationFactory()->getComponentName();
if ($this->definition['refClassRelationAlias']) {
$path = $this->getClass() . '.' . $this->definition['refClassRelationAlias'];
}
$q->addComponent($assocTable, $path);
$params = $this->definition['equal'] ? array($id, $id) : array($id);
$res = $q->execute($params);
return $res;
}
}
示例2: __construct
/**
* contructor, creates node with reference to record and any options
*
* @param object $record instance of Doctrine_Record
* @param array $options options
*/
public function __construct(Doctrine_Record $record, $options)
{
$this->record = $record;
$this->options = $options;
// Make sure that the tree object of the root class is used in the case
// of column aggregation inheritance (single table inheritance).
$class = $record->getTable()->getComponentName();
$thisTable = $record->getTable();
$table = $thisTable;
if ($thisTable->getOption('inheritanceMap')) {
// Move up the hierarchy until we find the "subclasses" option. This option
// MUST be set on the root class of the user's hierarchy that uses STI.
while (!($subclasses = $table->getOption('subclasses'))) {
$class = get_parent_class($class);
$reflectionClass = new ReflectionClass($class);
if ($reflectionClass->isAbstract()) {
continue;
}
if ($class == 'Doctrine_Record') {
throw new Doctrine_Node_Exception("No subclasses specified. You are " . "using Single Table Inheritance with NestedSet but you have " . "not specified the subclasses correctly. Make sure you use " . "setSubclasses() in the root class of your hierarchy.");
}
$table = $table->getConnection()->getTable($class);
}
}
if ($thisTable !== $table) {
$this->_tree = $table->getTree();
} else {
$this->_tree = $thisTable->getTree();
}
}
示例3: refreshPosition
/**
* Refreshs the position of the object
*
* @param Doctrine_Record $object
*/
private function refreshPosition(Doctrine_Record $object)
{
$identifiers = $object->getTable()->getIdentifierColumnNames();
$query = $object->getTable()->createQuery()->select($this->_options['name']);
foreach ($identifiers as $identifier) {
$query->andWhere($identifier . ' = ?', $object->get($identifier));
}
$position = $query->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
$object->set($this->_options['name'], $position['position'], false);
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->setupTableForRecord('Robo47_Log_Writer_Doctrine_Test_Log');
$this->setupTableForRecord('Robo47_Log_Writer_Doctrine_Test_Log2');
$this->_model = new Robo47_Log_Writer_Doctrine_Test_Log();
$this->_table = $this->_model->getTable();
$this->_model2 = new Robo47_Log_Writer_Doctrine_Test_Log2();
$this->_table2 = $this->_model2->getTable();
$this->_writer = new Robo47_Log_Writer_DoctrineTable($this->_table, array());
}
示例5: fetchRelatedFor
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = $record->getIncremented();
$q = new Doctrine_RawSql();
$assocTable = $this->getAssociationFactory()->getTableName();
$tableName = $record->getTable()->getTableName();
$identifier = $record->getTable()->getIdentifier();
$sub = 'SELECT ' . $this->getForeign() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocal() . ' = ?';
$sub2 = 'SELECT ' . $this->getLocal() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeign() . ' = ?';
$q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocal() . ' OR ' . $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeign())->where($tableName . '.' . $identifier . ' IN (' . $sub . ') OR ' . $tableName . '.' . $identifier . ' IN (' . $sub2 . ')');
$q->addComponent($tableName, $record->getTable()->getComponentName());
$q->addComponent($assocTable, $record->getTable()->getComponentName() . '.' . $this->getAssociationFactory()->getComponentName());
return $q->execute(array($id, $id));
}
示例6: fetchRelatedFor
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = array();
$localTable = $record->getTable();
foreach ((array) $this->definition['local'] as $local) {
$value = $record->get($localTable->getFieldName($local));
if (isset($value)) {
$id[] = $value;
}
}
if ($this->isOneToOne()) {
if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition();
$coll = $this->getTable()->getConnection()->query($dql, $id);
$related = $coll[0];
}
$related->set($related->getTable()->getFieldName($this->definition['foreign']), $record, false);
} else {
if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = Doctrine_Collection::create($this->getTable());
} else {
$query = $this->getRelationDql(1);
$related = $this->getTable()->getConnection()->query($query, $id);
}
$related->setReference($record, $this);
}
return $related;
}
示例7: toggleRecordValue
/**
* Automatic 'disabled' field handling
* @param Doctrine_Record $record
* @param string $field
* @throws AppKitDoctrineUtilException
*/
public static function toggleRecordValue(Doctrine_Record &$record, $field = null)
{
// Try to autodetect the fieldname
if ($field === null) {
foreach ($record->getTable()->getColumns() as $name => $info) {
if (preg_match('@_disabled$@', $name) && in_array($info['type'], array('boolean', 'integer')) == true) {
$field = $name;
}
}
}
if ($field && $record->getTable()->hasColumn($field)) {
$record->{$field} = !$record->{$field};
} else {
throw new AppKitDoctrineUtilException("Field does not exist on the record (tableobject) ");
}
}
示例8: fetchRelatedFor
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public function fetchRelatedFor(Doctrine_Record $record)
{
$localFieldName = $record->getTable()->getFieldName($this->definition['local']);
$id = $record->get($localFieldName);
if (is_null($id) || ! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
// Ticket #1131 Patch.
if ( ! is_null($id)) {
$related->assignIdentifier($id);
$related->state(Doctrine_Record::STATE_PROXY);
}
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
. ' WHERE ' . $this->getCondition() . $this->getOrderBy(null, false);
$related = $this->getTable()
->getConnection()
->query($dql, array($id))
->getFirst();
if ( ! $related || empty($related)) {
$related = $this->getTable()->create();
}
}
$record->set($localFieldName, $id, false);
return $related;
}
示例9: getFor
public static function getFor(Doctrine_Record $object)
{
$tableName = $object->getTable()->getTableName();
$componentName = $object->getTable()->getComponentName();
$q = Doctrine_Query::create()->select('c.message, c.parent, c.created_at, c.updated_at, c.created_by, c.updated_by, p.*, v.*,u.*')->from('Comment' . $componentName . ' c')->leftJoin('c.CreatedBy p')->leftJoin('p.User u')->leftJoin('c.VoteComment v')->where('c.' . $tableName . '_id = ?', $object->getId());
$treeObject = Doctrine::getTable('Comment' . $componentName)->getTree();
$treeObject->setBaseQuery($q);
$comments = array();
$rootComment = $treeObject->fetchRoots()->getFirst();
if ($rootComment) {
foreach ($treeObject->fetchTree(array('root_id' => $rootComment->root_id)) as $comment) {
$comments[] = $comment;
}
}
array_shift($comments);
return $comments;
}
示例10: cleanData
/**
* cleanData
* this method does several things to records internal data
*
* 1. It unserializes array and object typed columns
* 2. Uncompresses gzip typed columns
* 3. Gets the appropriate enum values for enum typed columns
* 4. Initializes special null object pointer for null values (for fast column existence checking purposes)
*
*
* example:
*
* $data = array("name" => "John", "lastname" => null, "id" => 1, "unknown" => "unknown");
* $data after operation:
* $data = array("name" => "John", "lastname" => Object(Doctrine_Null));
*
* here column 'id' is removed since its auto-incremented primary key (read-only)
*
* @throws Doctrine_Record_Exception if unserialization of array/object typed column fails or
* if uncompression of gzip typed column fails
*
* @param array $data data array to be cleaned
* @return integer
*/
public function cleanData($data)
{
foreach ($this->_record->getTable()->getColumnNames() as $name) {
if (!isset($data[$name])) {
$data[$name] = self::$_null;
}
}
return $data;
}
示例11: validateRecord
/**
* Validates a given record and saves possible errors in Doctrine_Validator::$stack
*
* @param Doctrine_Record $record
* @return void
*/
public function validateRecord(Doctrine_Record $record)
{
$table = $record->getTable();
// if record is transient all fields will be validated
// if record is persistent only the modified fields will be validated
$fields = $record->exists() ? $record->getModified() : $record->getData();
foreach ($fields as $fieldName => $value) {
$table->validateField($fieldName, $value, $record);
}
}
示例12: __construct
/**
* contructor, creates node with reference to record and any options
*
* @param object $record instance of Doctrine_Record
* @param array $options options
*/
public function __construct(Doctrine_Record $record, $options)
{
$this->record = $record;
$this->options = $options;
// Make sure that the tree object of the root component is used in the case
// of column aggregation inheritance.
$class = $record->getTable()->getComponentName();
$table = $record->getTable();
if ($table->getOption('inheritanceMap')) {
$subclasses = $table->getOption('subclasses');
while (in_array($class, $subclasses)) {
$class = get_parent_class($class);
}
}
if ($class != $table->getComponentName()) {
$this->_tree = $table->getConnection()->getTable($class)->getTree();
} else {
$this->_tree = $table->getTree();
}
}
示例13: initRelated
public function initRelated(Doctrine_Record $record, $name)
{
if (!isset($this->_initializedRelations[$record->getOid()][$name])) {
$relation = $record->getTable()->getRelation($name);
$coll = new Doctrine_Collection($relation->getTable()->getComponentName());
$coll->setReference($record, $relation);
$record[$name] = $coll;
$this->_initializedRelations[$record->getOid()][$name] = true;
}
return true;
}
示例14: createRoot
/**
* Creates root node from given record or from a new record.
*
* Note: When using a tree with multiple root nodes (hasManyRoots), you MUST pass in a
* record to use as the root. This can either be a new/transient record that already has
* the root id column set to some numeric value OR a persistent record. In the latter case
* the records id will be assigned to the root id. You must use numeric columns for the id
* and root id columns.
*
* @param object $record instance of Doctrine_Record
*/
public function createRoot(Doctrine_Record $record = null)
{
if ($this->getAttribute('hasManyRoots')) {
if (!$record || !$record->exists() && $record->getNode()->getRootValue() <= 0 || $record->getTable()->isIdentifierComposite()) {
throw new Doctrine_Tree_Exception("Node must have a root id set or must " . " be persistent and have a single-valued numeric primary key in order to" . " be created as a root node. Automatic assignment of a root id on" . " transient/new records is no longer supported.");
}
if ($record->exists() && $record->getNode()->getRootValue() <= 0) {
// Default: root_id = id
$identifier = $record->getTable()->getIdentifier();
$record->getNode()->setRootValue($record->get($identifier));
}
}
if (!$record) {
$record = $this->table->create();
}
$record->set('lft', '1');
$record->set('rgt', '2');
$record->set('level', 0);
$record->save();
return $record;
}
示例15: getRecordAsString
/**
* Dumps a record.
*
* This method returns an html representation of a given
* record, containing keys, state and data.
*
* @param Doctrine_Record $record
* @return string
*/
public static function getRecordAsString(Doctrine_Record $record)
{
$r[] = '<pre>';
$r[] = 'Component : ' . $record->getTable()->getComponentName();
$r[] = 'ID : ' . Doctrine::dump($record->identifier());
$r[] = 'References : ' . count($record->getReferences());
$r[] = 'State : ' . Doctrine_Lib::getRecordStateAsString($record->state());
$r[] = 'OID : ' . $record->getOID();
$r[] = 'data : ' . Doctrine::dump($record->getData(), false);
$r[] = '</pre>';
return implode("\n", $r) . "<br />";
}