Get Calendar Event end_date

@param \Cake\Datasource\EntityInterface $entity of the event
@param \ArrayObject $options based on the configs
@param array $map of the config

@return \Cake\I18n\Time
502048
public function getCalendarEventEndDate(EntityInterface $entity, ArrayObject $options, $map = null)
    {
        $source = $map->end_date->options->source;

        $ts = Time::parse($entity->get($source));
        $endDate = $ts->modify('+ 1 hour')->i18nFormat('yyyy-MM-dd HH:mm');

        $result = new Time($endDate);

        return $result;
    }
1342384
public function afterSave(Event $event, Setting $entity, ArrayObject $options)
    {
        Cache::delete('settings', 'wasabi/core/longterm');
        $this->eventManager()->dispatch(new Event('Wasabi.Settings.changed'));
    }
739238
public function cascadeDelete(EntityInterface $entity, array $options = [])
    {
        if (!$this->getDependent()) {
            return true;
        }
        $foreignKey = (array)$this->getForeignKey();
        $bindingKey = (array)$this->getBindingKey();
        $conditions = [];

        if (!empty($bindingKey)) {
            $conditions = array_combine($foreignKey, $entity->extract($bindingKey));
        }

        $table = $this->junction();
        $hasMany = $this->getSource()->getAssociation($table->getAlias());
        if ($this->_cascadeCallbacks) {
            foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) {
                $table->delete($related, $options);
            }

            return true;
        }

        $conditions = array_merge($conditions, $hasMany->getConditions());

        $table->deleteAll($conditions);

        return true;
    }
1334628
protected function _getImageVersionData(EntityInterface $entity, array $options = []) {
		$versionData = (array)Configure::read('FileStorage.imageSizes.' . $entity->get('model'));
		if (isset($options['originalVersion'])) {
			$versionData['original'] = $options['originalVersion'];
		} else {
			Configure::write('FileStorage.imageSizes.' . $entity->get('model') . '.original', []);
			$versionData['original'] = [];
		}

		$versionData['original'] = isset($options['originalVersion']) ? $options['originalVersion'] : 'original';

		return $versionData;
	}
1196875
public static function query($options = array())
	{
		$timestamp_start_name = static::temporal_property('start_column');
		$timestamp_end_name = static::temporal_property('end_column');
		$max_timestamp = static::temporal_property('max_timestamp');

		$query = Query_Temporal::forge(get_called_class(), static::connection(), $options)
			->set_temporal_properties($max_timestamp, $timestamp_end_name, $timestamp_start_name);

		//Check if we need to add filtering
		$class = get_called_class();
		$timestamp = \Arr::get(static::$_lazy_filtered_classes, $class, null);

		if( ! is_null($timestamp))
		{
			$query->where($timestamp_start_name, '<=', $timestamp)
				->where($timestamp_end_name, '>', $timestamp);
		}
		elseif(static::get_primary_key_status() and ! static::get_primary_key_id_only_status())
		{
			$query->where($timestamp_end_name, $max_timestamp);
		}

		return $query;
	}
669774
private function getAggregatedValue(array $options)
    {
        // for cases where the entity does not exist yet
        if (! $options['entity'] instanceof EntityInterface) {
            return '';
        }

        $config = explode(',', $options['fieldDefinitions']->getLimit(), 4);

        $configuration = new Configuration(TableRegistry::get($config[1]), $config[2]);
        $configuration->setJoinData($this->config->getTable(), $options['entity'])
            ->setDisplayField(isset($config[3]) ? $config[3] : '');

        $aggregator = new $config[0]($configuration);

        $factory = new FieldHandlerFactory($this->config->getView());

        return $factory->renderValue(
            $aggregator->getConfig()->getTable(),
            $aggregator->getConfig()->getDisplayField(),
            AggregateResult::get($aggregator),
            ['entity' => $options['entity']]
        );
    }
1267950
public function getAllEvents($starttime = null, $endtime = null) {

		if (is_null($starttime)) {
			$starttime = time();
		}
		if (is_null($endtime)) {
			$endtime = strtotime('+1 year', $starttime);
		}

		$starttime = sanitize_int($starttime);
		$endtime = sanitize_int($endtime);
		$relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP);

		$dbprefix = elgg_get_config('dbprefix');

		$mds_name = elgg_get_metastring_id('start_timestamp');
		$mdre_name = elgg_get_metastring_id('repeat_end_timestamp');

		$options = array(
			'type' => 'object',
			'subtype' => Event::SUBTYPE,
			'joins' => array(
				"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship
				"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata
				"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring
				"JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata
				"JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring
			),
			'wheres' => array(
				"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'",
				"mds.name_id = {$mds_name}",
				"mdre.name_id = {$mdre_name}",
				// event start is before our endtime AND (repeat end is after starttime, or there is no repeat end)
				"((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))"
			),
			'limit' => false
		);

		return new ElggBatch('elgg_get_entities', $options);
	}
365598
public function getOneTimeEvents($starttime = null, $endtime = null) {

		if (is_null($starttime)) {
			$starttime = time();
		}
		if (is_null($endtime)) {
			$endtime = strtotime('+1 year', $starttime);
		}

		$starttime = sanitize_int($starttime);
		$endtime = sanitize_int($endtime);
		$relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP);

		$dbprefix = elgg_get_config('dbprefix');

		// for performance we'll denormalize metastrings first
		$mdr_name = elgg_get_metastring_id('repeat');
		$mdr_val = elgg_get_metastring_id(0);
		$mds_name = elgg_get_metastring_id('start_timestamp');
		$mde_name = elgg_get_metastring_id('end_timestamp');
		$options = array(
			'type' => 'object',
			'subtype' => Event::SUBTYPE,
			'joins' => array(
				"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship
				"JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata
				"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata
				"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring
				"JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid", // end time metadata
				"JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id" // end time metastring
			),
			'wheres' => array(
				"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'",
				"mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}",
				"mds.name_id = {$mds_name}",
				"mde.name_id = {$mde_name}",
				"((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime})
					OR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))"
			),
			'limit' => false
		);

		return new ElggBatch('elgg_get_entities', $options);
	}
668562
public function getEvents(\DateTime $begin, \DateTime $end, array $options = array())
    {
        return $this->getEventsQuery($begin, $end, $options)->getResult();
    }
744235
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options): void
    {
        if (empty($entity->get('source_id'))) {
            $entity->set('source_id', $entity->get('id'));
            $this->save($entity);
        }
    }
73420
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$fields = $this->_getMappedFields();

		foreach ($fields as $map => $field) {
			if (!$entity->get($map)) {
				continue;
			}
			$val = $entity->get($map);
			$entity->set($field, $this->_encode($val));
		}
	}
1237892
public function getPluginCalendarEvents(Event $event, EntityInterface $calendar, array $options = []): void
    {
        /** @var \Qobo\Calendar\Model\Table\CalendarEventsTable $table */
        $table = TableRegistry::get('Qobo/Calendar.CalendarEvents');

        $events = $table->getEvents($calendar, $options);

        $event->result = $events;
    }
690432
public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $options) {
		$field = $this->getConfig('field');

		$value = $entity->get($field);
		if (!$value) {
			return;
		}

		$conditions = $this->buildConditions($entity);

		$order = $this->getConfig('findOrder');
		if ($order === null) {
			$order = [];
			if ($this->_table->getSchema()->getColumn('modified')) {
				$order['modified'] = 'DESC';
			}
		}
		$entity = $this->_table->find()->where($conditions)->order($order)->first();
		if (!$entity) {
			// This should be caught with a validation rule if at least one "primary" must exist
			return;
		}

		$entity->set($field, true);
		$this->_table->saveOrFail($entity);
	}
1043116
protected function define(MapperDefinition $map)
    {
        $map->type(TimeRange::class);

        $map->embedded(TimeRange::START)->using(new TimeOfDayMapper($this->startColumnName));
        $map->embedded(TimeRange::END)->using(new TimeOfDayMapper($this->endColumnName));
    }
868602
public function getTime(IdentifierInterface $entity)
    {
        $past = $this->getTimes($entity);
        if (!$past) {
            return;
        }

        // Compute average time
        $average = array_sum($past) / count($past);
        $average = round($average, 2);

        return $average;
    }
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;
    }
539325
public function setRecurrenceEventId($entity = null): string
    {
        $start = $entity instanceof EntityInterface ? $entity->get('start_date') : $entity['start_date'];
        $end = $entity instanceof EntityInterface ? $entity->get('end_date') : $entity['end_date'];
        $id = $entity instanceof EntityInterface ? $entity->get('id') : $entity['id'];

        $result = sprintf("%s__%s_%s", $id, strtotime($start), strtotime($end));

        return $result;
    }