/** * @param string $instanceName * @param int $limit * @param TimeFrame $timeFrame * * @return array */ private function getMostActiveWatchers($instanceName, $limit, $timeFrame) { $instance = InstanceQuery::create()->findOneByName($instanceName); $query = UserQuery::create()->getMostActiveWatchersQuery($instance); $ignoredUsers = $this->configuration->getInstanceByName($instanceName)->getIgnoredUsers(); $query = $query->filterByLimit($limit); $query = $query->useSubscriptionQuery()->filterByTimeFrame($timeFrame)->endUse(); $query = $query->filterIgnoredUsers($ignoredUsers); return $query->find()->getData(); }
/** * Get the associated ChildInstance object * * @param ConnectionInterface $con Optional Connection object. * @return ChildInstance The associated ChildInstance object. * @throws PropelException */ public function getInstance(ConnectionInterface $con = null) { if ($this->aInstance === null && ($this->instance_name !== "" && $this->instance_name !== null)) { $this->aInstance = ChildInstanceQuery::create()->findPk($this->instance_name, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aInstance->addConnections($this); */ } return $this->aInstance; }
/** * Performs an INSERT on the database, given a Instance or Criteria object. * * @param mixed $criteria Criteria or Instance object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(InstanceTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Instance object } // Set the correct dbName $query = InstanceQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Returns a new ChildInstanceQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildInstanceQuery */ public static function create($modelAlias = null, Criteria $criteria = null) { if ($criteria instanceof ChildInstanceQuery) { return $criteria; } $query = new ChildInstanceQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildInstanceQuery::create(); $criteria->add(InstanceTableMap::COL_NAME, $this->name); return $criteria; }
/** * @param SubscriptionSeenEvent $event * * @throws \Propel\Runtime\Exception\PropelException */ public function onSubscriptionSeen(SubscriptionSeenEvent $event) { $instanceName = $event->getInstance(); $status = $event->getSubscription(); // Ignore certain subscriptions if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) { return; } // Determine the username to store for the subscription $username = $status->username; switch ($status->getType()) { case SubscriptionStatus::TYPE_RECORDING: $username = User::NAME_DVR; break; } // Get the instance, user and channel $instance = InstanceQuery::create()->findPk($instanceName); $user = UserQuery::create()->filterByInstance($instance)->filterByName($username)->findOne(); // Ensure the channel exists $this->onChannelSeen($instanceName, $status->channel); $channel = ChannelQuery::create()->filterByInstance($instance)->filterByName($status->channel)->findOne(); if (SubscriptionQuery::create()->hasSubscription($instance, $user, $channel, $status)) { return; } // Try to determine which input is used by the subscription $input = InputQuery::create()->filterBySubscriptionStatus($instanceName, $status)->findOne(); if ($input === null) { $this->logger->warning('Got subscription that cannot be tied to an input ({instanceName}, user: {userName}, channel: {channelName})', ['instanceName' => $instanceName, 'userName' => $user !== null ? $user->getName() : 'N/A', 'channelName' => $channel->getName()]); } $subscription = new Subscription(); $subscription->setInstance($instance)->setInput($input)->setUser($user)->setChannel($channel)->setSubscriptionId($status->id)->setStarted($status->start)->setTitle($status->title)->setService($status->service); $subscription->save(); $this->logger->info('Stored new subscription (instance: {instanceName}, user: {userName}, channel: {channelName})', ['instanceName' => $instanceName, 'userName' => $user !== null ? $user->getName() : 'N/A', 'channelName' => $channel->getName()]); }