本文整理汇总了PHP中Doctrine\ODM\MongoDB\Event\LifecycleEventArgs::getDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getDocument方法的具体用法?PHP LifecycleEventArgs::getDocument怎么用?PHP LifecycleEventArgs::getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
的用法示例。
在下文中一共展示了LifecycleEventArgs::getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLoad
/**
* Hydrates the given node
* @param LifecycleEventArgs $eventArgs
*/
public function postLoad(LifecycleEventArgs $eventArgs)
{
if ($eventArgs->getDocument() instanceof Node) {
/*
* Loading users and group inside the current Node
* Using an event suscriber to allow these objects to come from many places
*/
$node = $eventArgs->getDocument();
$groupId = $node->getGroupId();
/*
* If netBS
*
if(!is_null($groupId))
$node->setGroup($this->em->getRepository('AppBundle:Groupe')->find($groupId));
foreach($node->getUsersId() as $id)
$node->addUser($this->em->getRepository('InterneSecurityBundle:User')->find($id));
*/
/*
* If colibri
*/
foreach ($node->getUsersId() as $id) {
$user = $eventArgs->getDocumentManager()->getRepository('ColibriUserBundle:User')->find($id);
$node->addUser($user);
}
}
}
示例2: postLoad
public function postLoad(\Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs)
{
if (!$eventArgs->getDocument() instanceof \Bpi\ApiBundle\Domain\Entity\Author) {
return;
}
$author = $eventArgs->getDocument();
$author->loadAgency($eventArgs->getDocumentManager()->getRepository('BpiApiBundle:Aggregate\\Agency'));
}
示例3: postRemove
public function postRemove(LifecycleEventArgs $eventArgs)
{
if ($eventArgs->getDocument() instanceof Image) {
/* @var Image $image */
$image = $eventArgs->getDocument();
try {
$this->imageManager->delete($image, 'uploads');
} catch (FileException $e) {
$this->logger->error('PostRemoveListener: Error while deleting image ' . $image->getFileName() . ' Error: ' . $e->getMessage());
}
}
}
示例4: postUpdate
public function postUpdate(LifecycleEventArgs $arg)
{
if (!$this->container->isScopeActive('request')) {
return;
}
if (!$this->container->get('security.context')->getToken()->isAuthenticated()) {
return;
}
if ($arg->getDocument() instanceof Document\Article) {
if ($arg->getDocument()->wereTranslationsModified()) {
$this->notifyModification($arg->getDocument(), $arg->getDocumentManager());
}
}
}
示例5: postRemove
public function postRemove(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if ($document instanceof $this->objectClass) {
$this->removeIfScheduled($document);
}
}
示例6: preUpdate
public function preUpdate(LifecycleEventArgs $args)
{
$document = $args->getDocument();
// perhaps you only want to act on some "Product" document
if ($document instanceof Project) {
$dm = $args->getDocumentManager();
$document->setDateUpdated(new \DateTime("now"));
$class = $dm->getClassMetadata("Zeega\\DataBundle\\Document\\Project");
if ($args->hasChangedField("tags")) {
$update = true;
$oldTags = $args->getOldValue('tags');
foreach ($oldTags as $tag) {
$name = $tag->getName();
$id = $tag->getId();
if ($name == 'homepage' && $id !== null) {
$update = false;
break;
}
}
if ($update === true) {
$document->setDateTagsUpdated(new \DateTime("now"));
}
}
$dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document);
}
}
示例7: prePersist
/**
* @param LifecycleEventArgs $event
*/
public function prePersist(LifecycleEventArgs $event)
{
$document = $event->getDocument();
$className = get_class($document);
$generateAnnotations = $this->annotationReader->getClassAnnotation(new \ReflectionClass($className), 'OpenOrchestra\\Mapping\\Annotations\\Document');
if (!is_null($generateAnnotations)) {
$repository = $this->container->get($generateAnnotations->getServiceName());
$getSource = $generateAnnotations->getSource($document);
$getGenerated = $generateAnnotations->getGenerated($document);
$setGenerated = $generateAnnotations->setGenerated($document);
$testMethod = $generateAnnotations->getTestMethod();
if ($testMethod === null && $repository instanceof FieldAutoGenerableRepositoryInterface) {
$testMethod = 'testUniquenessInContext';
}
if (is_null($document->{$getGenerated}())) {
$source = $document->{$getSource}();
$source = Inflector::tableize($source);
$sourceField = $this->suppressSpecialCharacterHelper->transform($source);
$generatedField = $sourceField;
$count = 1;
while ($repository->{$testMethod}($generatedField)) {
$generatedField = $sourceField . '-' . $count;
$count++;
}
$document->{$setGenerated}($generatedField);
}
}
}
示例8: preUpdate
/**
* @param LifecycleEventArgs $event
*/
public function preUpdate(LifecycleEventArgs $event)
{
if (!($object = $event->getDocument()) instanceof ContentInterface || in_array($object->getContentId(), $this->contentManaged)) {
return;
}
$this->contentManaged[] = $object->getContentId();
$contents = $this->getContentRepository()->findByContentId($object->getContentId());
$contentType = $this->getContentTypeRepository()->findOneByContentTypeIdInLastVersion($object->getContentType());
/** @var ContentInterface $content */
foreach ($contents as $content) {
if ($content != $object) {
foreach ($this->immutableData as $immutableData) {
$getter = $this->generateGetter($immutableData, $object);
$setter = 'set' . ucfirst($immutableData);
$content->{$setter}($object->{$getter}());
}
/** @var FieldTypeInterface $field */
foreach ($contentType->getFields() as $field) {
if (!$field->isTranslatable()) {
$contentAttribute = $this->getContentAttribute($content, $field->getFieldId());
$contentAttribute->setValue($object->getAttributeByName($field->getFieldId())->getValue());
}
}
}
$event->getDocumentManager()->flush($content);
}
}
开发者ID:open-orchestra,项目名称:open-orchestra-model-bundle,代码行数:30,代码来源:UpdateNonTranslatableContentFieldsListener.php
示例9: preRemove
public function preRemove(LifecycleEventArgs $args)
{
$dm = $args->getDocumentManager();
$currentDocument = $args->getDocument();
$currentDocumentClass = get_class($currentDocument);
$isRefExists = FALSE;
$documentClassNames = $dm->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
foreach ($documentClassNames as $documentClassName) {
try {
$cm = $dm->getClassMetadata($documentClassName);
foreach ($cm->getAssociationNames() as $associationName) {
if ($currentDocumentClass == $cm->getAssociationTargetClass($associationName) || is_subclass_of($currentDocumentClass, $cm->getAssociationTargetClass($associationName))) {
$searchObj = $dm->getRepository($documentClassName)->findOneBy(array($associationName . '.$id' => new \MongoId($currentDocument->getId())));
if ($searchObj) {
$isRefExists = TRUE;
}
}
}
} catch (\Exception $e) {
}
}
if ($isRefExists) {
throw new \Exception('ref_erro');
}
}
示例10: postLoad
/**
* @param LifecycleEventArgs $eventArgs
* @since 0.28
*/
public function postLoad(LifecycleEventArgs $eventArgs)
{
$entity = $eventArgs->getDocument();
if ($entity instanceof AttachableEntityInterface) {
$this->injectAttachableEntityManager($entity);
}
}
示例11: prePersist
/**
* @param LifecycleEventArgs $args
*/
public function prePersist($args)
{
$object = $args->getDocument();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
示例12: preUpdate
public function preUpdate(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if (!$document instanceof SearchableEntityInterface) {
return;
}
$dm = $eventArgs->getDocumentManager();
$uow = $dm->getUnitOfWork();
$changeset = $uow->getDocumentChangeset($document);
$filter = $this->getKeywordsFilter();
$keywords = array();
$mustUpdate = false;
foreach ($document->getSearchableProperties() as $name) {
if (isset($changeset[$name])) {
$mustUpdate = true;
break;
}
}
if (!$mustUpdate) {
return;
}
$keywords = $filter->filter($document);
$document->setKeywords($keywords);
$uow->recomputeSingleDocumentChangeSet($dm->getClassMetadata(get_class($document)), $document);
}
示例13: setPath
/**
* @param LifecycleEventArgs $eventArgs
*/
public function setPath(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if ($document instanceof NodeInterface && false === $document->isDeleted()) {
$nodeRepository = $this->container->get('open_orchestra_model.repository.node');
$nodeId = $document->getNodeId();
$siteId = $document->getSiteId();
$language = $document->getLanguage();
$path = '';
$parentNode = $nodeRepository->findInLastVersion($document->getParentId(), $document->getLanguage(), $siteId);
if ($parentNode instanceof NodeInterface) {
$path = $parentNode->getPath() . '/';
}
$path .= $nodeId;
if ($path != $document->getPath()) {
$document->setPath($path);
$this->nodes[] = $document;
$childNodes = $nodeRepository->findSubTreeByPath($document->getPath(), $siteId, $language);
foreach ($childNodes as $childNode) {
$this->nodes[] = $childNode;
$childNode->setPath(preg_replace('/' . preg_quote($document->getPath(), '/') . '(.*)/', $path . '$1', $childNode->getPath()));
}
}
}
}
示例14: postUpdate
public function postUpdate(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if ($document instanceof MODM67EmbeddedObject) {
$document->postUpdate = true;
}
}
示例15: prePersist
/**
* Set object creator & updater
*
* @param LifecycleEventArgs $args The event arguments
*/
public function prePersist(LifecycleEventArgs $args)
{
$obj = $args->getDocument();
$blameable = $this->driver->getBlameableAnnotation($obj);
if (null !== $blameable) {
$this->updateEntity($obj, $blameable, true);
}
}