Toggle visibility for an object

@param ModelCriteria               $query
@param ToggleVisibilityEvent $event
@param EventDispatcherInterface $dispatcher

@return mixed
161927
public function genericToggleVisibility(ModelCriteria $query, ToggleVisibilityEvent $event, EventDispatcherInterface $dispatcher = null)
    {
        if (null !== $object = $query->findPk($event->getObjectId())) {
            $newVisibility = !$object->getVisible();
            $object
                //for backward compatibility
                ->setDispatcher($dispatcher !== null ? $dispatcher : $event->getDispatcher())
                ->setVisible($newVisibility)
                ->save()
            ;

            $event->setObject($object);
        }

        return $object;
    }
322921
public function onSaveJobResultQuery(
        QueueSaveJobResultEvent $event,
        $eventName,
        EventDispatcherInterface $dispatcher
    ) {
        $table          = $event->getQueueTable();
        $field          = $event->getField();
        $data           = urlencode(serialize($event->getData()));
        $id             = $event->getId();
        $query          = "UPDATE $table SET $field = '$data' WHERE id = $id";
        $event->setQuery($query);
    }
1213912
public function onAddToQueueListenerQuery(AddToQueueEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $query          = $event->getQuery();
        $eventToSave    = $event->getEvent();
        $eventToSave    = serialize($eventToSave);
        $eventToSave    = urlencode($eventToSave);  // Ohne urlencode speichert Contao das serialisierte Event nicht!
        $kind           = $event->getKind();
        $priotity       = $event->getPriority();
        $srcmodule      = $event->getSrcmodule();
        $srctable       = $event->getSrctable();
        $srcid          = $event->getSrcid();
        $interval       = $event->getIntervalkind();
        $query         .= "tstamp = " . time();
        $query         .= ", kind = '$kind'";
        $query         .= ", priority = $priotity";
        $query         .= ", data = '$eventToSave'";
        $query         .= ", srcmodule = '$srcmodule'";
        $query         .= ", srcid = $srcid";
        $query         .= ", srctable = '$srctable'";
        $query         .= ", intervalkind = '$interval'";
        $event->setQuery($query);
    }
512993
public function toggleActivity(SaleToggleActivityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $sale = $event->getSale();

        $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);

        $con->beginTransaction();

        try {
            $sale
            ->setDispatcher($dispatcher)
            ->setActive(!$sale->getActive())
            ->save($con);

            // Update related products sale status
            $dispatcher->dispatch(
                TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                new ProductSaleStatusUpdateEvent($sale)
            );

            $event->setSale($sale);

            $con->commit();
        } catch (PropelException $e) {
            $con->rollback();
            throw $e;
        }
    }
1314605
function setHideServer($visibility, $multicall = false)
    {
        if (!is_int($visibility) || $visibility < 0 || $visibility > 2) {
            throw new InvalidArgumentException('visibility = ' . print_r($visibility, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($visibility), $multicall);
    }
848182
public function updateAccessoryPosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        return $this->genericUpdatePosition(AccessoryQuery::create(), $event, $dispatcher);
    }
758529
public function updateCondition(CouponCreateOrUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $modelCoupon = $event->getCouponModel();

        $this->createOrUpdateCondition($modelCoupon, $event, $dispatcher);
    }
932914
protected function genericUpdateSeo(ModelCriteria $query, UpdateSeoEvent $event, EventDispatcherInterface $dispatcher = null)
    {
        if (null !== $object = $query->findPk($event->getObjectId())) {
            $object
                //for backward compatibility
                ->setDispatcher($dispatcher !== null ? $dispatcher : $event->getDispatcher())

                ->setLocale($event->getLocale())
                ->setMetaTitle($event->getMetaTitle())
                ->setMetaDescription($event->getMetaDescription())
                ->setMetaKeywords($event->getMetaKeywords())

                ->save()
            ;

            // Update the rewritten URL, if required
            try {
                $object->setRewrittenUrl($event->getLocale(), $event->getUrl());
            } catch (UrlRewritingException $e) {
                throw new FormValidationException($e->getMessage(), $e->getCode());
            }

            $event->setObject($object);
        }

        return $object;
    }
972466
public function onSetStartTimeListenerQuery(
        QueueSetStartTimeEvent $event,
        $eventName,
        EventDispatcherInterface $dispatcher
    ) {
        $table          = $event->getQueueTable();
        $field          = $event->getField();
        $id             = $event->getId();
        $query          = "UPDATE $table SET $field = " . time() . " WHERE id = $id";
        $event->setQuery($query);
    }
600542
public function scopeWhereSubjectVisibleTo(Builder $query, User $actor)
    {
        $query->where(function ($query) use ($actor) {
            $classes = [];

            foreach (static::$subjectModels as $type => $class) {
                $classes[$class][] = $type;
            }

            foreach ($classes as $class => $types) {
                $query->orWhere(function ($query) use ($types, $class, $actor) {
                    $query->whereIn('type', $types)
                        ->whereExists(function ($query) use ($class, $actor) {
                            $query->selectRaw(1)
                                ->from((new $class)->getTable())
                                ->whereColumn('id', 'subject_id');

                            static::$dispatcher->dispatch(
                                new ScopeModelVisibility($class::query()->setQuery($query), $actor, 'view')
                            );
                        });
                });
            }
        });
    }
1018856
public function batchActionToggleEnabled($query)
    {
        $this->admin->checkAccess('batchToggleEnabled');

        $snapshotManager = $this->get('sonata.page.manager.snapshot');
        foreach ($query->getQuery()->iterate() as $snapshot) {
            $snapshot[0]->setEnabled(!$snapshot[0]->getEnabled());
            $snapshotManager->save($snapshot[0]);
        }

        return new RedirectResponse($this->admin->generateUrl('list'));
    }
252555
public function recursiveActivation(ModuleToggleActivationEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $module = ModuleQuery::create()->findPk($event->getModuleId())) {
            $moduleValidator = new ModuleValidator($module->getAbsoluteBaseDir());
            $dependencies = $moduleValidator->getCurrentModuleDependencies();
            foreach ($dependencies as $defMod) {
                $submodule = ModuleQuery::create()
                    ->findOneByCode($defMod["code"]);
                if ($submodule && $submodule->getActivate() != BaseModule::IS_ACTIVATED) {
                    $subevent = new ModuleToggleActivationEvent($submodule->getId());
                    $subevent->setRecursive(true);
                    $dispatcher->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $subevent);
                }
            }
        }
    }
522437
protected function scopeVisibleTo(Builder $query, User $user = null)
    {
        if ($user !== null && !$user->isAdmin()) {
            $query->whereIsHidden(0);
        }

        return $query;
    }
1315792
public function bind(EventDispatcherInterface $dispatcher, $eventName)
    {
        if (isset($this->events[$eventName])) {
            return;
        }

        $dispatcher->addListener($eventName, $this->getListener(), $this->priority);
        $this->events[$eventName] = true;
    }
1017688
public function onLoadQueueListenerQuery(LoadQueueEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $kind           = $event->getKind();
        $table          = $event->getQueueTable();
        $count          = $event->getCount();
        $query          = "SELECT * FROM $table WHERE ";
        $query         .= " kind = '$kind'";
        $query         .= " AND endworking = 0";
        $query         .= " AND startworking = 0";
        $query         .= " AND (intervaltorun != 0 OR intervaltorun = '')";
        $query         .= " ORDER BY priority, id";
        $query         .= " LIMIT 0,$count";
        $event->setQuery($query);
    }
1368920
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
		$query->formatResults(function (CollectionInterface $results) {
			return $results->map(function ($row) {
				if (!$row instanceOf Entity) {
					return $row;
				}

				$this->decodeItems($row);
				return $row;
			});
		});
	}
612518
public function getSessionCart(EventDispatcherInterface $dispatcher = null)
    {
        $cart_id = $this->get("thelia.cart_id", null);
        if (null !== $cart_id) {
            $cart = CartQuery::create()->findPk($cart_id);
        } else {
            $cart = self::$transientCart;
        }

        // If we do not have a cart, or if the current cart is nor valid
        // restore it from the cart cookie, or create a new one
        if (null === $cart || ! $this->isValidCart($cart)) {
            // A dispatcher is required here. If we do not have it, throw an exception
            // This is a temporary workaround to ensure backward compatibility with getCart(),
            // When genCart() will be removed, this check should be removed, and  $dispatcher should become
            // a required parameter.

            if (null == $dispatcher) {
                throw new \InvalidArgumentException(
                    "In this context (no cart in session), an EventDispatcher should be provided to Session::getSessionCart()."
                );
            }

            $cartEvent = new CartRestoreEvent();

            if (null !== $cart) {
                $cartEvent->setCart($cart);
            }

            $dispatcher->dispatch(TheliaEvents::CART_RESTORE_CURRENT, $cartEvent);

            if (null === $cart = $cartEvent->getCart()) {
                throw new \LogicException(
                    "Unable to get a Cart."
                );
            }

            // Store the cart.
            $this->setSessionCart($cart);
        }

        return $cart;
    }