<commit_before><?php
/**
 * Garp_Model_Db
 * Model implementation for database tables.
 * @author $Author: $
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Model
 * @lastmodified $Date: $
 */
abstract class Garp_Model_Db extends Zend_Db_Table_Abstract implements Garp_Model, Garp_Util_Observer, Garp_Util_Observable {
	/**
	 * The table name.
	 * @var String
	 */
	protected $_name;
	

	/**
 	 * The join table name. This is the name of an SQL view containing the 
 	 * original table along with display fields for all possible belongsTo 
 	 * related records.
 	 * @var String
 	 */
	protected $_jointView;


	/**
	 * Default sorting of queries
	 * @var Mixed Any type that's accepted by Zend_Db_Select::order()
	 */
	protected $_defaultOrder = null;

	
	/**
	 * Collection of model names that might be bound to this model in the future.
	 * This is used by the core Cachable behavior. Models that are in this array
	 * also get their cache cleared when a record of this model is updated.
	 * @var Array
	 */
	protected $_bindable = array();
	
	
	/**
	 * Custom rowset class
	 * @var String
	 */
	protected $_rowsetClass = 'Garp_Db_Table_Rowset';
	
	
	/**
	 * Custom row class
	 * @var String
	 */
	protected $_rowClass = 'Garp_Db_Table_Row';
	
	
	/**
	 * Collection of observers
	 * @var Array
	 */
	protected $_observers = array();
	
	
	/**
	 * Wether to cache queries
	 * @var Boolean
	 */
	protected static $_cacheQueries = true;


	/**
 	 * Configuration.
 	 * @var Array
 	 */
	protected $_configuration = array();
	
	
    /**
     * Initialize object
     * Called from {@link __construct()} as final step of object instantiation.
     * @return Void
     */
	public function init() {
		/**
		 * Register core behaviors and also this model itself, 
		 * to allow for callback methods in the models themselves.
		 */
		$this->registerObserver($this)
			 ->registerObserver(new Garp_Model_Behavior_Bindable())
			 ->registerObserver(new Garp_Model_Behavior_DefaultSortable())
			 ->registerObserver(new Garp_Model_Behavior_Cachable())
		;
	}
	
	
	/**
	 * Get name without namespace
	 * @return String 
	 */
	public function getNameWithoutNamespace() {
		$name = get_class($this);
		$name = explode('_', $name);
		return array_pop($name);
	}


	/**
 	 * Get namespace
 	 * @return String
 	 */
	public function getNamespace() {
		$name = get_class($this);
		$name = explode('_', $name);
		return array_shift($name);
	}
	

	/**
 	 * Get configuration
 	 * @param String $key Pick one specific configuration item.
 	 * @return Array
 	 */
	public function getConfiguration($key = null) {
		if ($key) {
			if (!array_key_exists($key, $this->_configuration)) {
				throw new Exception("'$key' is not a valid configuration key.");
			}
			return $this->_configuration[$key];
		}
		return $this->_configuration;
	}


	/**
 	 * Get field configuration
 	 * @param String $column
 	 * @return Array
 	 */
	public function getFieldConfiguration($column) {
		$fields = $this->getConfiguration('fields');
		foreach ($fields as $key => $value) {
			if ($value['name'] == $column) {
				return $value;
			}
		}
		return null;
	}

	
	/**
	 * Convenience method for creating SELECT objects
     * @param string|array|Zend_Db_Table_Select $where  OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
     * @param string|array                      $order  OPTIONAL An SQL ORDER clause.
     * @param int                               $count  OPTIONAL An SQL LIMIT count.
     * @param int                               $offset OPTIONAL An SQL LIMIT offset.
     * @return Zend_Db_Table_Select
	 */
	public function createSelect($where = null, $order = null, $count = null, $offset = null) {
		$select = $this->select();

		if ($where !== null) {
			$this->_where($select, $where);
		}

		if ($order !== null) {
			$this->_order($select, $order);
		}

		if ($count !== null || $offset !== null) {
			$select->limit($count, $offset);
		}
		return $select;
	}
	
	<commit_msg>Added arrayToWhereClause() convenience method<commit_after><?php
/**
 * Garp_Model_Db
 * Model implementation for database tables.
 * @author $Author: $
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Model
 * @lastmodified $Date: $
 */
abstract class Garp_Model_Db extends Zend_Db_Table_Abstract implements Garp_Model, Garp_Util_Observer, Garp_Util_Observable {
	/**
	 * The table name.
	 * @var String
	 */
	protected $_name;
	

	/**
 	 * The join table name. This is the name of an SQL view containing the 
 	 * original table along with display fields for all possible belongsTo 
 	 * related records.
 	 * @var String
 	 */
	protected $_jointView;


	/**
	 * Default sorting of queries
	 * @var Mixed Any type that's accepted by Zend_Db_Select::order()
	 */
	protected $_defaultOrder = null;

	
	/**
	 * Collection of model names that might be bound to this model in the future.
	 * This is used by the core Cachable behavior. Models that are in this array
	 * also get their cache cleared when a record of this model is updated.
	 * @var Array
	 */
	protected $_bindable = array();
	
	
	/**
	 * Custom rowset class
	 * @var String
	 */
	protected $_rowsetClass = 'Garp_Db_Table_Rowset';
	
	
	/**
	 * Custom row class
	 * @var String
	 */
	protected $_rowClass = 'Garp_Db_Table_Row';
	
	
	/**
	 * Collection of observers
	 * @var Array
	 */
	protected $_observers = array();
	
	
	/**
	 * Wether to cache queries
	 * @var Boolean
	 */
	protected static $_cacheQueries = true;


	/**
 	 * Configuration.
 	 * @var Array
 	 */
	protected $_configuration = array();
	
	
    /**
     * Initialize object
     * Called from {@link __construct()} as final step of object instantiation.
     * @return Void
     */
	public function init() {
		/**
		 * Register core behaviors and also this model itself, 
		 * to allow for callback methods in the models themselves.
		 */
		$this->registerObserver($this)
			 ->registerObserver(new Garp_Model_Behavior_Bindable())
			 ->registerObserver(new Garp_Model_Behavior_DefaultSortable())
			 ->registerObserver(new Garp_Model_Behavior_Cachable())
		;
	}
	
	
	/**
	 * Get name without namespace
	 * @return String 
	 */
	public function getNameWithoutNamespace() {
		$name = get_class($this);
		$name = explode('_', $name);
		return array_pop($name);
	}


	/**
 	 * Get namespace
 	 * @return String
 	 */
	public function getNamespace() {
		$name = get_class($this);
		$name = explode('_', $name);
		return array_shift($name);
	}
	

	/**
 	 * Get configuration
 	 * @param String $key Pick one specific configuration item.
 	 * @return Array
 	 */
	public function getConfiguration($key = null) {
		if ($key) {
			if (!array_key_exists($key, $this->_configuration)) {
				throw new Exception("'$key' is not a valid configuration key.");
			}
			return $this->_configuration[$key];
		}
		return $this->_configuration;
	}


	/**
 	 * Get field configuration
 	 * @param String $column
 	 * @return Array
 	 */
	public function getFieldConfiguration($column) {
		$fields = $this->getConfiguration('fields');
		foreach ($fields as $key => $value) {
			if ($value['name'] == $column) {
				return $value;
			}
		}
		return null;
	}


	/**
 	 * Convert array to WHERE clause
 	 * @param Array $data
 	 * @param Boolean $and Wether to use AND or OR
 	 * @return String
 	 */
	public function arrayToWhereClause(array $data, $and = true) {
		$out = array();
		$adapter = $this->getAdapter();
		foreach ($data as $key => $value) {
			$quotedKey = $adapter->quoteIdentifier($key);
			$quotedValue = $adapter->quote($value);
			$out[] = "$quotedKey = $quotedValue";
		}
		$glue = $and ? 'AND' : 'OR';
		$out = implode(" $glue ", $out);
		return $out;
	}

	
	/**
	 * Convenience method for creating SELECT objects
     * @param string|array|Zend_Db_Table_Select $where  OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
     * @param string|array                      $order  OPTIONAL An SQL ORDER clause.
     * @param int                               $count  OPTIONAL An SQL LIMIT count.
     * @param int                               $offset OPTIONAL An SQL LIMIT offset.
     * @return Zend_Db_Table_Select
	 */
	public function createSelect($where = null, $order = null, $count = null, $offset = null) {
		$select = $this->select();

		if ($where !== null) {
			$this->_where($select, $where);
		}

		if ($order !== null) {
			$this->_order($select, $order);
		}

		if ($count !== null || $offset !== null) {
			$select->limit($count, $offset);
		}
		return $select;
	}
	
	
{'fraction_non_alphanumeric': 0.12599160055996267, 'fraction_numerical': 0.0, 'mean_word_length': 2.961645101663586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5276170', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2538, 'n_words': 794}