<commit_before><?php
/**
 * Shows a widget with viewing blog entries
 * by months or years.
 * 
 * @package blog
 */
class ArchiveWidget extends Widget {
	
	static $db = array(
		'DisplayMode' => 'Varchar'
	);
	static $has_one = array();
	
	static $has_many = array();
	
	static $many_many = array();
	
	static $belongs_many_many = array();
	
	static $defaults = array(
		'DisplayMode' => 'month'
	);
	
	static $title = 'Browse by Date';

	static $cmsTitle = 'Blog Archive';
	
	static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.';
	
	function getCMSFields() {
		return new FieldSet(
			new OptionsetField(
				'DisplayMode',
				_t('ArchiveWidget.DispBY', 'Display by'),
				array(
					'month' => _t('ArchiveWidget.MONTH', 'month'),
					'year' => _t('ArchiveWidget.YEAR', 'year')
				)
			)
		);
	}
	
	function Dates() {
		Requirements::themedCSS('archivewidget');
		
		$results = new DataObjectSet();
		$container = BlogTree::current();
		$ids = $container->BlogHolderIDs();
		
		$stage = Versioned::current_stage();
		$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";

		if($this->DisplayMode == 'month') {
			if(defined('Database::USE_ANSI_SQL')) {
				$sqlResults = DB::query("
					SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") AS \"Year\", \"Date\"
					FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
					WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
					ORDER BY \"Date\" DESC"
				);
			} else {
				$sqlResults = DB::query("
					SELECT DISTINCT MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year` 
					FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` 
					WHERE `ParentID` IN (" . implode(', ', $ids) . ")
					ORDER BY `Date` DESC"
				);
			}
		} else {
			if(defined('Database::USE_ANSI_SQL')) {
				$sqlResults = DB::query("
					SELECT DISTINCT YEAR(\"Date\") AS \"Year\", \"Date\" 
					FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
					WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
					ORDER BY \"Date\" DESC"
				);
			} else {
				$sqlResults = DB::query("
					SELECT DISTINCT YEAR(`Date`) AS `Year` 
					FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` 
					WHERE `ParentID` in (".implode(', ',$ids).")
					ORDER BY `Date` DESC"
				);
			}
		}
		
		if($sqlResults) foreach($sqlResults as $sqlResult) {
			$isMonthDisplay = $this->DisplayMode == 'month';
			
			$monthVal = ($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1;
			$month = ($isMonthDisplay) ? $monthVal : 1;
			$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y');
			
			$date = DBField::create('Date', array(
				'Day' => 1,
				'Month' => $month,<commit_msg>MINOR Fixed undefined Month in ArchiveWidget<commit_after><?php
/**
 * Shows a widget with viewing blog entries
 * by months or years.
 * 
 * @package blog
 */
class ArchiveWidget extends Widget {
	
	static $db = array(
		'DisplayMode' => 'Varchar'
	);
	static $has_one = array();
	
	static $has_many = array();
	
	static $many_many = array();
	
	static $belongs_many_many = array();
	
	static $defaults = array(
		'DisplayMode' => 'month'
	);
	
	static $title = 'Browse by Date';

	static $cmsTitle = 'Blog Archive';
	
	static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.';
	
	function getCMSFields() {
		return new FieldSet(
			new OptionsetField(
				'DisplayMode',
				_t('ArchiveWidget.DispBY', 'Display by'),
				array(
					'month' => _t('ArchiveWidget.MONTH', 'month'),
					'year' => _t('ArchiveWidget.YEAR', 'year')
				)
			)
		);
	}
	
	function Dates() {
		Requirements::themedCSS('archivewidget');
		
		$results = new DataObjectSet();
		$container = BlogTree::current();
		$ids = $container->BlogHolderIDs();
		
		$stage = Versioned::current_stage();
		$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";

		if($this->DisplayMode == 'month') {
			if(defined('Database::USE_ANSI_SQL')) {
				$sqlResults = DB::query("
					SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") AS \"Year\", \"Date\"
					FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
					WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
					ORDER BY \"Date\" DESC"
				);
			} else {
				$sqlResults = DB::query("
					SELECT DISTINCT MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year` 
					FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` 
					WHERE `ParentID` IN (" . implode(', ', $ids) . ")
					ORDER BY `Date` DESC"
				);
			}
		} else {
			if(defined('Database::USE_ANSI_SQL')) {
				$sqlResults = DB::query("
					SELECT DISTINCT YEAR(\"Date\") AS \"Year\", \"Date\" 
					FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
					WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
					ORDER BY \"Date\" DESC"
				);
			} else {
				$sqlResults = DB::query("
					SELECT DISTINCT YEAR(`Date`) AS `Year` 
					FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix` 
					WHERE `ParentID` in (".implode(', ',$ids).")
					ORDER BY `Date` DESC"
				);
			}
		}
		
		if($sqlResults) foreach($sqlResults as $sqlResult) {
			$isMonthDisplay = $this->DisplayMode == 'month';
			
			$monthVal = (isset($sqlResult['Month'])) ? (int) $sqlResult['Month'] : 1;
			$month = ($isMonthDisplay) ? $monthVal : 1;
			$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y');
			
			$date = DBField::create('Date', array(
				'Day' => 1,
				'Month' => $month,
{'fraction_non_alphanumeric': 0.19528501055594652, 'fraction_numerical': 0.001055594651653765, 'mean_word_length': 3.2111111111111112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2321010', 'n_tokens_mistral': 2378, 'n_tokens_neox': 1913, 'n_words': 478}