本文整理汇总了PHP中Doctrine_Record::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Record::get方法的具体用法?PHP Doctrine_Record::get怎么用?PHP Doctrine_Record::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Record
的用法示例。
在下文中一共展示了Doctrine_Record::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterSet
/**
* Implementation of filterSet() to call set on Translation relationship to allow
* access to I18n properties from the main object.
*
* @param Doctrine_Record $record
* @param string $name Name of the property
* @param string $value Value of the property
* @return void
*/
public function filterSet(Doctrine_Record $record, $fieldName, $value)
{
$translation = $record->get('Translation');
$culture = myDoctrineRecord::getDefaultCulture();
if ($translation->contains($culture)) {
$i18n = $record->get('Translation')->get($culture);
} else {
$i18n = $record->get('Translation')->get($culture);
/*
* If translation is new
* populate it with i18n fallback
*/
if ($i18n->state() == Doctrine_Record::STATE_TDIRTY) {
if ($fallback = $record->getI18nFallBack()) {
$fallBackData = $fallback->toArray();
unset($fallBackData['id'], $fallBackData['lang']);
$i18n->fromArray($fallBackData);
}
}
}
if (!ctype_lower($fieldName) && !$i18n->contains($fieldName)) {
$underscoredFieldName = dmString::underscore($fieldName);
if (strpos($underscoredFieldName, '_') !== false && $i18n->contains($underscoredFieldName)) {
$fieldName = $underscoredFieldName;
}
}
$i18n->set($fieldName, $value);
return $value;
}
示例2: updatedAtBy
function updatedAtBy(Doctrine_Record $record)
{
$user = $record->get('UpdatedBy');
if ($user && $user->isNew()) {
$user = null;
}
return format_date($record->get('updated_at'), 'f') . ($user ? ' - ' . $user : '');
}
示例3: doPreSave
protected function doPreSave(Doctrine_Record $record, sfForm $form)
{
// loop through relations
if ($relations = $form->getOption('dynamic_relations')) {
foreach ($relations as $field => $config) {
$collection = $record->get($config['relation']->getAlias());
// collect form objects for comparison
$search = array();
foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
$search[] = $embed->getObject();
}
foreach ($collection as $i => $object) {
if (false === ($pos = array_search($object, $search, true))) {
// if a related object exists in the record but isn't represented
// in the form, the reference has been removed
$collection->remove($i);
// if the foreign column is a notnull columns, delete the object
$column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
$object->delete();
}
}
}
}
}
}
开发者ID:rschumacher,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:26,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例4: get
public function get($name, $load = true)
{
if ($name === 'content') {
return file_get_contents(parent::get('url'));
}
return parent::get($name, $load);
}
示例5: 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;
}
示例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: doPreSave
protected function doPreSave(Doctrine_Record $record, sfForm $form)
{
// loop through relations
if ($relations = $form->getOption('dynamic_relations')) {
foreach ($relations as $field => $config) {
$collection = $record->get($config['relation']->getAlias());
// collect form objects for comparison
$search = array();
try {
foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
$search[] = $embed->getObject();
}
} catch (InvalidArgumentException $e) {
// previously embedded form was removed at the end of form.filter_values as there were no values for it.
// @see sfDoctrineDynamicFormRelations::correctValidators()
}
foreach ($collection as $i => $object) {
$pos = array_search($object, $search, true);
if (false === $pos && $this->filterObject($object, $config['arguments'])) {
// if a related object exists in the record but isn't represented
// in the form, the reference has been removed
$collection->remove($i);
// if the foreign column is a notnull columns, delete the object
$column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
$object->delete();
}
}
}
}
}
}
开发者ID:AUTOPLANNING,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:32,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例8: get
/**
* Get a record attribute. Allows overriding Doctrine record accessors with Propel style functions
*
* @param string $name
* @param string $load
* @return void
*/
public function get($name, $load = true)
{
$getter = 'get' . Doctrine_Inflector::classify($name);
if (method_exists($this, $getter)) {
return $this->{$getter}($load);
}
return parent::get($name, $load);
}
示例9: get
public function get($column, $load = true)
{
$val = parent::get($column, $load);
if (is_resource($val)) {
$val = stream_get_contents($val);
}
if ($col = $this->getTable()->getColumnDefinition($column)) {
if ($col["type"] == 'blob') {
$val = base64_decode($val);
}
}
return $val;
}
示例10: getVersion
/**
* Get the version
*
* @param Doctrine_Record $record
* @param mixed $version
* @return array An array with version information
*/
public function getVersion(Doctrine_Record $record, $version)
{
$className = $this->_options['className'];
$q = new Doctrine_Query();
$values = array();
foreach ((array) $this->_options['table']->getIdentifier() as $id) {
$conditions[] = $className . '.' . $id . ' = ?';
$values[] = $record->get($id);
}
$where = implode(' AND ', $conditions) . ' AND ' . $className . '.' . $this->_options['versionColumn'] . ' = ?';
$values[] = $version;
$q->from($className)->where($where);
return $q->execute($values, Doctrine::HYDRATE_ARRAY);
}
示例11: 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 = $record->get($this->definition['local']);
if (empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$related = $this->getTable()->find($id);
if (!$related) {
$related = $this->getTable()->create();
}
}
$record->set($this->definition['local'], $related, false);
return $related;
}
示例12: 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 = $record->get($this->definition['local']);
if (empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition();
$related = $this->getTable()->getConnection()->query($dql, array($id))->getFirst();
if (!$related || empty($related)) {
$related = $this->getTable()->create();
}
}
$record->set($this->definition['local'], $related, false);
return $related;
}
示例13: getDistance
public function getDistance(Doctrine_Record $record, $kilometers = false)
{
$query = $this->getDistanceQuery($kilometers);
$conditions = array();
$values = array();
foreach ((array) $record->getTable()->getIdentifier() as $id) {
$conditions[] = $query->getRootAlias() . '.' . $id . ' = ?';
$values[] = $record->get($id);
}
$where = implode(' AND ', $conditions);
$query->addWhere($where, $values);
$query->limit(1);
$result = $query->execute()->getFirst();
if (isset($result['kilometers']) && $result['miles']) {
return $kilometers ? $result->get('kilometers') : $result->get('miles');
} else {
return 0;
}
}
示例14: buildIntegrityRelationQuery
public function buildIntegrityRelationQuery(Doctrine_Record $record)
{
$q = new Doctrine_Query();
$aliases = array();
$indexes = array();
$root = $record->getTable()->getComponentName();
$rootAlias = strtolower(substr($root, 0, 1));
$aliases[$rootAlias] = $root;
foreach ((array) $record->getTable()->getIdentifier() as $id) {
$field = $rootAlias . '.' . $id;
$cond[] = $field . ' = ?';
$fields[] = $field;
$params = $record->get($id);
}
$fields = implode(', ', $fields);
$components[] = $root;
$this->buildIntegrityRelations($record->getTable(), $aliases, $fields, $indexes, $components);
$q->select($fields)->from($root . ' ' . $rootAlias);
foreach ($aliases as $alias => $name) {
$q->leftJoin($rootAlias . '.' . $name . ' ' . $alias);
}
$q->where(implode(' AND ', $cond));
return $q->execute(array($params));
}
示例15: getRecordAsXml
/**
* Return a recrd as XML.
*
* In order to control how this is done set the "xml" option in a record.
* This option is an array that has the keys "ignore_fields" and "include_relations". Both of these are arrays that list the name of fields/relations to include/process.
*
* If you want to insert this xml as a part inside another xml send a
* SimpleXMLElement to the function. Because of the nature of SimpleXML the
* content you add to this element will be avilable after the function is
* complete.
*
* @param Doctrine_Record $record
* @param SimpleXMLElement $xml
* @return string Xml as string
*/
public static function getRecordAsXml(Doctrine_Record $record, SimpleXMlElement $incomming_xml = NULL)
{
$recordname = $record->getTable()->tableName;
if (!isset($incomming_xml)) {
$new_xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><" . $recordname . "></" . $recordname . ">";
$xml = new SimpleXMLElement($new_xml_string);
} else {
$xml = $incomming_xml->addChild($recordname);
}
foreach ($record->obtainIdentifier() as $pk_field => $pk_value) {
$xml->addChild($pk_field, $pk_value);
}
$xml_options = $record->option("xml");
if (isset($xml_options["record_name"])) {
$recordname = $xml_options["record_name"];
}
foreach ($record->getData() as $field => $value) {
if (isset($xml_options["ignore_fields"]) && !in_array($field, $xml_options["ignore_fields"]) || !isset($xml_options["ignore_fields"])) {
if ($value instanceof Doctrine_Null) {
$xml->addChild($field);
} else {
$xml->addChild($field, $value);
}
}
}
if (!isset($xml_options["include_relations"])) {
return $xml->asXML();
}
$relations = $record->getTable()->getRelations();
foreach ($relations as $name => $relation) {
if (in_array($name, $xml_options["include_relations"])) {
$relation_type = $relation->getType();
$related_records = $record->get($name);
if ($relation_type == Doctrine_Relation::ONE && $related_records instanceof Doctrine_Record) {
Doctrine_Lib::getRecordAsXml($related_records, $xml);
} else {
Doctrine_Lib::getCollectionAsXml($related_records, $xml);
}
}
}
return $xml->asXML();
}