find events that matches the given period (during or over).

@param \CalendR\Period\PeriodInterface $period
@param array                           $options

@return array|EventInterface

@throws NoProviderFound
160491
public function find(PeriodInterface $period, array $options = array())
    {
        if (0 === count($this->providers)) {
            throw new NoProviderFound();
        }

        // Check if there's a provider option provided, used to filter the used providers
        $providers = isset($options['providers']) ? $options['providers'] : array();
        if (!is_array($providers)) {
            $providers = array($providers);
        }

        // Instantiate an event collection
        $collection = call_user_func($this->collectionInstantiator);
        foreach ($this->providers as $name => $provider) {
            if (count($providers) > 0 && !in_array($name, $providers)) {
                continue;
            }

            // Add matching events to the collection
            foreach ($provider->getEvents($period->getBegin(), $period->getEnd(), $options) as $event) {
                if ($period->containsEvent($event)) {
                    $collection->add($event);
                }
            }
        }

        return $collection;
    }
1191083
public function performQuery(Period $period, string $metrics, array $others = [])
    {
        return $this->client->performQuery(
            $this->viewId,
            $period->startDate,
            $period->endDate,
            $metrics,
            $others
        );
    }
714304
public function syncAll(array $options = [])
    {
        $periods = \GuzzleHttp\json_decode((string) $this->api->relatedData->getPeriods()->getBody());
        foreach ($periods as $period) {
            $entity = $this->periodUpdater->updateFromApiResponse(DandomainFoundation\objectToArray($period));
            $this->repository->save($entity);
        }
    }
309040
public function watch($options = array()) {
		
		// double-checks options was properly set
		if (empty($options)) {
			Console::writeError("need to pass options to generate...");
		}
		
		// set default attributes
		$moveStatic    = (isset($options["moveStatic"])) ? $options["moveStatic"] : true;
		$noCacheBuster = (isset($options["noCacheBuster"])) ? $options["noCacheBuster"] : false;
		
		// make sure a copy of the given options are saved for using when running generate
		$this->options = $options;
		
		// set-up the Dispatcher
		$dispatcherInstance = Dispatcher::getInstance();
		$dispatcherInstance->dispatch("watcher.start");
		
		if ($noCacheBuster) {
			Config::setOption("cacheBuster",0);
		}
		
		$c  = false;           // track that one loop through the pattern file listing has completed
		$o  = new \stdClass(); // create an object to hold the properties
		$cp = new \stdClass(); // create an object to hold a clone of $o
		
		$o->patterns = new \stdClass();
		
		Console::writeLine("watching your site for changes...");
		
		// default vars
		$publicDir        = Config::getOption("publicDir");
		$sourceDir        = Config::getOption("sourceDir");
		$patternSourceDir = Config::getOption("patternSourceDir");
		$ignoreExts       = Config::getOption("ie");
		$ignoreDirs       = Config::getOption("id");
		$patternExt       = Config::getOption("patternExtension");
		
		// build the file extensions based on the rules
		$fileExtensions   = array();
		$patternRules     = PatternData::getRules();
		foreach ($patternRules as $patternRule) {
			$extensions = $patternRule->getProp("extProp");
			if (strpos($extensions,"&&") !== false) {
				$extensions = explode("&&",$extensions);
			} else if (strpos($extensions,"||") !== false) {
				$extensions = explode("||",$extensions);
			} else {
				$extensions = array($extensions);
			}
			foreach ($extensions as $extension) {
				if (!in_array($extension, $fileExtensions)) {
					$fileExtensions[] = $extension;
				}
			}
		}
		
		// run forever
		while (true) {
			
			// clone the patterns so they can be checked in case something gets deleted
			$cp = clone $o->patterns;
			
			// iterate over the patterns & related data and regenerate the entire site if they've changed
			$patternObjects  = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
			
			// make sure dots are skipped
			$patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
			
			foreach($patternObjects as $name => $object) {
				
				// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
				$fileName      = str_replace($patternSourceDir.DIRECTORY_SEPARATOR,"",$name);
				$fileNameClean = str_replace(DIRECTORY_SEPARATOR."_",DIRECTORY_SEPARATOR,$fileName);
				
				if ($object->isFile() && in_array($object->getExtension(), $fileExtensions)) {
					
					// make sure this isn't a hidden pattern
					$patternParts = explode(DIRECTORY_SEPARATOR,$fileName);
					$pattern      = isset($patternParts[2]) ? $patternParts[2] : $patternParts[1];
					
					// make sure the pattern still exists in source just in case it's been deleted during the iteration
					if (file_exists($name)) {
						
						$mt = $object->getMTime();
						if (isset($o->patterns->$fileName) && ($o->patterns->$fileName != $mt)) {
							$o->patterns->$fileName = $mt;
							$this->updateSite($fileName,"changed");
						} else if (!isset($o->patterns->$fileName) && $c) {
							$o->patterns->$fileName = $mt;
							$this->updateSite($fileName,"added");
							if ($object->getExtension() == $patternExt) {
								$patternSrcPath  = str_replace(".".$patternExt,"",$fileName);
								$patternDestPath = str_replace("/","-",$patternSrcPath);
								$render = ($pattern[0] != "_") ? true : false;
								$this->patternPaths[$patternParts[0]][$pattern] = array("patternSrcPath" => $patternSrcPath, "patternDestPath" => $patternDestPath, "render" => $render);
							}
						} else if (!isset($o->patterns->$fileName)) {
							$o->patterns->$fileName = $mt;
						}
						
						if ($c && isset($o->patterns->$fileName)) {
							unset($cp->$fileName);
						}
						
					} else {
						
						// the file was removed during the iteration so remove references to the item
						unset($o->patterns->$fileName);
						unset($cp->$fileName);
						unset($this->patternPaths[$patternParts[0]][$pattern]);
						$this->updateSite($fileName,"removed");
						
					}
					
				}
				
			}
			
			// make sure old entries are deleted
			// will throw "pattern not found" errors if an entire directory is removed at once but that shouldn't be a big deal
			if ($c) {
				
				foreach($cp as $fileName => $mt) {
					
					unset($o->patterns->$fileName);
					$patternParts = explode(DIRECTORY_SEPARATOR,$fileName);
					$pattern = isset($patternParts[2]) ? $patternParts[2] : $patternParts[1];
					
					unset($this->patternPaths[$patternParts[0]][$pattern]);
					$this->updateSite($fileName,"removed");
					
				}
				
			}
			
			// iterate over annotations, data, meta and any other _ dirs
			$watchDirs = glob($sourceDir.DIRECTORY_SEPARATOR."_*",GLOB_ONLYDIR);
			foreach ($watchDirs as $watchDir) {
				
				if ($watchDir != $patternSourceDir) {
					
					// iterate over the data files and regenerate the entire site if they've changed
					$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($watchDir), \RecursiveIteratorIterator::SELF_FIRST);
					
					// make sure dots are skipped
					$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
					
					foreach($objects as $name => $object) {
						
						$fileName = str_replace($sourceDir.DIRECTORY_SEPARATOR,"",$name);
						$mt = $object->getMTime();
						
						if (!isset($o->$fileName)) {
							$o->$fileName = $mt;
							if ($c) {
								$this->updateSite($fileName,"added");
							}
						} else if ($o->$fileName != $mt) {
							$o->$fileName = $mt;
							if ($c) {
								$this->updateSite($fileName,"changed");
							}
						}
						
					}
					
				}
				
			}
			
			// iterate over all of the other files in the source directory and move them if their modified time has changed
			if ($moveStatic) {
				
				$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir.DIRECTORY_SEPARATOR), \RecursiveIteratorIterator::SELF_FIRST);
				
				// make sure dots are skipped
				$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
				
				foreach($objects as $name => $object) {
					
					// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
					$fileName = str_replace($sourceDir.DIRECTORY_SEPARATOR,"",$name);
					if (($fileName[0] != "_") && (!in_array($object->getExtension(),$ignoreExts)) && (!in_array($object->getFilename(),$ignoreDirs))) {
						
						// catch directories that have the ignored dir in their path
						$ignoreDir = FileUtil::ignoreDir($fileName);
						
						// check to see if it's a new directory
						if (!$ignoreDir && $object->isDir() && !isset($o->$fileName) && !is_dir($publicDir."/".$fileName)) {
							mkdir($publicDir."/".$fileName);
							$o->$fileName = "dir created"; // placeholder
							Console::writeLine($fileName."/ directory was created...");
						}
						
						// check to see if it's a new file or a file that has changed
						if (file_exists($name)) {
							
							$mt = $object->getMTime();
							if (!$ignoreDir && $object->isFile() && !isset($o->$fileName) && !file_exists($publicDir."/".$fileName)) {
								$o->$fileName = $mt;
								FileUtil::moveStaticFile($fileName,"added");
								if ($object->getExtension() == "css") {
									$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
								}
							} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
								$o->$fileName = $mt;
								FileUtil::moveStaticFile($fileName,"changed");
								if ($object->getExtension() == "css") {
									$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
								}
							} else if (!isset($o->fileName)) {
								$o->$fileName = $mt;
							}
							
						} else {
							unset($o->$fileName);
						}
						
					}
					
				}
				
			}
			
			
			$c = true;
			
			// taking out the garbage. basically killing mustache after each run.
			if (gc_enabled()) gc_collect_cycles();
			
			// pause for .05 seconds to give the CPU a rest
			usleep(50000);
			
		}
		
	}
1110313
private function processPeriod($period)
    {
        $sub = null;

        if ($period == 'week' || $period == 'W') {
            $sub = \Zend_Date::WEEK;
        } elseif ($period == 'month' || $period == 'M') {
            $sub = \Zend_Date::MONTH;
        } elseif ($period == 'year') {
            $sub = \Zend_Date::YEAR;
        } elseif ($period == 'D') {
            $sub = \Zend_Date::DAY;
        }
        return $sub;
    }
1013272
public function getCalendarId(EntityInterface $entity, ArrayObject $options, $map = null)
    {
        $result = null;

        if (empty($options['calendar'])) {
            return $result;
        }

        $result = $options['calendar']->id;

        return $result;
    }
1282774
public function getEvents(\DateTime $begin, \DateTime $end, array $options = array())
    {
        $events = array();

        foreach ($this->providers as $provider) {
            $events = array_merge($events, $provider->getEvents($begin, $end, $options));
        }

        return $events;
    }
962001
public function contains(Period $interval, Period ...$intervals): bool
    {
        $intervals[] = $interval;
        foreach ($intervals as $period) {
            if (false === $this->indexOf($period)) {
                return false;
            }
        }

        return true;
    }
622545
protected function resolveOptions(array $options)
    {
        if (null === $this->resolver) {
            $this->resolver = new OptionsResolver();
            $this->resolver->setDefaults(
                array(
                    'second_class' => 'CalendR\Period\Second',
                    'minute_class' => 'CalendR\Period\Minute',
                    'hour_class' => 'CalendR\Period\Hour',
                    'day_class' => 'CalendR\Period\Day',
                    'week_class' => 'CalendR\Period\Week',
                    'month_class' => 'CalendR\Period\Month',
                    'year_class' => 'CalendR\Period\Year',
                    'range_class' => 'CalendR\Period\Range',
                    'first_weekday' => Day::MONDAY,
                )
            );
            $this->setDefaultOptions($this->resolver);
        }

        return $this->resolver->resolve($options);
    }
721411
public function getPluginCalendars(Event $event, array $options = []): void
    {
        $content = $result = [];

        /** @var \Qobo\Calendar\Model\Table\CalendarsTable $table */
        $table = TableRegistry::get('Qobo/Calendar.Calendars');

        if (!empty($event->result)) {
            $result = $event->result;
        }

        // locally created calendars don't have source_id (external link).
        $options = array_merge($options, [
            'conditions' => [
                'source LIKE' => 'Plugin__%',
            ]
        ]);

        $calendars = $table->getCalendars($options);

        if (empty($calendars)) {
            return;
        }

        foreach ($calendars as $k => $calendar) {
            unset($calendar->calendar_events);

            $encoded = (string)json_encode($calendar);
            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new \RuntimeException(json_last_error_msg());
            }

            $content[$k]['calendar'] = json_decode($encoded, true);
        }

        if (!empty($content)) {
            $result = array_merge($result, $content);
        }

        $event->result = $result;
    }
274746
public function scopeActiveOn($query, $period)
    {
        return $query->whereHas('periods', function($query) use ($period){
            $query->where('academic_periods_id', $period);
        });
    }
1050361
public function abuts(Period $interval): bool
    {
        return $this->bordersOnEnd($interval) || $this->bordersOnStart($interval);
    }
82232
public function setSchedule($schedule, $options = [])
    {
        $this->schedule = $schedule;
        $this->setOptions($options);

        return $this;
    }
1038086
public function getEvents(array $options = null)
    {
        $url = ThisData::ENDPOINT_EVENTS;
        if (!is_null($options)) {
            $url .= '?' . http_build_query($options);
        }
        $response = $this->synchronousExecute('GET', $url);
        return json_decode($response->getBody(), TRUE);
    }
609663
public function setExpires($period)
    {
        if (is_int($period))
            return $this->setExpiresInSeconds($period);
        if ($period instanceof DateTimeInterface)
            return $this->setExpireDate($period);
        if ($period instanceof DateInterval)
            return $this->setExpiresIn($period);

        throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required");
    }
215700
public function getEventType(EntityInterface $entity, ArrayObject $options, $map = null)
    {
        $result = 'Json::' . $entity->getSource() . '::Default';

        if (! empty($options['event_type'])) {
            $result = $options['event_type'];
        }

        return $result;
    }
541509
public function findBy(array $wheres, array $options = [])
    {
        $query = $this->getSqlObject()->select();

        $this->setColumns($query, $options);

        $wheres = $this->addJoins($query, $wheres, $options);

        $this->addWheres($query, $wheres, $options);

        if (Arr::get($options, 'order')) {
            $this->setOrder($query, $options['order']);
        }

        return $this->executeAndGetResultsAsEntity($query);
    }