本文整理汇总了PHP中Doctrine_Event::getInvoker方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Event::getInvoker方法的具体用法?PHP Doctrine_Event::getInvoker怎么用?PHP Doctrine_Event::getInvoker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Event
的用法示例。
在下文中一共展示了Doctrine_Event::getInvoker方法的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: 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);
}
}
示例3: 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.');
}
}
示例4: preDelete
public function preDelete(Doctrine_Event $event)
{
$table = $event->getInvoker()->getTable();
$targets = $this->detectCascadingTargets($table);
foreach ($targets as $target) {
$relations = $event->getInvoker()->{$target}['alias'];
if (!$relations instanceof Doctrine_Collection) {
if (!count($relations)) {
continue;
}
$relations = array($relations);
}
foreach ($relations as $record) {
switch (strtolower($target['delete'])) {
case 'cascade':
if ($record instanceof Doctrine_Record) {
$record->delete();
}
break;
case 'set null':
$record->{$target}['localFrom'] = null;
$record->save();
break;
default:
// do nothing
}
}
}
}
示例5: preUpdate
/**
* preUpdate
*
* @param object $Doctrine_Event
* @return void
*/
public function preUpdate(Doctrine_Event $event)
{
$updatedName = $this->_options['updated']['name'];
$modified = $event->getInvoker()->getModified();
if (!isset($modified[$updatedName])) {
$event->getInvoker()->{$updatedName} = self::getCurrentUserId();
}
}
示例6: postConnect
/**
* Post-connect listener. Will set charset and run init queries if configured.
*
* @param Doctrine_Event The Doctrine event object.
*
* @author David Zülke <david.zuelke@bitextender.com>
* @since 1.0.4
*/
public function postConnect(Doctrine_Event $event)
{
if ($this->database->hasParameter('charset')) {
$event->getInvoker()->setCharset($this->database->getParameter('charset'));
}
foreach ((array) $this->database->getParameter('init_queries') as $query) {
$event->getInvoker()->exec($query);
}
}
示例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)
{
// this listener may have been added several times with a different $form instance
// but as listeners have a model rather than a record scope we need to filter if
// this current listener actually matches!
if ($this->form->getObject()->id == $event->getInvoker()->id) {
$this->doPreSave($event->getInvoker(), $this->form);
}
}
开发者ID:rschumacher,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:17,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例8: preDelete
public function preDelete(Doctrine_Event $event)
{
$id = $event->getInvoker()->getId();
$foreignTableName = $event->getInvoker()->getTable()->getTableName();
$records = Doctrine::getTable('ActivityData')->findByForeignTableAndForeignId($foreignTableName, $id);
if ($records instanceof Doctrine_Collection) {
$records->delete();
}
}
示例9: postSave
/**
* Executes save routine
*/
public function postSave(Doctrine_Event $event)
{
if ($event->getInvoker()->doIndex()) {
try {
$this->saveIndex($event->getInvoker());
} catch (sfException $e) {
// no context define, cannot do anything,
}
}
}
示例10: postInsert
public function postInsert(Doctrine_Event $event)
{
if ('first' === $this->_options['new']) {
$position = $event->getInvoker()->getTable()->createQuery('r')->select('MIN(r.position)')->fetchValue() - 1;
} else {
$position = $event->getInvoker()->get('id');
}
$event->getInvoker()->set('position', $position);
$event->getInvoker()->save();
}
示例11: postValidate
/**
* Checks if the file exists in file system. If it does not exists,
* the validator screams.
*
* @param Doctrine_Event $event
* @return void
*/
public function postValidate(Doctrine_Event $event)
{
if ($this->_options['checkExistence']) {
$file = $event->getInvoker()->getFile();
if (!$file->fileExists()) {
$error_stack = $event->getInvoker()->getErrorStack();
$error_stack->add($this->_options['name'], 'The file does not exist.');
}
}
}
示例12: preUpdate
public function preUpdate(Doctrine_Event $event)
{
$modified = $event->getInvoker()->getModified();
$modified_old = $event->getInvoker()->getModified(true);
if (key_exists('created_by', $modified)) {
$event->getInvoker()->created_by = $modified_old['created_by'];
}
if ($user = sfContext::getInstance()->getUser()) {
$event->getInvoker()->updated_by = $user->getGuardUser() ? $user->getGuardUser()->getId() : null;
} else {
if (key_exists('updated_by', $modified)) {
$event->getInvoker()->updated_by = $modified_old['updated_by'];
}
}
}
示例13: 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());
}
}
}
示例14: preUpdate
public function preUpdate(Doctrine_Event $event)
{
$record = $event->getInvoker();
if ($record->isModified()) {
$this->denormalize($record);
}
}
示例15: 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();
}
}
}
}
}