<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 * @since 2011-06-26
 */
class Photo extends AbstractItem {
	
	/**
	 * Creates new photo.
	 */
	public function create(array $data) {
		throw new NotImplementedException();
	}
	
	/**
	 * Updates photo.
	 */
	public function update(array $data) {
		throw new NotImplementedException();
	}
	
	/**
	 * Toggles activity/visibility of photo.
	 * 
	 * @param int $id Photo ID
	 */
	public function toggleActive($id) {
		dibi::begin();
		
		$is_active = dibi::fetchSingle('
			SELECT tgp.is_active
			FROM gallery_photo AS tgp
			WHERE tgp.photo_id = %s', $id, '
			LIMIT 1
		');
		
		$is_active = $is_active ? false : true;
		
		dibi::query('
			UPDATE gallery_photo
			SET is_active = %b', $is_active, '
			WHERE photo_id = %s', $id, '
		');
		
		dibi::commit();
	}
	
	/**
	 * Deletes photo.
	 * 
	 * @param int $id Photo ID
	 */
	public function delete($id) {
		$this->deleteFile($id);
		
		dibi::query('
			DELETE FROM gallery_photo
			WHERE photo_id = %s', $id, '
		');
	}
	
	/**
	 * Deletes photo file.
	 * 
	 * @param int $id Photo ID
	 */
	protected function deleteFile($id) {
		throw new NotImplementedException();
	}
	
	/**
	 * Changes ordering of file to left.
	 * 
	 * @param int $id Photo ID 
	 */
	public function moveLeft($id) {
		$left_id = dibi::fetchSingle('<commit_msg>* Implementation of file delete<commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 * @since 2011-06-26
 */
class Photo extends AbstractItem {
	
	/**
	 * Creates new photo.
	 */
	public function create(array $data) {
		throw new NotImplementedException();
	}
	
	/**
	 * Updates photo.
	 */
	public function update(array $data) {
		throw new NotImplementedException();
	}
	
	/**
	 * Toggles activity/visibility of photo.
	 * 
	 * @param int $id Photo ID
	 */
	public function toggleActive($id) {
		dibi::begin();
		
		$is_active = dibi::fetchSingle('
			SELECT tgp.is_active
			FROM gallery_photo AS tgp
			WHERE tgp.photo_id = %s', $id, '
			LIMIT 1
		');
		
		$is_active = $is_active ? false : true;
		
		dibi::query('
			UPDATE gallery_photo
			SET is_active = %b', $is_active, '
			WHERE photo_id = %s', $id, '
		');
		
		dibi::commit();
	}
	
	/**
	 * Deletes photo.
	 * 
	 * @param int $id Photo ID
	 */
	public function delete($id) {
		$this->deleteFile($id);
		
		dibi::query('
			DELETE FROM gallery_photo
			WHERE photo_id = %s', $id, '
		');
	}
	
	/**
	 * Deletes photo file.
	 * 
	 * @param int $id Photo ID
	 */
	protected function deleteFile($id) {
		$result = dibi::fetchAll('
			SELECT tgp.filename, tgp.gallery_id
			FROM gallery_photo AS tgp
			WHERE tgp.photo_id = %s', $id, '
			LIMIT 1
		');
		
		if (!$result) {
			throw new InvalidArgumentException('Photo with ID [' . $id . '] was not found.');
		}
		$filename = $result[0]['filename'];
		$gallery_id = $result[0]['gallery_id'];
		
		$filepath_thumbnails = $this->environment->basePath . '/' . $gallery_id . '/' . $this->environment->thumbnailsDirName . '/' . $filename;
		$filepath_regular = $this->environment->basePath . '/' . $gallery_id . '/' . $filename;
		
		if (file_exists($filepath_thumbnails) && is_file($filepath_thumbnails)) {
			unlink($filepath_thumbnails);
		}
		if (file_exists($filepath_regular) && is_file($filepath_regular)) {
			unlink($filepath_regular);
		}
	}
	
	/**
	 * Changes ordering of file to left.
	 * 
	 * @param int $id Photo ID 
	 */
	public function moveLeft($id) {
		$left_id = dibi::fetchSingle('
{'fraction_non_alphanumeric': 0.15780296425457715, 'fraction_numerical': 0.006102877070619006, 'mean_word_length': 2.970011534025375, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '6789010', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1170, 'n_words': 289}