<commit_before><?php
/**
 * Garp_Model_Behavior_Draftable
 * Handles 'draft' status and 'published' dates.
 * A table must have an 'online_status' column (TINYINT) and a 'published' column (DATETIME) to 
 * work with this behavior.
 * The SELECT object is modified with every fetch() command to include the following WHERE clause:
 *
 * WHERE online_status = 1 AND (published IS NULL OR published <= NOW())
 *
 * All this is not applicable in the CMS context.
 *
 * @author <NAME> | grrr.nl
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Db
 * @lastmodified $Date: $
 */
class Garp_Model_Behavior_Draftable extends Garp_Model_Behavior_Abstract {
	/**
 	 * Online status column
 	 * @var String
 	 */
	const STATUS_COLUMN = 'online_status';

	/**
 	 * Published date column
 	 * @var String
 	 */
	const PUBLISHED_COLUMN = 'published';

	/**
 	 * Human-readable status ints
 	 * @var Int
 	 */
	const OFFLINE = 0;
	const ONLINE = 1;

	/**
	 * Configuration.
	 * @return Void
	 */
	protected function _setup($config) {
		$this->_config = $config;
		if (!array_key_exists('draft_only', $config)) {
			$config['draft_only'] = false;
		}
	}

	/**
	 * Before fetch callback.
	 * Adds the WHERE clause.
	 * @param Array $args
	 * @return Void
	 */
	public function beforeFetch(&$args) {
		$is_cms = Zend_Registry::isRegistered('CMS') && Zend_Registry::get('CMS');
		$is_preview = isset($_GET) && array_key_exists('preview', $_GET) && Garp_Auth::getInstance()->isLoggedIn();
		if ($is_cms || $is_preview) {
			// don't use in the CMS, or in preview mode
			return;
		}

		$model = &$args[0];
		$select = &$args[1];

		$this->addWhereClause($model, $select);
	}

	/**
 	 * Add the WHERE clause that keeps offline items from appearing in the results
 	 * @param Garp_Model_Db $model
 	 * @param Zend_Db_Select $select
 	 * @return Void
 	 */
	public function addWhereClause(&$model, Zend_Db_Select &$select) {
		$statusColumn = $model->getAdapter()->quoteIdentifier(self::STATUS_COLUMN);
		$publishedColumn = $model->getAdapter()->quoteIdentifier(self::PUBLISHED_COLUMN);

		// Add online_status check
		$select->where($statusColumn.' = ?', self::ONLINE);

		// Add published check
		if (isset($this->_config['draft_only']) && $this->_config['draft_only']) {
			return;
		}<commit_msg>Sanity check<commit_after><?php
/**
 * Garp_Model_Behavior_Draftable
 * Handles 'draft' status and 'published' dates.
 * A table must have an 'online_status' column (TINYINT) and a 'published' column (DATETIME) to 
 * work with this behavior.
 * The SELECT object is modified with every fetch() command to include the following WHERE clause:
 *
 * WHERE online_status = 1 AND (published IS NULL OR published <= NOW())
 *
 * All this is not applicable in the CMS context.
 *
 * @author <NAME> | grrr.nl
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Db
 * @lastmodified $Date: $
 */
class Garp_Model_Behavior_Draftable extends Garp_Model_Behavior_Abstract {
	/**
 	 * Online status column
 	 * @var String
 	 */
	const STATUS_COLUMN = 'online_status';

	/**
 	 * Published date column
 	 * @var String
 	 */
	const PUBLISHED_COLUMN = 'published';

	/**
 	 * Human-readable status ints
 	 * @var Int
 	 */
	const OFFLINE = 0;
	const ONLINE = 1;

	/**
	 * Configuration.
	 * @return Void
	 */
	protected function _setup($config) {
		if (!array_key_exists('draft_only', $config)) {
			$config['draft_only'] = false;
		}
		$this->_config = $config;
	}

	/**
	 * Before fetch callback.
	 * Adds the WHERE clause.
	 * @param Array $args
	 * @return Void
	 */
	public function beforeFetch(&$args) {
		$is_cms = Zend_Registry::isRegistered('CMS') && Zend_Registry::get('CMS');
		$is_preview = isset($_GET) && array_key_exists('preview', $_GET) && Garp_Auth::getInstance()->isLoggedIn();
		if ($is_cms || $is_preview) {
			// don't use in the CMS, or in preview mode
			return;
		}

		$model = &$args[0];
		$select = &$args[1];

		$this->addWhereClause($model, $select);
	}

	/**
 	 * Add the WHERE clause that keeps offline items from appearing in the results
 	 * @param Garp_Model_Db $model
 	 * @param Zend_Db_Select $select
 	 * @return Void
 	 */
	public function addWhereClause(&$model, Zend_Db_Select &$select) {
		$statusColumn = $model->getAdapter()->quoteIdentifier(self::STATUS_COLUMN);
		$publishedColumn = $model->getAdapter()->quoteIdentifier(self::PUBLISHED_COLUMN);

		// Add online_status check
		$select->where($statusColumn.' = ?', self::ONLINE);

		// Add published check
		if ($this->_config['draft_only']) {
			return;
		}
{'fraction_non_alphanumeric': 0.14338555265448216, 'fraction_numerical': 0.002175805047867711, 'mean_word_length': 3.885228480340064, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 24, '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': '514833', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1471, 'n_words': 402}