<commit_before><?php
namespace Album;

class Model_AlbumImage extends \Orm\Model
{
	protected static $_table_name = 'album_image';

	protected static $_belongs_to = array(
		'album' => array(
			'key_from' => 'album_id',
			'model_to' => '\Album\Model_Album',
			'key_to' => 'id',
			'cascade_save' => false,
			'cascade_delete' => false,
		),
	);
	protected static $_has_one = array(
		'file' => array(
			'key_from' => 'file_id',
			'model_to' => '\Model_File',
			'key_to' => 'id',
			'cascade_save' => false,
			'cascade_delete' => true,
		),
	);
//	protected static $_has_many = array(
//		'album_image_comment' => array(
//			'key_from' => 'id',
//			'model_to' => '\Album\Model_AlbumImageComment',
//			'key_to' => 'album_image_id',
//			'cascade_save' => false,
//			'cascade_delete' => false,
//		)
//	);

	protected static $_properties = array(
		'id',
		'album_id' => array(
			'data_type' => 'integer',
			'form' => array('type' => false),
		),
		'file_id' => array(
			'data_type' => 'integer',
			'form' => array('type' => false),
		),
		'name' => array(
			'data_type' => 'varchar',
			'label' => '名前',
			'validation' => array('trim', 'max_length' => array(255)),
			'form' => array('type' => 'text', 'class' => 'form-control'),
		),
		'comment_count' => array(
			'data_type' => 'integer',
			'default' => 0,
			'form' => array('type' => false),
		),
		'public_flag' => array(
			'data_type' => 'integer',
			'validation' => array('required'),
			'form' => array('type' => 'radio', 'options' => array()),
		),
		'shot_at' => array(
			'data_type' => 'datetime',
			'validation' => array('trim', 'valid_date' => array('Y-m-d H:i:s')),
			'form' => array('type' => false),
		),
		'created_at' => array('form' => array('type' => false)),
		'updated_at' => array('form' => array('type' => false)),
		'sort_datetime' => array('form' => array('type' => false)),
	);

	protected static $_observers = array(
		'Orm\Observer_Validation' => array(
			'events' => array('before_save'),
		),
		'Orm\Observer_CreatedAt' => array(
			'events' => array('before_insert'),
			'mysql_timestamp' => true,
		),
		'Orm\Observer_UpdatedAt' => array(
			'events' => array('before_save'),
			'mysql_timestamp' => true,
		),
		'MyOrm\Observer_CopyValue'=>array(
			'events'=>array('before_insert'),
			'property_to'   => 'sort_datetime',
			'property_from' => 'created_at',
		),
		'MyOrm\Observer_SortDatetime' => array(
			'events' => array('before_update'),
			'mysql_timestamp' => true,
			'check_changed' => array(
				'check_properties' => array(
					'name',
					'public_flag',
					'comment_count' => array(
						'ignore_value' => 'reduced_num',
					),
				),
			),
		),
		'MyOrm\Observer_DeleteAlbumImage' => array(
			'events' => array('before_delete'),
		),
	);

	protected static $count_par_album_list = array();

	public static function _init()
	{
		static::$_properties['name']['label'] = term('site.picture', 'site.title');
		static::$_properties['public_flag']['form'] = \Site_Form::get_public_flag_configs();
		static::$_properties['public_flag']['validation']['in_array'][] = \Site_Util::get_public_flags();

		if (\Module::loaded('timeline'))
		{
			$type_album_image_profile = \Config::get('timeline.types.album_image_profile');
			// 更新時に timeline の sort_datetime, comment_count を更新
			static::$_observers['MyOrm\Observer_UpdateRelationalTables'] = array(
				'events' => array('after_update'),
				'relations' => array(
					array(
						'model_to' => '\Timeline\Model_Timeline',
						'conditions' => array(
							'foreign_table' => array(
								'album_image' => 'value',
							),
							'foreign_id' => array(
								'id' => 'property',
							),
							'type' => array(
								$type_album_image_profile => 'value',
							),
						),
						'update_properties' => array(
							'public_flag',
							'sort_datetime',
							'comment_count',
						),
					),
				),
			);

			if (\Config::get('timeline.articles.cache.is_use'))
			{
				static::$_observers['MyOrm\Observer_ExecuteToRelations'] = array(
					'events' => array('after_save'),
					'relations' => array(
						array(
							'model_to' => '\Timeline\Model_TimelineChildData',
							'conditions' => array(
								'foreign_table' => array(
									'album_image' => 'value',
								),
								'foreign_id' => array(
									'id' => 'property',
								),
							),
							'execute_func' => array(
								'method' => '\Timeline\Site_Util::delete_cache',
								'params' => array(
									'timeline_id' => 'property',
								),
							),
						),
					),
				);
			}
		}
	}

	public static function check_authority($id, $target_member_id = 0)
	{
		if (!$id) return false;

		$obj = self::find($id, array('rows_limit' => 1, 'related' => array('album', 'file')))? : null;
		if (!$obj) return false;
		if ($target_member_id && $target_member_id != $obj->album->member_id) return false;

		return $obj;
	}

	public function get_image()
	{
		if (empty($this->file_id)) return 'ai';<commit_msg>album_image update 時に紐づく timeline view_cache を削除するようにした<commit_after><?php
namespace Album;

class Model_AlbumImage extends \Orm\Model
{
	protected static $_table_name = 'album_image';

	protected static $_belongs_to = array(
		'album' => array(
			'key_from' => 'album_id',
			'model_to' => '\Album\Model_Album',
			'key_to' => 'id',
			'cascade_save' => false,
			'cascade_delete' => false,
		),
	);
	protected static $_has_one = array(
		'file' => array(
			'key_from' => 'file_id',
			'model_to' => '\Model_File',
			'key_to' => 'id',
			'cascade_save' => false,
			'cascade_delete' => true,
		),
	);
//	protected static $_has_many = array(
//		'album_image_comment' => array(
//			'key_from' => 'id',
//			'model_to' => '\Album\Model_AlbumImageComment',
//			'key_to' => 'album_image_id',
//			'cascade_save' => false,
//			'cascade_delete' => false,
//		)
//	);

	protected static $_properties = array(
		'id',
		'album_id' => array(
			'data_type' => 'integer',
			'form' => array('type' => false),
		),
		'file_id' => array(
			'data_type' => 'integer',
			'form' => array('type' => false),
		),
		'name' => array(
			'data_type' => 'varchar',
			'label' => '名前',
			'validation' => array('trim', 'max_length' => array(255)),
			'form' => array('type' => 'text', 'class' => 'form-control'),
		),
		'comment_count' => array(
			'data_type' => 'integer',
			'default' => 0,
			'form' => array('type' => false),
		),
		'public_flag' => array(
			'data_type' => 'integer',
			'validation' => array('required'),
			'form' => array('type' => 'radio', 'options' => array()),
		),
		'shot_at' => array(
			'data_type' => 'datetime',
			'validation' => array('trim', 'valid_date' => array('Y-m-d H:i:s')),
			'form' => array('type' => false),
		),
		'created_at' => array('form' => array('type' => false)),
		'updated_at' => array('form' => array('type' => false)),
		'sort_datetime' => array('form' => array('type' => false)),
	);

	protected static $_observers = array(
		'Orm\Observer_Validation' => array(
			'events' => array('before_save'),
		),
		'Orm\Observer_CreatedAt' => array(
			'events' => array('before_insert'),
			'mysql_timestamp' => true,
		),
		'Orm\Observer_UpdatedAt' => array(
			'events' => array('before_save'),
			'mysql_timestamp' => true,
		),
		'MyOrm\Observer_CopyValue'=>array(
			'events'=>array('before_insert'),
			'property_to'   => 'sort_datetime',
			'property_from' => 'created_at',
		),
		'MyOrm\Observer_SortDatetime' => array(
			'events' => array('before_update'),
			'mysql_timestamp' => true,
			'check_changed' => array(
				'check_properties' => array(
					'name',
					'public_flag',
					'comment_count' => array(
						'ignore_value' => 'reduced_num',
					),
				),
			),
		),
		'MyOrm\Observer_DeleteAlbumImage' => array(
			'events' => array('before_delete'),
		),
	);

	protected static $count_par_album_list = array();

	public static function _init()
	{
		static::$_properties['name']['label'] = term('site.picture', 'site.title');
		static::$_properties['public_flag']['form'] = \Site_Form::get_public_flag_configs();
		static::$_properties['public_flag']['validation']['in_array'][] = \Site_Util::get_public_flags();

		if (\Module::loaded('timeline'))
		{
			$type_album_image_profile = \Config::get('timeline.types.album_image_profile');
			// 更新時に timeline の sort_datetime, comment_count を更新
			static::$_observers['MyOrm\Observer_UpdateRelationalTables'] = array(
				'events' => array('after_update'),
				'relations' => array(
					array(
						'model_to' => '\Timeline\Model_Timeline',
						'conditions' => array(
							'foreign_table' => array(
								'album_image' => 'value',
							),
							'foreign_id' => array(
								'id' => 'property',
							),
							'type' => array(
								$type_album_image_profile => 'value',
							),
						),
						'update_properties' => array(
							'public_flag',
							'sort_datetime',
							'comment_count',
						),
					),
				),
			);
			if (\Config::get('timeline.articles.cache.is_use'))
			{
				static::$_observers['MyOrm\Observer_ExecuteToRelations'] = array(
					'events' => array('after_update'),
					'relations' => array(
						array(
							'model_to' => '\Timeline\Model_TimelineChildData',
							'conditions' => array(
								'foreign_table' => array(
									'album_image' => 'value',
								),
								'foreign_id' => array(
									'id' => 'property',
								),
							),
							'properties_check_changed' => array(
								'name',
								'public_flag',
							),
							'execute_func' => array(
								'method' => '\Timeline\Site_Util::delete_cache',
								'params' => array(
									'timeline_id' => 'property',
								),
							),
						),
					),
				);
			}
		}
	}

	public static function check_authority($id, $target_member_id = 0)
	{
		if (!$id) return false;

		$obj = self::find($id, array('rows_limit' => 1, 'related' => array('album', 'file')))? : null;
		if (!$obj) return false;
		if ($target_member_id && $target_member_id != $obj->album->member_id) return false;

		return $obj;
	}

	public function get_image()
	{
		if (empty($this->file_id)) return 'ai';
{'fraction_non_alphanumeric': 0.20382481173206501, 'fraction_numerical': 0.0011890606420927466, 'mean_word_length': 3.3485566566135287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 222, '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': '130152', 'n_tokens_mistral': 4466, 'n_tokens_neox': 3559, 'n_words': 612}