<commit_before><?php defined('SYSPATH') or die('No direct script access.');

/**
 * Model for Channel_Filters
 *
 * PHP version 5
 * LICENSE: This source file is subject to GPLv3 license 
 * that is available through the world-wide-web at the following URI:
 * http://www.gnu.org/copyleft/gpl.html
 * @author     <NAME> <<EMAIL>> 
 * @package    SwiftRiver - http://github.com/ushahidi/Swiftriver_v2
 * @category   Models
 * @copyright  Ushahidi - http://www.ushahidi.com
 * @license    http://www.gnu.org/copyleft/gpl.html GNU General Public License v3 (GPLv3) 
 */
class Model_Channel_Filter extends ORM {
    
    const RUN_INTERVAL = 5; // Default minimum duration between crawls
    
	/**
	 * A channel_filter has many droplets and channel_filter_options
	 * @var array Relationhips
	 */
	protected $_has_many = array(
		'channel_filter_options' => array()
		);

	/**
	 * A channel_filter belongs to an account and a user
	 * @var array Relationhips
	 */
	protected $_belongs_to = array(
		'account' => array(),
		'user' => array(),
		'river' => array()
		);

	
	/**
	 * Overload saving to perform additional functions on the channel_filter
	 */
	public function save(Validation $validation = NULL)
	{

		// Do this for first time channel_filters only
		if ($this->loaded() === FALSE)
		{
			// Save the date the channel_filter was first added
			$this->filter_date_add = date("Y-m-d H:i:s", time());
		}
		else
		{
			// Set the date modified
			$this->filter_date_modified = date("Y-m-d H:i:s", time());
		}

		return parent::save();
	}

	/**
	 * Overrides the default behaviour to perform
	 * extra tasks before removing the channel filter
	 * entry 
	 */
	public function delete()
	{
		// Delete the channel filter options
		DB::delete('channel_filter_options')
		    ->where('channel_filter_id', '=', $this->id)
		    ->execute();

		// Default
		parent::delete();
	}

	/**
	 * Get channel filter by channel and river id
	 *
	 * @param string $channel Name of the channel
	 * @param int $river_id Database ID of the river associated with the channel
	 * @return Database_Result
	 */
	public static function get_channel_filters($channel, $river_id)
	{
		$channel_filter = ORM::factory('channel_filter')<commit_msg>Model/Channel_Filter: Auto-update fix.<commit_after><?php defined('SYSPATH') or die('No direct script access.');

/**
 * Model for Channel_Filters
 *
 * PHP version 5
 * LICENSE: This source file is subject to GPLv3 license 
 * that is available through the world-wide-web at the following URI:
 * http://www.gnu.org/copyleft/gpl.html
 * @author     <NAME> <<EMAIL>> 
 * @package    SwiftRiver - http://github.com/ushahidi/Swiftriver_v2
 * @category   Models
 * @copyright  Ushahidi - http://www.ushahidi.com
 * @license    http://www.gnu.org/copyleft/gpl.html GNU General Public License v3 (GPLv3) 
 */
class Model_Channel_Filter extends ORM {
    
    const RUN_INTERVAL = 5; // Default minimum duration between crawls
    
	/**
	 * A channel_filter has many droplets and channel_filter_options
	 * @var array Relationhips
	 */
	protected $_has_many = array(
		'channel_filter_options' => array()
		);

	/**
	 * A channel_filter belongs to an account and a user
	 * @var array Relationhips
	 */
	protected $_belongs_to = array(
		'account' => array(),
		'user' => array(),
		'river' => array()
		);

	/**
	 * Auto-update columns for updates
	 * @var string
	 */
	protected $_updated_column = array('column' => 'filter_date_add', 'format' => 'Y-m-d H:i:s');

	/**
	 * Auto-update columns for creation
	 * @var string
	 */
	protected $_created_column = array('column' => 'filter_date_modified', 'format' => 'Y-m-d H:i:s');

	/**
	 * Overrides the default behaviour to perform
	 * extra tasks before removing the channel filter
	 * entry 
	 */
	public function delete()
	{
		// Delete the channel filter options
		DB::delete('channel_filter_options')
		    ->where('channel_filter_id', '=', $this->id)
		    ->execute();

		// Default
		parent::delete();
	}

	/**
	 * Get channel filter by channel and river id
	 *
	 * @param string $channel Name of the channel
	 * @param int $river_id Database ID of the river associated with the channel
	 * @return Database_Result
	 */
	public static function get_channel_filters($channel, $river_id)
	{
		$channel_filter = ORM::factory('channel_filter')
{'fraction_non_alphanumeric': 0.1282170183167169, 'fraction_numerical': 0.0027822861117551586, 'mean_word_length': 3.4520123839009287, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '7140223', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1306, 'n_words': 402}