本文整理汇总了PHP中Doctrine_Event类的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Event类的具体用法?PHP Doctrine_Event怎么用?PHP Doctrine_Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Doctrine_Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _createOperationLog
/**
* Creates a new logging instance.
*
* @param Doctrine_Event $event Event.
* @param int $opType I/U/D for Insert/Update/Delete.
*
* @return void
*/
private function _createOperationLog(Doctrine_Event $event, $opType = 'I')
{
$data = $event->getInvoker();
$tableName = $this->getTableNameFromEvent($event);
$idColumn = $this->getIdColumnFromEvent($event);
$log = array();
$log['object_type'] = $tableName;
$log['object_id'] = $data[$idColumn];
$log['op'] = $opType;
if ($opType == 'U') {
$oldValues = $data->getLastModified(true);
$diff = array();
foreach ($oldValues as $column => $oldValue) {
if (empty($oldValue) && isset($data[$column]) && !empty($data[$column])) {
$diff[$column] = 'I: ' . $data[$column];
} elseif (!empty($oldValue) && isset($data[$column]) && !empty($data[$column])) {
$diff[$column] = 'U: ' . $data[$column];
} elseif (!empty($oldValue) && empty($data[$column])) {
$diff[$column] = 'D: ' . $oldValue;
}
}
$log['diff'] = serialize($diff);
} else {
// Convert object to array (otherwise we serialize the record object)
$log['diff'] = serialize($data->toArray());
}
DBUtil::insertObject($log, 'objectdata_log');
}
示例2: preStmtExecute
public function preStmtExecute(Doctrine_Event $event)
{
// Check if the administrator has enabled the query logging feature
if (Settings::findbyParam('debug_queries')) {
$breadcrumps = array();
$query = $event->getQuery();
$params = $event->getParams();
$callers = array_reverse(debug_backtrace(), true);
$callers = array_slice($callers, 4, count($callers) - 10);
foreach ($callers as $caller) {
$class = !empty($caller['class']) ? $caller['class'] : null;
$breadcrumps[] = $class . "->" . $caller['function'];
}
$strBreadcrump = "System: " . implode(" / ", $breadcrumps);
//the below makes some naive assumptions about the queries being logged
while (sizeof($params) > 0) {
$param = array_shift($params);
if (!is_numeric($param)) {
$param = sprintf("'%s'", $param);
}
$query = substr_replace($query, $param, strpos($query, '?'), 1);
}
Shineisp_Commons_Utilities::log($query, "queries.log");
Shineisp_Commons_Utilities::log($strBreadcrump, "debug.log", Zend_Log::DEBUG);
// Increase query counter
$queryCount = Shineisp_Registry::isRegistered('querycount') ? Shineisp_Registry::get('querycount') : 0;
$queryCount = $queryCount + 1;
Shineisp_Registry::set('querycount', $queryCount);
}
}
示例3: preUpdate
/**
* @param Doctrine_Event $event
*/
public function preUpdate(Doctrine_Event $event)
{
$record = $event->getInvoker();
$modified = $record->getModified();
$original = $record->getModified(true);
foreach ($this->Slices as &$slice) {
if (array_key_exists('title', $modified)) {
if ($slice->title == $original['title'] || $slice->title == null) {
$slice->title = $modified['title'];
}
}
if (array_key_exists('slug', $modified)) {
if ($slice->slug == $original['slug'] || $slice->slug == null) {
$slice->slug = $modified['slug'];
}
}
if (array_key_exists('description', $modified)) {
if ($slice->caption == $original['description'] || $slice->caption == null) {
$slice->caption = $modified['description'];
}
}
if (array_key_exists('published', $modified) && $modified['published'] == false && $original['published'] == true) {
$slice->published = false;
}
if (array_key_exists('published', $modified) && $modified['published'] == true && $original['published'] == false && RokGallery_Config::getOption(RokGallery_Config::OPTION_SLICE_AUTOPUBLISH_ON_FILE_PUBLISH, false)) {
$slice->published = true;
}
}
if (array_key_exists('manipulations', $modified)) {
$this->processImages();
}
}
示例4: preDqlDelete
public function preDqlDelete(Doctrine_Event $event)
{
$params = $event->getParams();
$tmpQuery = clone $event->getQuery();
$subQuery = $tmpQuery->select($params['alias'] . '.' . $params['component']['table']->getIdentifier())->getDql();
if (!in_array($params['alias'], $tmpQuery->getDqlPart('from'))) {
return false;
}
$targets = $this->detectCascadingTargets($params['component']['table']);
foreach ($targets as $target) {
$table = Doctrine::getTable($target['table']);
$relation = $table->getRelation($target['aliasFrom']);
$localField = $relation->getLocalFieldName();
$q = $table->createQuery();
$q = $q->where($q->getRootAlias() . '.' . $localField . ' IN (' . $subQuery . ')');
switch (strtolower($target['delete'])) {
case 'cascade':
$q->delete()->execute();
break;
case 'set null':
$q->update()->set($localField, '?', array(null))->execute();
break;
default:
// do nothing
}
}
}
示例5: preUpdate
/**
* preUpdate
*
* @param object $Doctrine_Event
* @return void
*/
public function preUpdate(Doctrine_Event $event)
{
if (!$this->_options['updated']['disabled']) {
$updatedName = $this->_options['updated']['name'];
$event->getInvoker()->{$updatedName} = $this->getTimestamp('updated');
}
}
示例6: preSave
/**
* Throws an exception if the record is modified while it is
* locked.
*
* @param Doctrine_Event $event
* @return void
*/
public function preSave(Doctrine_Event $event)
{
$modelName = Doctrine_Inflector::tableize(get_class($event->getInvoker()));
$modifiedFields = $event->getInvoker()->getModified();
$locked = $event->getInvoker()->isLocked;
$lockModified = array_key_exists('isLocked', $modifiedFields);
$numModified = count($modifiedFields);
/**
* Record fields haven't been modified, nothing to do here.
*/
if (!$event->getInvoker()->isModified()) {
return;
}
/**
* The record is not locked, and the lock isn't being changed, nothing to do here.
*/
if (!$locked && !$lockModified) {
return;
}
/**
* Only the lock is being modified so there's nothing to
* do here.
*/
if ($lockModified && $numModified == 1) {
return;
}
/**
* The record is locked, throw an exception.
*/
if ($locked) {
throw new Behavior_Lockable_Exception('The record must be unlocked before it can be modified.');
}
}
示例7: preSave
/**
* Pre-save logic.
*
* Use preSave instead of preUpdate since the latter depends on the record's
* state, which isn't necessarily dirty.
*
* @see Doctrine_Record_Listener
*/
public function preSave(Doctrine_Event $event)
{
// loop through relations
if ($relations = $this->form->getOption('dynamic_relations')) {
foreach ($relations as $field => $config) {
// collect form objects for comparison
$search = array();
foreach ($this->form->getEmbeddedForm($field)->getEmbeddedForms() as $embed) {
$search[] = $embed->getObject();
}
$collection = $event->getInvoker()->get($config['relation']->getAlias());
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:kriswallsmith,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:34,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例8: preUpdate
/**
* Pre update event hook for inserting new version record
* This will only insert a version record if the auditLog is enabled
*
* @param Doctrine_Event $event
* @return void
*/
public function preUpdate(Doctrine_Event $event)
{
$disabled = $event->getInvoker()->hasMappedValue('disable_versioning') ? $event->getInvoker()->get('disable_versioning') : false;
if (!$disabled) {
parent::preUpdate($event);
}
}
示例9: __construct
public function __construct(Doctrine_Event $event, $when, $action, $parameters = array())
{
$invoker = $event->getInvoker();
$parameters['record'] = $invoker;
parent::__construct($invoker, sprintf('op_doctrine.%s_%s_%s', $when, $action, get_class($invoker)), $parameters);
$this->doctrineEvent = $event;
}
示例10: preSave
public function preSave(Doctrine_Event $event)
{
$invoker = $event->getInvoker();
$template = $invoker->getTable()->getTemplate('Doctrine_Template_GoogleI18n');
$options = $template->getOptions();
// get the first langauge that was changed
foreach ($invoker->Translation as $lang => $translation) {
if ($translation->isModified()) {
$from = $lang;
break;
}
}
// skip if no translation was updated
if (!isset($from)) {
return true;
}
foreach ($options['languages'] as $to) {
if ($to == $from) {
continue;
}
foreach ($invoker->Translation[$to] as $field => $value) {
if ($invoker->Translation->getTable()->isIdentifier($field)) {
continue;
}
$fromValue = $invoker->Translation[$from]->{$field};
if ($options['skipEmpty'] && !$fromValue) {
continue;
}
$translatedValue = $template->getTranslation($from, $to, $fromValue);
$invoker->Translation[$to]->{$field} = $translatedValue;
}
}
}
示例11: preSave
/**
* preSave.
*
* @param Doctrine_Event $event
*/
public function preSave($event)
{
$record = $event->getInvoker();
if ($record->isNew()) {
$file = $record->getFilename();
if ($file != basename($file) && is_file($file)) {
$fs = new lyMediaFileSystem();
$dest_path = $record->getFolderPath();
$dest_file = $fs->generateUniqueFileName($dest_path, basename($file));
$fs->import($file, $dest_path . $dest_file);
$record->setType(mime_content_type($file));
$record->setFilename($dest_file);
}
if ($record->supportsThumbnails()) {
lyMediaTools::generateThumbnails($record->getFolderPath(), $record->getFilename());
}
} else {
$modified = $record->getModified(true);
if (isset($modified['folder_id']) || isset($modified['filename'])) {
//Selected new folder or edited filename: move/rename asset
$dest_folder = Doctrine::getTable('lyMediaFolder')->find($record->getFolderId());
$src_folder = $dest_folder;
if (isset($modified['folder_id'])) {
$src_folder = Doctrine::getTable('lyMediaFolder')->find($modified['folder_id']);
}
$src = $src_folder->getRelativePath() . (isset($modified['filename']) ? $modified['filename'] : $record->getFileName());
$dest = $dest_folder->getRelativePath() . $record->getFileName();
$fs = new lyMediaFileSystem();
$fs->rename($src, $dest, $record->supportsThumbnails());
}
}
}
示例12: preUpdate
public function preUpdate(Doctrine_Event $event)
{
$record = $event->getInvoker();
if ($record->isModified()) {
$this->denormalize($record);
}
}
示例13: preSave
public function preSave(Doctrine_Event $event)
{
$invoker = $event->getInvoker();
$modified = $invoker->getModified();
if ($invoker->isNew()) {
// Check if the model is spam
$akismet = $this->getAkismet($invoker);
if ($akismet && (is_bool($akismet) || $akismet->isCommentSpam())) {
$invoker->is_not_spam = false;
$invoker->is_active = false;
} else {
$invoker->is_not_spam = true;
}
} else {
if (isset($modified['is_not_spam'])) {
$akismet = $this->getAkismet($invoker);
if ($akismet) {
if (!$invoker->is_not_spam) {
$akismet->submitSpam();
} else {
$akismet->submitHam();
}
}
}
}
}
示例14: postDelete
/**
* Deletes the object
*/
public function postDelete(Doctrine_Event $event)
{
try {
$this->deleteIndex($event->getInvoker());
} catch (sfException $e) {
// no context define, cannot do anything
}
}
示例15: preSave
/**
* Set the geocodes automatically when a locatable object's locatable fields are modified
*
* @param Doctrine_Event $event
* @return void
* @author Brent Shaffer
*/
public function preSave(Doctrine_Event $event)
{
$object = $event->getInvoker();
$modified = array_keys($object->getModified());
if (array_intersect($this->_options['fields'], $modified)) {
$object->refreshGeocodes();
}
}