Get number of unique beacons given an event and a set of dates.

@param string $token Event
@param string $event Token
@param array  $dates Dates

@return int Number of hits
552307
public function getBeaconsUnique($token, $event, array $dates)
    {
        $keys = [];

        foreach ($dates as $date) {
            $keys[] = $this->generateEntryKey(
                    $token,
                    $event,
                    $date
                ) . '_unique';
        }

        return (int)
        $this->doRedisQuery(function () use ($keys) {
            $this
                ->redis
                ->pfCount($keys);
        }, 0);
    }
115569
public function heartbeats($date, $show = null)
    {
        if ($show !== null) {
            $show = "&show={$show}";
        }

        return $this->makeRequest("users/current/heartbeats?date={$date}" . $show);
    }
288797
public static Integer getRemainingDayOfSeason(Date date) {

        if (date == null)
            return null;

        return getDayNumOfSeason(date) - getDayOfSeason(date);
    }
780021
public function getEmailByToken($token)
    {
        $reminder = $this->getReminder()
            ->where('token', '=', $token)
            ->where('created_at', '>=', $this->getOldestValidDate())
            ->first();

        return $reminder->email;
    }
544098
private function filterTokensByClass(array $tokens, $tokenClass)
    {
        return array_filter(
            $tokens,
            function (Token $token) use ($tokenClass) {
                return get_class($token) === $tokenClass;
            }
        );
    }
590815
public function date($token, $_params = array()) 
	{
        return $this->transform($this->master->get('availability/' . $token . '/date', $_params), true);
    }
1044541
protected function countGroupClose(Array $tokens)
	{
		return array_reduce($tokens, function ($carry, $item) {
			return $carry += $item instanceof Token\Group\Close;
		}, 0);
	}
401975
public function onKernelRequestAuthToken($event)
  {
    if (!$event->isMasterRequest()) return;
    
    // Bearer jwt
    $auth = $event->getRequest()->getHeaderLine('Authorization');
    if (!$auth) return;
    
    $authParts = explode(' ',$auth);
    $jwt = $authParts[count($authParts)-1];
    
    if (!$jwt) return;

    $jwtPayload = $this->jwtCoder->decode($jwt);
    
    $authToken = new AuthToken($jwtPayload['username'],$jwtPayload['roles']);
    
    $event->getRequest()->setAttribute('authToken',$authToken);
  }
736896
public function getAllEventsHook($allEvents, $calendars, $start, $end, $module)
	{
		if (!($permissions = static::checkLogin()) || !in_array('beModules', $permissions)) {
			return $allEvents;
		}

		foreach ($allEvents as $key => $days) {
			foreach ($days as $day => $events) {
				foreach ($events as $index => $event) {
					$allEvents[$key][$day][$index]['class'] =
						(empty($event['class']) ? '' : $event['class'])
						. ' rsfh-event-' . $event['id'];
				}
			}
		}

		return $allEvents;
	}
1347410
@SuppressWarnings("ConstantConditions")
    @Beta
    public static int countToken(@Nullable String target, String token) {
        checkArgument(token != null && !token.isEmpty(), "Expected non-empty token, got: '%s'", token);

        if (isNullOrEmpty(target)) {
            return 0;
        }

        int count = 0;
        int tokenIndex = 0;
        while ((tokenIndex = target.indexOf(token, tokenIndex)) != -1) {
            count++;
            tokenIndex += token.length();
        }
        return count;
    }
722546
private function getEventCount(array $events): int
    {
        $query = DB::table('dates')
            ->where('d_file', '=', $this->tree->id());

        $no_types = [
            'HEAD',
            'CHAN',
        ];

        if ($events) {
            $types = [];

            foreach ($events as $type) {
                if (strncmp($type, '!', 1) === 0) {
                    $no_types[] = substr($type, 1);
                } else {
                    $types[] = $type;
                }
            }

            if ($types) {
                $query->whereIn('d_fact', $types);
            }
        }

        return $query->whereNotIn('d_fact', $no_types)
            ->count();
    }
947853
protected function recurseArrayForTokens($arr, $tokens)
    {
        $out = [];
        foreach ($arr as $name => $value) {
            if (is_array($value)) {
                $out[$name] = $this->recurseArrayForTokens($value, $tokens);
                continue;
            }
            if (is_string($value)) {
                foreach ($tokens as $token => $tval) {
                    $value = str_replace($token, $tval, $value);
                }
                $out[$name] = $value;
                continue;
            }
            $out[$name] = $value;
        }

        return $out;
    }
895634
public function findNextTokenPosition($tokenId, $apos = null) {
		if ($apos === null) {
			$pos = $this->getCurrentPosition();
		} else {
			$pos = $apos;
		}
		$pos += 1; // Start from the token following the current position

		$nbTokens = count($this->tokens);
		while ($pos < $nbTokens) {
			$token = $this->tokens[$pos];

			if ($tokenId === $token->id) {
				return $pos;
			}

			$pos ++;
		}

		return null;
	}
1242989
public function getMulti(array $keys, array &$tokens = null)
    {
        $values = $this->transaction->getMulti($keys, $tokens);

        $missing = array_diff_key($values, $this->local->getMulti($keys));
        if (!empty($missing)) {
            $this->local->setMulti($missing);
        }

        return $values;
    }
936238
public static function create(array $tokens, $content) {
        if (empty($content) || !is_array($content)) return [];
        return empty($content[0]) ? SelectSingleResult::create($tokens, $content) : SelectAllResult::create($tokens, $content);
    }
1027441
public function timelineFriends($token, $number = null)
    {
        $params = array(
            'token' => $token
        );

        // handle number parameter
        if (!is_null($number)) {
            if (!ctype_digit((string)$number) || (0 === $number) || (100 < $number)) {
                throw new \InvalidArgumentException('Invalid number parameter');
            }
            $params['number'] = $number;
        }

        return $this->query('timeline/friends.json', $params);
    }
36169
public function generateOccurrences(Array $events, \DateTime $fromDate, \DateTime $toDate, $limit = null)
	{
		$return = array();
		$object = $this;

		$weeklyEvents = array_filter($events, function ($event) use ($object) {
			return $event->getRecurrenceType() === $object->getLabel();
		});

		foreach ($weeklyEvents as $weeklyEvent) {
			$weeklyEventTime = $weeklyEvent->getStartDate()->format('H:i:s');

			// Retrieve the day of the week that the event takes place on
			$day = $weeklyEvent->getStartDate()->format('w');

			$startMarker = $fromDate > $weeklyEvent->getStartDate()
				? clone($fromDate)
				: clone($weeklyEvent->getStartDate());

			while ($startMarker->format('w') != $day) {
				$startMarker->modify('+1 day');
			}

			$maxEndMarker = clone($startMarker);
			$maxEndMarker->modify($this->limit);

			$endMarker = $weeklyEvent->getRecurrenceUntil()
				? min($weeklyEvent->getRecurrenceUntil(), clone($toDate), $maxEndMarker)
				: min(clone($toDate), $maxEndMarker);

			$actualEndMarker = clone($endMarker);

			// The DatePeriod class does not actually include the end date so you have to increment it first
			$endMarker->modify('+1 day');

			$dateInterval = new \DateInterval('P1W');
			$datePeriod = new \DatePeriod($startMarker, $dateInterval, $endMarker);

			$limitMarker = 0;

			foreach ($datePeriod as $date) {
				if (($limit and ($limit === $limitMarker)) or ($date > $actualEndMarker)) {
					break;
				}

				$newWeeklyEvent = clone($weeklyEvent);
				$newStartDate = new \DateTime($date->format('Y-m-d').' '.$weeklyEventTime);

				if ($newStartDate < $startMarker) {
					continue;
				}

				$duration = $newWeeklyEvent->getDuration();

				$newWeeklyEvent->setStartDate($newStartDate);
				
				$newEndDate = clone($newStartDate);
				$newEndDate->add($duration);

				$newWeeklyEvent->setEndDate($newEndDate);
				$newWeeklyEvent->setRecurrenceType();

				$return[] = $newWeeklyEvent;

				$limit and $limitMarker++;
			}
		}

		return $return;
	}