Harro Verton avatar Harro Verton committed 58c07ca

set the version to 1.8.3-dev
changed private methods to protected so they can be extended
fixed form validation language file loading
fixed ar_* properties no longer accessable after being made protected
changed calls to lang->line() to lang->dm_line() to deal with missing language strings

Comments (0)

Files changed (1)

application/libraries/datamapper.php

 /**
  * DMZ version
  */
-define('DMZ_VERSION', '1.8.2');
+define('DMZ_VERSION', '1.8.3-dev');
 
 /**
  * Data Mapper Class
 	 * Loads the extensions that are local to this model.
 	 * @param	string $common_key Shared key to save extenions to.
 	 */
-	private function _initiate_local_extensions($common_key)
+	protected function _initiate_local_extensions($common_key)
 	{
 		if(!empty($this->extensions))
 		{
 		{
 			if ( ! isset($this->form_validation) )
 			{
-				if( ! isset($CI->form_validation))
-				{
-					$CI->load->library('form_validation');
-					$this->lang->load('form_validation');
-				}
+				isset($CI->form_validation) OR $CI->load->library('form_validation');
+
 				$this->form_validation =& $CI->form_validation;
+				$this->lang->load('form_validation');
 			}
+
 			return $this->form_validation;
 		}
 
 	 * @param string $related Related Name
 	 * @return DataMapper|NULL
 	 */
-	private function &_get_without_auto_populating($related)
+	protected function &_get_without_auto_populating($related)
 	{
 		$b_many = $this->auto_populate_has_many;
 		$b_one = $this->auto_populate_has_one;
 	 * @param	object $which One of 'both', 'local', or 'global'
 	 * @return	bool TRUE if the method can be called.
 	 */
-	private function _extension_method_exists($method, $which = 'both') {
+	protected function _extension_method_exists($method, $which = 'both') {
 		$found = FALSE;
 		if($which != 'global') {
 			$found =  ! empty($this->extensions) && isset($this->extensions['_methods'][$method]);
 
 		// for performance, we clear out the select AND the order by statements,
 		// since they aren't necessary and might slow down the query.
-		$count_query->db->ar_select = NULL;
-		$count_query->db->ar_orderby = NULL;
-		$total = $count_query->db->ar_distinct ? $count_query->count_distinct() : $count_query->count();
+		$count_query->db->dm_set('ar_select', NULL);
+		$count_query->db->dm_set('ar_orderby', NULL);
+		$total = $count_query->db->dm_get('ar_distinct') ? $count_query->count_distinct() : $count_query->count();
 
 		// common vars
 		$last_row = $page_size * floor($total / $page_size);
 	 * @param	array $arguments
 	 * @return	bool
 	 */
-	private function _save($related_field, $arguments)
+	protected function _save($related_field, $arguments)
 	{
 		return $this->save($arguments[0], $related_field);
 	}
 	 * Gets a timestamp to use when saving.
 	 * @return mixed
 	 */
-	private function _get_generated_timestamp()
+	protected function _get_generated_timestamp()
 	{
 		// Get current timestamp
 		$timestamp = ($this->local_time) ? date($this->timestamp_format) : gmdate($this->timestamp_format);
 	 * @param	array $arguments
 	 * @return	bool
 	 */
-	private function _delete($related_field, $arguments)
+	protected function _delete($related_field, $arguments)
 	{
 		return $this->delete($arguments[0], $related_field);
 	}
 					{
 						if(!is_string($line))
 						{
-							if (FALSE === ($line = $this->lang->line($rule)))
+							if (FALSE === ($line = $this->lang->dm_line($rule)))
 							{
 								// Get corresponding error from language file
 								$line = 'Unable to access an error message corresponding to your rule name: '.$rule.'.';
 			$relationship_table = $this->_get_relationship_table($object, $related_field);
 
 			// To ensure result integrity, group all previous queries
-			if( ! empty($this->db->ar_where))
+			$where = $this->db->dm_get('ar_where');
+			if( ! empty($where))
 			{
 				// if the relationship table is different from our table, include our table in the count query
 				if ($relationship_table != $this->table)
 					$this->db->join($this->table, $this->table . '.id = ' . $relationship_table . '.' . $this_model.'_id', 'LEFT OUTER');
 				}
 
-				array_unshift($this->db->ar_where, '( ');
-				$this->db->ar_where[] = ' )';
+				$arwhere = $this->db->dm_get('ar_where');
+				array_unshift($arwhere, '( ');
+				$arwhere[] = ' )';
+				$this->db->dm_set('ar_where', $arwhere);
 			}
 
 			// We have to query special for in-table foreign keys that
 	 * @param	array $value Arguments to this method.
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _get_by($field, $value = array())
+	protected function _get_by($field, $value = array())
 	{
 		if (isset($value[0]))
 		{
 	 * @param	array $arguments Arguments to the where method
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _get_by_related($model, $arguments = array())
+	protected function _get_by_related($model, $arguments = array())
 	{
 		if ( ! empty($model))
 		{
 	}
 
 	// private method to convert function arguments into SQL
-	private function _process_function_arg($arg, $is_formula = FALSE)
+	protected function _process_function_arg($arg, $is_formula = FALSE)
 	{
 		$ret = '';
 		if(is_array($arg)) {
 	 * @param	array $args Arguments for func()
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _func($query, $args)
+	protected function _func($query, $args)
 	{
 		if(count($args) < 2)
 		{
 	 * @param	array $args Arguments for func()
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _field_func($query, $args)
+	protected function _field_func($query, $args)
 	{
 		if(count($args) < 2)
 		{
 	 * @param	array $args Arguments for subquery
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _subquery($query, $args)
+	protected function _subquery($query, $args)
 	{
 		if(count($args) < 1)
 		{
 	protected function _add_to_select_directly($value)
 	{
 		// copied from system/database/DB_activerecord.php
-		$this->db->ar_select[] = $value;
-
-		if ($this->db->ar_caching === TRUE)
-		{
-			$this->db->ar_cache_select[] = $value;
-			$this->db->ar_cache_exists[] = 'select';
+		$var = $this->db->dm_get('ar_select');
+		$var[] = $value;
+		$this->db->dm_set('ar_select', $var);
+
+		if ($this->db->dm_get('ar_caching') === TRUE)
+		{
+			$var = $this->db->dm_get('ar_cache_select');
+			$var[] = $value;
+			$this->db->dm_set('ar_cache_select', $var);
+
+			$var = $this->db->dm_get('ar_cache_exists');
+			$var[] = 'select';
+			$this->db->dm_set('ar_cache_exists', $var);
 		}
 	}
 
 	 * @param	mixed $extra If included, overrides the default assumption of FALSE for the third parameter to $query
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _process_special_query_clause($query, $field, $value, $extra = NULL) {
+	protected function _process_special_query_clause($query, $field, $value, $extra = NULL) {
 		if(strpos($query, 'where_in') !== FALSE) {
 			$query = str_replace('_in', '', $query);
 			$field .= ' IN ';
 
 		$this->_where_group_started = TRUE;
 
-		$prefix = (count($this->db->ar_where) == 0 AND count($this->db->ar_cache_where) == 0) ? '' : $type;
+		$prefix = (count($this->db->dm_get('ar_where')) == 0 AND count($this->db->dm_get('ar_cache_where')) == 0) ? '' : $type;
 
 		$value =  $prefix . $not . str_repeat(' ', $this->_group_count) . ' (';
-		$this->db->ar_where[] = $value;
-		if($this->db->ar_caching) $this->db->ar_cache_where[] = $value;
+
+		$var = $this->db->dm_get('ar_where');
+		$var[] = $value;
+		$this->db->dm_set('ar_where', $var);
+
+		if ($this->db->dm_get('ar_caching'))
+		{
+			$var = $this->db->dm_get('ar_cache_where');
+			$var[] = $value;
+			$this->db->dm_set('ar_cache_where', $var);
+		}
 
 		return $this;
 	}
 	public function group_end()
 	{
 		$value = str_repeat(' ', $this->_group_count) . ')';
-		$this->db->ar_where[] = $value;
+		$var = $this->db->dm_get('ar_where');
+		$var[] = $value;
+		$this->db->dm_set('ar_where', $var);
+
 		if($this->db->ar_caching) $this->db->ar_cache_where[] = $value;
 
 		$this->_where_group_started = FALSE;
 	{
 		$type = $this->_get_prepend_type($type);
 
-	 	$this->db->dm_call_method('_where', "`$key` ".($not?"NOT ":"")."BETWEEN ".$value1." AND ".$value2, NULL, $type, NULL);
+	 	$this->db->dm_call_method('_where', $this->add_table_name($key)." ".($not?"NOT ":"")."BETWEEN ".$value1." AND ".$value2, NULL, $type, NULL);
 
 		// For method chaining
 		return $this;
 				$rule = 'transaction';
 
 				// Get corresponding error from language file
-				if (FALSE === ($line = $this->lang->line($rule)))
+				if (FALSE === ($line = $this->lang->dm_line($rule)))
 				{
 					$line = 'Unable to access the ' . $rule .' error message.';
 				}
 	 * @param	mixed $extra Used to prevent escaping in special circumstances.
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _related($query, $arguments = array(), $extra = NULL)
+	protected function _related($query, $arguments = array(), $extra = NULL)
 	{
 		if ( ! empty($query) && ! empty($arguments))
 		{
 	 * @param	object $args Arguments for the query
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _related_subquery($query, $args)
+	protected function _related_subquery($query, $args)
 	{
 		$rel_object = $args[0];
 		$field = $value = NULL;
 		$object->select_func('COUNT', '*', 'count');
 		$this_rel = $related_properties['other_field'];
 		$tablename = $object->_add_related_table($this, $this_rel);
-		$object->where($tablename . '.id  = ', $this->db->dm_call_method('_escape_identifiers', '${parent}.id'), FALSE);
+		$object->where($tablename . '.`id` = ', $this->db->dm_call_method('_escape_identifiers', '${parent}.id'), FALSE);
 		$this->select_subquery($object, $alias);
 		return $this;
 	}
 	 * @param	int $id ID of related field or object
 	 * @return	bool Sucess or Failure
 	 */
-	private function _get_relation($related_field, $id)
+	protected function _get_relation($related_field, $id)
 	{
 		// No related items
 		if (empty($related_field) || empty($id))
 			{
 				$msg = 'dm_save_rel_failed';
 			}
-			$msg = $this->lang->line($msg);
+			$msg = $this->lang->dm_line($msg);
 			$this->error_message($related_field, sprintf($msg, $related_field));
 		}
 
 	 * @param string $rf Related field to look at.
 	 * @param DataMapper $object Object to look at.
 	 */
-	private function _remove_other_one_to_one($rf, $object)
+	protected function _remove_other_one_to_one($rf, $object)
 	{
 		if( ! $object->exists())
 		{
 	 * @param	array $ids list of IDs we've already found.
 	 * @return	int Number of items found.
 	 */
-	private function _count_related_objects($compare, $object, $related_field, &$ids)
+	protected function _count_related_objects($compare, $object, $related_field, &$ids)
 	{
 		$count = 0;
 		if (is_array($object))
 	 * @param	array $arguments Arguments for query.
 	 * @return	DataMapper Returns self for method chaining.
 	 */
-	private function _join_field($query, $arguments)
+	protected function _join_field($query, $arguments)
 	{
 		if ( ! empty($query) && count($arguments) >= 3)
 		{
 			$r[] = $field;
 		}
 		$key = str_replace($s, $r, $key);
-		return $this->lang->line($key);
+		return $this->lang->dm_line($key);
 	}
 
 	// --------------------------------------------------------------------
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.