<commit_before><?php

class dmEventCalendar extends dmHtmlCalendar
{

	protected static
	$eventModels;

	/**
	 *
	 * @param array $options Options for the calendar
	 * @param int $date  Timestamp of a date from the Week/Month/Year you want to display
	 */
	public function __construct($options = array( ), $date = null )
	{
		parent::__construct( $options, $date );
	}

	public static function getEventModels()
	{

		if (!is_null( self::$eventModels ))
		{
			return self::$eventModels;
		}
		// get Model files including their subclasses
		$libDir = dmOs::normalize( sfConfig::get( 'sf_lib_dir' ) );
		$modelFiles = glob( $libDir . '/model/doctrine/*.class.php' , GLOB_BRACE );
		// get files to be filtered out
		$modelTableFiles = glob( $libDir . '/model/doctrine/*{Table,DoctrineRecord}.class.php' , GLOB_BRACE );
		$modelFiles = array_diff( $modelFiles , $modelTableFiles );
		$modelFiles;
		$models = array( );
		// extract classnames
		foreach ($modelFiles as $file)
		{
			$models[] = preg_replace( '|^(\w+).class.php$|' , '$1' , basename( $file ) );
		}
		// filter classnames that implement the Event interface
		$models = array_filter( $models , array( 'dmEventCalendar' , 'isClassEvent' ) );
		self::$eventModels = $models;
		return $models;
	}

	public static function isClassEvent( $class )
	{
		$reflection = new ReflectionClass( $class );
		return $reflection->implementsInterface( 'dmHtmlCalendarEventInterface' );
	}

	protected function attachModelEvents(Doctrine_Collection $events)
	{
		foreach ($events as $event)
		{
			$this->addEvent( strtotime( $event->getCalendarDate() ) , $event );
		}
	}

	protected function retrieveModelEvents()
	{
		$model = $this->getOption( 'model');
		if (is_null($model)) {
			return null;
		}
		if (!self::isClassEvent($model)) {
			throw new sfException( 'The provided model ('.$model.') for Diem Calendar should implement dmHtmlCalendarEventInterface' );
		}
		//get this month's events
		$query = $model::getCalendarQuery($this->getFirstDateOfMonth(), $this->getLastDateOfMonth());
		if (is_null( $query) || !$query instanceof Doctrine_Query) {
			$date_column = $model::getCalendarDateColumnName();
			$query = dmDb::table( $model )
				->createQuery( 'e' )
				->andWhere( "DATEDIFF('" . date( 'Y-m-d' , $this->getFirstDateOfMonth() ) . "', e." . $date_column . ") < 0" )
				->andWhere( "DATEDIFF('" . date( 'Y-m-d' , $this->getLastDateOfMonth() ) . "', e." . $date_column . ") > 0" );
		}
		return $query->execute();
	}

	public function render()
	{
		$html = '';

		$modelEvents = $this->retrieveModelEvents();
		if (!is_null($modelEvents)) {
			$this->attachModelEvents($modelEvents);
		}
		$html = dmContext::getInstance()->getHelper()->renderPartial( 'dmWidget' , 'dmWidgetScheduleEventCalendar' , array(
			'calendar' => $this
		) );
		return $html;
	}
<commit_msg>Fix: Make the plugin compatible with PHP versions older than 5.3<commit_after><?php

class dmEventCalendar extends dmHtmlCalendar
{

	protected static
	$eventModels;

	/**
	 *
	 * @param array $options Options for the calendar
	 * @param int $date  Timestamp of a date from the Week/Month/Year you want to display
	 */
	public function __construct($options = array( ), $date = null )
	{
		parent::__construct( $options, $date );
	}

	public static function getEventModels()
	{

		if (!is_null( self::$eventModels ))
		{
			return self::$eventModels;
		}
		// get Model files including their subclasses
		$libDir = dmOs::normalize( sfConfig::get( 'sf_lib_dir' ) );
		$modelFiles = glob( $libDir . '/model/doctrine/*.class.php' , GLOB_BRACE );
		// get files to be filtered out
		$modelTableFiles = glob( $libDir . '/model/doctrine/*{Table,DoctrineRecord}.class.php' , GLOB_BRACE );
		$modelFiles = array_diff( $modelFiles , $modelTableFiles );
		$modelFiles;
		$models = array( );
		// extract classnames
		foreach ($modelFiles as $file)
		{
			$models[] = preg_replace( '|^(\w+).class.php$|' , '$1' , basename( $file ) );
		}
		// filter classnames that implement the Event interface
		$models = array_filter( $models , array( 'dmEventCalendar' , 'isClassEvent' ) );
		self::$eventModels = $models;
		return $models;
	}

	public static function isClassEvent( $class )
	{
		$reflection = new ReflectionClass( $class );
		return $reflection->implementsInterface( 'dmHtmlCalendarEventInterface' );
	}

	protected function attachModelEvents(Doctrine_Collection $events)
	{
		foreach ($events as $event)
		{
			$this->addEvent( strtotime( $event->getCalendarDate() ) , $event );
		}
	}

	protected function retrieveModelEvents()
	{
		$model = $this->getOption( 'model');
		if (is_null($model)) {
			return null;
		}
		if (!self::isClassEvent($model)) {
			throw new sfException( 'The provided model ('.$model.') for Diem Calendar should implement dmHtmlCalendarEventInterface' );
		}
		//get this month's events

		$query = call_user_func(array($model, 'getCalendarQuery'), $this->getFirstDateOfMonth(), $this->getLastDateOfMonth());
		if (is_null( $query) || !$query instanceof Doctrine_Query) {
			$date_column = call_user_func(array($model, 'getCalendarDateColumnName'));
			$query = dmDb::table( $model )
				->createQuery( 'e' )
				->andWhere( "DATEDIFF('" . date( 'Y-m-d' , $this->getFirstDateOfMonth() ) . "', e." . $date_column . ") < 0" )
				->andWhere( "DATEDIFF('" . date( 'Y-m-d' , $this->getLastDateOfMonth() ) . "', e." . $date_column . ") > 0" );
		}
		return $query->execute();
	}

	public function render()
	{
		$html = '';

		$modelEvents = $this->retrieveModelEvents();
		if (!is_null($modelEvents)) {
			$this->attachModelEvents($modelEvents);
		}
		$html = dmContext::getInstance()->getHelper()->renderPartial( 'dmWidget' , 'dmWidgetScheduleEventCalendar' , array(
			'calendar' => $this
		) );
		return $html;
	}

{'fraction_non_alphanumeric': 0.16290770298403887, 'fraction_numerical': 0.0013879250520471894, 'mean_word_length': 4.156529516994634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3064716', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1892, 'n_words': 441}