<commit_before><?php
/**
 * The news.
 * Sit back and relax, this might take a while.
 * History is NOT supported. Only the URLSegment is being tracked. This makes it a bit more simplistic.
 * 
 * @package News/blog module
 * @author Simon 'Sphere'
 * @todo Semantics
 * @todo Cleanup and integration with newsholderpage.
 * @method NewsHolderPage NewsHolderPage this NewsItem belongs to
 * @method Impression Image the Impression for this NewsItem
 * @method Comments Comment Comments on this NewsItem
 * @method Renamed Renamed changed URLSegments
 * @method SlideshowImages SlideshowImage Images for the slideshow-feature
 * @method Tags Tag Added Tags for this Item.
 */
class News extends DataObject { // implements IOGObject{ // optional for OpenGraph support

	private static $db = array(
		'Title' => 'Varchar(255)',
		/**
		 * Author is a troublemaker. Please tell me, 
		 * should I either auto-set the username from currentmember, 
		 * or use the textfield I'm using now (Lazy implementation).
		 */
		'Author' => 'Varchar(255)',
		'URLSegment' => 'Varchar(255)',
		'Synopsis' => 'Text',
		'Content' => 'HTMLText',
		'PublishFrom' => 'Date',
		'Tweeted' => 'Boolean(false)',
		'Live' => 'Boolean(true)',
		'Commenting' => 'Boolean(true)',
		'Locale' => 'Varchar(10)',
		/** This is for the external location of a link */
		'Type' => 'Enum("news,external,download","news")',
		'External' => 'Varchar(255)',
	);
	
	private static $has_one = array(
		'NewsHolderPage' => 'NewsHolderPage',
		'Impression' => 'Image',
		/** If you want to have a download-file */
		'Download' => 'File',
	);
	
	private static $has_many = array(
		'Comments' => 'Comment',
		'Renamed' => 'Renamed',
		'SlideshowImages' => 'SlideshowImage',
	);
	
	private static $many_many = array(
		'Tags' => 'Tag',
	);
	
	private static $summary_fields = array();
	
	private static $searchable_fields = array();

	private static $default_sort = 'News.PublishFrom DESC';
	
	/**
	 * Set defaults. Commenting (show comments if allowed in siteconfig) is default to true.
	 * @var type array of defaults. Commenting is true, SiteConfig overrides this!
	 */
	private static $defaults = array(
		'Commenting' => true,
	);
	
	/**
	 * On large databases, this is a small performance improvement.
	 * @var type array of indexes.
	 */
	private static $indexes = array(
		'URLSegment' => true,
	);

	/**
	 * Define singular name translatable
	 * @return type string Singular name
	 */
	public function singular_name() {
		if (_t($this->class . '.SINGULARNAME')) {
			return _t($this->class . '.SINGULARNAME');
		} else {
			return parent::singular_name();
		} 
	}
	
	/**
	 * Define plural name translatable
	 * @return type string Plural name
	 */
	public function plural_name() {
		if (_t($this->class . '.PLURALNAME')) {
			return _t($this->class . '.PLURALNAME');
		} else {
			return parent::plural_name();
		}
	}

	/**
	 * Define sumaryfields;
	 * @return array of summaryfields
	 */
	public function summaryFields() {
		$summaryFields = parent::summaryFields();
		$summaryFields = array_merge(
			$summaryFields, 
			array(
				'Title' => _t($this->class . '.TITLE', 'Titel'),
				'Author' => _t($this->class . '.AUTHOR', 'Author'),
				'PublishFrom' => _t($this->class . '.PUBLISH', 'Publish from'),
			)
		);
		$pages = NewsHolderPage::get();
		if($pages->count() > 1){
			$summaryFields['NewsHolderPage.Title'] = _t($this->class . '.PARENTPAGE', 'Parent holderpage');
		}
		if(class_exists('Translatable')){
			$translatable = Translatable::get_existing_content_languages('NewsHolderPage');
			if(count($translatable) > 1){
				$summaryFields['fetchLocale'] = _t($this->class . '.LOCALE', 'Language');
			}
		}
		return $summaryFields;
	}
	
	/**
	 * Define translatable searchable fields
	 * @return array Searchable Fields translatable
	 */
	public function searchableFields(){
		$searchableFields = parent::searchableFields();
		unset($searchableFields['NewsHolderPage.Title']);
        unset($searchableFields['NewsHolderPage.Author']);
		unset($searchableFields['PublishFrom']);
		$searchableFields['Title'] = array(
				'field'  => 'TextField',
				'filter' => 'PartialMatchFilter',
				'title'  => _t($this->class . '.TITLE','Title')
			);
        $searchableFields['Author'] = array(
            'field'  => 'TextField',
            'filter' => 'PartialMatchFilter',
            'title'  => _t($this->class . '.AUTHOR','Author')
        );
		$pages = NewsHolderPage::get();
		if($pages->count() > 1){
			$searchableFields['NewsHolderPageID'] = array(<commit_msg>I'm a nitpicker on tabbing.<commit_after><?php
/**
 * The news.
 * Sit back and relax, this might take a while.
 * History is NOT supported. Only the URLSegment is being tracked. This makes it a bit more simplistic.
 * 
 * @package News/blog module
 * @author Simon 'Sphere'
 * @todo Semantics
 * @todo Cleanup and integration with newsholderpage.
 * @method NewsHolderPage NewsHolderPage this NewsItem belongs to
 * @method Impression Image the Impression for this NewsItem
 * @method Comments Comment Comments on this NewsItem
 * @method Renamed Renamed changed URLSegments
 * @method SlideshowImages SlideshowImage Images for the slideshow-feature
 * @method Tags Tag Added Tags for this Item.
 */
class News extends DataObject { // implements IOGObject{ // optional for OpenGraph support

	private static $db = array(
		'Title' => 'Varchar(255)',
		/**
		 * Author is a troublemaker. Please tell me, 
		 * should I either auto-set the username from currentmember, 
		 * or use the textfield I'm using now (Lazy implementation).
		 */
		'Author' => 'Varchar(255)',
		'URLSegment' => 'Varchar(255)',
		'Synopsis' => 'Text',
		'Content' => 'HTMLText',
		'PublishFrom' => 'Date',
		'Tweeted' => 'Boolean(false)',
		'Live' => 'Boolean(true)',
		'Commenting' => 'Boolean(true)',
		'Locale' => 'Varchar(10)',
		/** This is for the external location of a link */
		'Type' => 'Enum("news,external,download","news")',
		'External' => 'Varchar(255)',
	);
	
	private static $has_one = array(
		'NewsHolderPage' => 'NewsHolderPage',
		'Impression' => 'Image',
		/** If you want to have a download-file */
		'Download' => 'File',
	);
	
	private static $has_many = array(
		'Comments' => 'Comment',
		'Renamed' => 'Renamed',
		'SlideshowImages' => 'SlideshowImage',
	);
	
	private static $many_many = array(
		'Tags' => 'Tag',
	);
	
	private static $summary_fields = array();
	
	private static $searchable_fields = array();

	private static $default_sort = 'News.PublishFrom DESC';
	
	/**
	 * Set defaults. Commenting (show comments if allowed in siteconfig) is default to true.
	 * @var type array of defaults. Commenting is true, SiteConfig overrides this!
	 */
	private static $defaults = array(
		'Commenting' => true,
	);
	
	/**
	 * On large databases, this is a small performance improvement.
	 * @var type array of indexes.
	 */
	private static $indexes = array(
		'URLSegment' => true,
	);

	/**
	 * Define singular name translatable
	 * @return type string Singular name
	 */
	public function singular_name() {
		if (_t($this->class . '.SINGULARNAME')) {
			return _t($this->class . '.SINGULARNAME');
		} else {
			return parent::singular_name();
		} 
	}
	
	/**
	 * Define plural name translatable
	 * @return type string Plural name
	 */
	public function plural_name() {
		if (_t($this->class . '.PLURALNAME')) {
			return _t($this->class . '.PLURALNAME');
		} else {
			return parent::plural_name();
		}
	}

	/**
	 * Define sumaryfields;
	 * @return array of summaryfields
	 */
	public function summaryFields() {
		$summaryFields = parent::summaryFields();
		$summaryFields = array_merge(
			$summaryFields, 
			array(
				'Title' => _t($this->class . '.TITLE', 'Titel'),
				'Author' => _t($this->class . '.AUTHOR', 'Author'),
				'PublishFrom' => _t($this->class . '.PUBLISH', 'Publish from'),
			)
		);
		$pages = NewsHolderPage::get();
		if($pages->count() > 1){
			$summaryFields['NewsHolderPage.Title'] = _t($this->class . '.PARENTPAGE', 'Parent holderpage');
		}
		if(class_exists('Translatable')){
			$translatable = Translatable::get_existing_content_languages('NewsHolderPage');
			if(count($translatable) > 1){
				$summaryFields['fetchLocale'] = _t($this->class . '.LOCALE', 'Language');
			}
		}
		return $summaryFields;
	}
	
	/**
	 * Define translatable searchable fields
	 * @return array Searchable Fields translatable
	 */
	public function searchableFields(){
		$searchableFields = parent::searchableFields();
		unset($searchableFields['NewsHolderPage.Title']);
		unset($searchableFields['NewsHolderPage.Author']);
		unset($searchableFields['PublishFrom']);
		$searchableFields['Title'] = array(
				'field'  => 'TextField',
				'filter' => 'PartialMatchFilter',
				'title'  => _t($this->class . '.TITLE','Title')
			);
		$searchableFields['Author'] = array(
			'field'  => 'TextField',
			'filter' => 'PartialMatchFilter',
			'title'  => _t($this->class . '.AUTHOR','Author')
		);
		$pages = NewsHolderPage::get();
		if($pages->count() > 1){
			$searchableFields['NewsHolderPageID'] = array(
{'fraction_non_alphanumeric': 0.15733068169263065, 'fraction_numerical': 0.003756490995470114, 'mean_word_length': 3.8903295515937333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2932263', 'n_tokens_mistral': 3143, 'n_tokens_neox': 2792, 'n_words': 769}