<commit_before><?php

class PhotoItem extends DataObject { 
	
	private static $db = array (
	   	"SortID" => "Int",
		"Caption" => "Text"
	);
	
	private static $has_one = array (
		"PhotoGallery" => "PhotoGallery",
		"PhotoAlbum" => "PhotoAlbum",
		"Photo" => "Image"
	);

	private static $summary_fields = array (
      	"CaptionExcerpt" => "Caption",
      	"Thumbnail" => "Photo",
      	"AlbumTitle" => "Album"
   	);

	function canCreate($Member = null) { return true; }
	function canEdit($Member = null) { return true; }
	function canView($Member = null) { return true; }
	function canDelete($Member = null) { return true; }
	
	private static $default_sort = "SortID Asc";
	private static $singular_name = "Photo";
	private static $plural_name = "Photos";
	
	public function getCMSFields() {
		$albums = PhotoAlbum::get();
		$map = $albums ? $albums->map("ID", "Name", "Please Select") : array();
		if($map) {
			$albumsdropdown = new DropdownField("PhotoAlbumID","Photo Album", $map);
			$albumsdropdown->setEmptyString("-- Please Select --");
		}
		else {
			$albumsdropdown = new DropdownField("PhotoAlbumID","Photo Album", $map);
			$albumsdropdown->setEmptyString("There are no photo albums created yet"); 
		}
		$imgfield = UploadField::create("Photo");
		$imgfield->folderName = "PhotoGallery"; 
      	$imgfield->getValidator()->allowedExtensions = array("jpg","jpeg","gif","png");
		return new FieldList(
			$albumsdropdown,
		   	$imgfield,
			TextField::create("Caption")
		);
	}
	
	public function Thumbnail() {
		$Image = $this->Photo();
		if ( $Image ) 
			return $Image->CMSThumbnail();
		else 
			return null;
	}
	
	public function CaptionExcerpt($length = 75) {<commit_msg>Add some logic for assigning albums to photo items<commit_after><?php

class PhotoItem extends DataObject { 
	
	private static $db = array (
	   	"SortID" => "Int",
		"Caption" => "Text"
	);
	
	private static $has_one = array (
		"PhotoGallery" => "PhotoGallery",
		"PhotoAlbum" => "PhotoAlbum",
		"Photo" => "Image"
	);

	private static $summary_fields = array (
      	"CaptionExcerpt" => "Caption",
      	"Thumbnail" => "Photo",
      	"AlbumTitle" => "Album"
   	);

	function canCreate($Member = null) { return true; }
	function canEdit($Member = null) { return true; }
	function canView($Member = null) { return true; }
	function canDelete($Member = null) { return true; }
	
	private static $default_sort = "SortID Asc";
	private static $singular_name = "Photo";
	private static $plural_name = "Photos";
	
	public function getCMSFields() {
		if($this->ID == 0) {
			$albumsdropdown = TextField::create('AlbumDisclaimer')->setTitle('Album')->setDisabled(true)->setValue('You can assign an album once you have saved the record for the first time.');
		}
		else {
			$albums = PhotoAlbum::get()->sort("Name ASC");
			$map = $albums ? $albums->map("ID", "Name", "Please Select") : array();
			if($map) {
				$albumsdropdown = new DropdownField("PhotoAlbumID","Photo Album", $map);
				$albumsdropdown->setEmptyString("-- Please Select --");
			}
			else {
				$albumsdropdown = new DropdownField("PhotoAlbumID","Photo Album", $map);
				$albumsdropdown->setEmptyString("There are no photo albums created yet"); 
			}
		}
		$imgfield = UploadField::create("Photo");
		$imgfield->folderName = "PhotoGallery"; 
      	$imgfield->getValidator()->allowedExtensions = array("jpg","jpeg","gif","png");
		return new FieldList(
			$albumsdropdown,
		   	$imgfield,
			TextField::create("Caption")
		);
	}
	
	public function Thumbnail() {
		$Image = $this->Photo();
		if ( $Image ) 
			return $Image->CMSThumbnail();
		else 
			return null;
	}
	
	public function CaptionExcerpt($length = 75) {
{'fraction_non_alphanumeric': 0.16268332428028245, 'fraction_numerical': 0.0013579576317218902, 'mean_word_length': 4.045205479452055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '5678280', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1179, 'n_words': 284}