diff --git a/Change Log.txt b/Change Log.txt
index 3a6ce93..4d27748 100644
--- a/Change Log.txt
+++ b/Change Log.txt
@@ -1,14 +1,46 @@
/**
* Channel Data
* Author: Justin Kimbrell (Objective HTML)
-* @version 0.8.15
-* @build 20121217
-* Copyright 2012 - All rights reserved
+* @version 1.0.0-rc3
+* @build 2014-03-03
+* Copyright 2013 - All rights reserved
* http://objectivehtml.com
*/
+#### 2014-03-03
+##### 1.0.0-rc3
+
+- Added get() method to QueryResponse
+- Added toArray() method to QueryResponse
+- Added fixedOrder parameter to entries() method in Channel Response
+- Added findByUsername() to Member
+- Added label() method to ChannelField
+- Added findByName() method to ChannelField
+- Added findByName() method to ChannelField
+- Added groupBy() method to QueryBuilder
+- Added prefix() method to ChannelData
+- Added entries() method to ChannelModel
+- Added new ChannelEntriesParser class
+- Bug fixes in QueryString class
+- Bug fixes in QueryBuilder class
+- Bug fixes in ChannelEntriesApi class
+
+#### 2013-12-16
+##### 1.0.0-rc2
+
+- Decoupled Channel Data into it’s own “module”.
+- Added more models and helper methods
+
+
+#### 2013-12-10
+##### 1.0.0-rc1
+
+- Complete rewrite of entire API. All new docs and syntax based on Eloquent.
+
+
Version 0.8.16 - 12/15/2012
--------------------------
+
- Fixed a bug that caused OR operators to not work properly
Version 0.8.15 - 12/15/2012
diff --git a/Channel_data/.DS_Store b/Channel_data/.DS_Store
deleted file mode 100644
index b29c585..0000000
Binary files a/Channel_data/.DS_Store and /dev/null differ
diff --git a/Channel_data/Channel_data.php b/Channel_data/Channel_data.php
deleted file mode 100644
index 31ea5c5..0000000
--- a/Channel_data/Channel_data.php
+++ /dev/null
@@ -1,86 +0,0 @@
-drivers;
-
- $this->load_drivers($drivers);
- }
-
- /**
- * Load Drivers
- *
- * Loads the Channel Data driver
- *
- * @param mixed You can override the default drivers by passing
- an array of drivers to load.
- * @return void
- */
-
- public function load_drivers($drivers = FALSE)
- {
- $this->drivers = $drivers ? $drivers : $this->drivers;
-
- foreach($this->drivers as $driver)
- {
- $driver = ucfirst($driver);
- $obj = str_replace(array(__CLASS__.'_',strtolower(__CLASS__.'_')),'', $driver);
- $path = 'drivers/' . ucfirst($driver) . '.php';
-
- include_once($path);
-
- if(class_exists($driver))
- {
- $this->$obj = new $driver();
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Channel_data/Channel_data_lib.php b/Channel_data/Channel_data_lib.php
deleted file mode 100644
index 8bd883d..0000000
--- a/Channel_data/Channel_data_lib.php
+++ /dev/null
@@ -1,1959 +0,0 @@
-\=', '\<', '\>', '\=', 'like', 'LIKE');
-
- // A list of common ambitious fields
-
- private $ambigious_fields = array(
- 'entry_id',
- 'site_id',
- 'channel_id'
- );
-
- // A list of the reserved SQL terms
-
- private $reserved_terms = array(
- 'select', 'like', 'or_like', 'or_where', 'where', 'where_in',
- 'order_by', 'sort', 'limit', 'offset', 'join', 'left join', 'inner join', 'outer join', 'having', 'group_by'
- );
-
- /**
- * Construct
- *
- * Gets the instance variable
- *
- * @param array Additional parameters used to instatiate the object
- * @return void
- */
-
- public function __construct($params = array())
- {
- $this->EE =& get_instance();
- }
-
- public function strip_logic($field)
- {
- foreach(array("or", "OR", 'and', 'AND') as $condition)
- {
- $field = trim(preg_replace('/^'.$condition.'\s/', '', $field));
- }
-
- foreach($this->conditionals as $condition)
- {
- $field = preg_replace('/'.$condition.'/', '', $field);
- }
-
- return trim($field);
- }
-
- public function is_or($field)
- {
- $return = FALSE;
-
- if(preg_match("/((^|\s)or\s.+)|((^|\s)OR\s.+)/", $field))
- {
- $return = TRUE;
- }
-
- return $return;
- }
-
- public function build_concat($field)
- {
- $concat = ' AND ';
-
- if($this->is_or($field))
- {
- $concat = ' OR ';
- }
-
- return $concat;
- }
-
- public function build_operator($field, $value, $protect_identifiers = TRUE, $debug = FALSE)
- {
- $field = trim($field);
-
- $concat = ' AND ';
-
- if($this->is_or($field))
- {
- $concat = ' OR ';
-
- $field = $this->strip_logic($field);
- }
-
- if($this->is_or($value))
- {
- $concat = ' OR ';
-
- $value = $this->strip_logic($value);
- }
-
- $field = trim(preg_replace('/{\d}/', '', $field));
-
- if($protect_identifiers)
- {
- $field = $this->EE->db->protect_identifiers($field);
- }
-
- $conditional = $this->assign_conditional($field);
- $alt_conditional = $this->assign_conditional(' '.trim($value));
-
- if($conditional != $alt_conditional && trim($alt_conditional) != '=')
- {
- $conditional = $alt_conditional;
- $value = $this->strip_logic($value);
- }
-
- if(preg_match('/^\d*$/', $value))
- {
- $value = (float) $value;
- }
-
- return $concat . $this->remove_conditionals($field) . $conditional . $this->EE->db->escape($value);
- }
-
- public function build_operators($where = array(), $protect_identifiers = TRUE, $debug = FALSE)
- {
- $where_sql = array();
- $concat = NULL;
-
- foreach($where as $field => $values)
- {
- $field_name = $field;
- $field_sql = array();
-
- if(!is_array($values))
- {
- $values = array($field => array($values));
- }
-
- $reserved = array('channel_id', 'group_id', 'channel_data.channel_id', 'status', 'channel_titles.channel_id', 'channel_name', 'author_id', 'url_title', 'field_id_135', 'author_id', 'author_id', 'author_id', 'author_id', 'author_id', 'author_id');
-
- foreach($values as $field => $value)
- {
- if(!is_array($value))
- {
- $value = array($value);
- }
-
- if(preg_match('/^\d*$/', $field))
- {
- $field = $this->strip_logic($field_name);
- }
-
- $concat = $this->build_concat($field);
-
- foreach($value as $where_val)
- {
- $field_sql[] = $this->build_operator($field, $where_val, $protect_identifiers);
- }
- }
-
- $sql = trim(implode(' ', $field_sql));
-
-
- $where_sql[] = str_replace('()', '', $concat . '('.trim(ltrim(ltrim($sql, 'AND'), 'OR')).')');
- }
-
- $sql = trim(implode('', $where_sql));
- $sql = preg_replace("/^(AND|OR)|(AND|OR)$/", '', trim($sql));
-
- return $sql;
- }
-
- /**
- * Builds a select statement from a field array
- *
- * @access public
- * @param array Pass select parameters using index's
- * @param string A prefix for the title fields
- * @param string A prefix for the data fields
- * @return array
- */
-
- public function build_select($result_array, $title_prefix = '', $data_prefix = '')
- {
- $select = array(
- $title_prefix.'`entry_id`',
- $title_prefix.'`channel_id`',
- $title_prefix.'`title`',
- $title_prefix.'`author_id`',
- $title_prefix.'`entry_date`',
- $title_prefix.'`expiration_date`',
- $title_prefix.'`status`'
- );
-
- foreach($result_array as $row)
- {
- $row = (object) $row;
-
- $select[] = $data_prefix.'`field_id_'.$row->field_id.'` as \''.$row->field_name.'\'';
- }
-
- return $select;
- }
-
- /**
- * Build a where array
- *
- * @access public
- * @param array Pass where parameters using index's and values
- * @param array Pass the valid channel fields to convert indexes
- * @param bool Private parameter used for debugging.
- * @return array
- */
-
- public function build_where($result_array, $field_array = array(), $debug = FALSE)
- {
- $where_array = array();
-
- foreach($result_array as $index => $values)
- {
- $conditional = '';
- $operator = '';
- $digit = '';
-
- if(!is_array($values))
- {
- $values = array($values);
- }
-
- $statements = array();
-
- foreach($values as $value)
- {
- if(preg_match('/^{\d}\s/', $index, $matches))
- {
- $digit = $matches[0];
- $index = str_replace($digit, '', $index);
- }
-
- foreach(array('or', 'and') as $word)
- {
- if(preg_match('/^'.$word.'\s/', strtolower($index), $matches))
- {
- $matches[0] = trim($matches[0]);
-
- if($matches[0] == 'or')
- {
- $operator = $matches[0].' ';
- }
-
- $index = trim(preg_replace('/^'.$word.'\s/', '', $index));
- }
- }
-
- foreach($this->conditionals as $condition)
- {
- if(preg_match('/'.$condition.'/', $index, $matches))
- {
- $conditional = ' '.$matches[0];
- }
-
- //$index = trim(preg_replace('/'.$condition.'/', '', $index));
- }
-
- if(isset($field_array[$index]))
- {
- $field_array[$index] = (object) $field_array[$index];
-
- unset($where_array[$index]);
-
- $statements[$digit.$operator.'field_id_'.$field_array[$index]->field_id.$conditional][] = $value;
- }
- else
- {
- $statements[$operator.$index][] = $value;
- }
- }
-
- $where_array[] = $statements;
- }
-
- return $where_array;
- }
-
- /**
- * Gets a specified table using polymorphic parameters
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get($table, $select = array(), $where = array(), $order_by = FALSE, $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- $this->convert_params($select, $where, $order_by, $sort, $limit, $offset);
-
- return $this->EE->db->get($table);
- }
-
- /**
- * Gets a single action_id from a class and method
- *
- * @access public
- * @param string A valid class name
- * @param string A method within the class
- * @return int
- */
-
- public function get_action_id($class, $method)
- {
- $return = $this->get_actions(array('*'), array(
- 'class' => ucfirst($class),
- 'method' => $method
- ));
-
- if($return->num_rows() == 0)
- return FALSE;
-
- return (int) $return->row('action_id');
- }
-
- /**
- * Gets records from the actions table using polymorphic
- * parameters.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_actions($select = array(), $where = array(), $order_by = FALSE, $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('actions', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get a single category by specifying a category id.
- *
- * @access public
- * @param int
- * @param mixed
- * @return string
- */
-
- public function get_category($category_id, $select = array('*'))
- {
- return $this->get_categories($select, array('cat_id' => $category_id));
- }
-
- /**
- * Get categories using on a series of polymorphic parameters that
- * returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_categories($select = array(), $where = array(), $order_by = 'cat_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('categories', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get categories using on a series of polymorphic parameters that
- * returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_entries($select = array(), $where = array(), $order_by = 'categories.cat_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- $fields = $this->get_category_fields()->result();
- $field_array = array();
- $field_select = array();
-
- //Default fields to select
-
- $default_select = array('categories.*');
-
- // If the parameter is polymorphic, then the variables are extracted
-
- if($this->is_polymorphic($select) && $polymorphic = $select)
- {
- extract($this->prepare_extract($select));
-
- foreach($this->reserved_terms as $term)
- {
- $var_name = str_replace(' ', '_', $term);
-
- if(!isset($polymorphic[$term]) && isset($$var_name) || isset($polymorphic[$term]))
- {
- $var_term = $$var_name;
-
- if($term == 'select' && !isset($var_term['select']))
- {
- $$var_name = $default_select;
- }
- else
- {
- $$var_name = isset($polymorphic[$term]) ? $polymorphic[$term] : $$var_name;
- }
- }
- }
- }
-
- // Selects the appropriate field name and converts where converts
- // where parameters to their corresponding m_field_id's
- foreach($fields as $field)
- {
- if(is_array($select))
- $select[] = 'field_id_'.$field->field_id.' as \''.$field->field_name.'\'';
-
- foreach($where as $index => $value)
- {
- $index = $this->check_ambiguity($index);
-
- if($field->field_name == $index)
- {
- unset($where[$index]);
- $where['field_id_'.$field->field_id] = $value;
- }
- }
- }
-
- // Joins the channel_data table
-
- $this->EE->db->join('category_field_data', 'categories.cat_id = category_field_data.cat_id');
-
- $params = array(
- 'select' => $select,
- 'where' => $where,
- 'order_by' => $order_by,
- 'sort' => $sort,
- 'limit' => $limit,
- 'offset' => $offset
- );
-
- // Converts the params into active record methods
-
- $this->convert_params($params, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE);
-
- return $this->get('categories', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get category field by specifying a field id.
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_category_field($field_id, $select = array('*'))
- {
- return $this->get_category_fields($select, array('field_id' => $field_id));
- }
-
- /**
- * Get category fields using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_fields($select = array(), $where = array(), $order_by = 'field_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('category_fields', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get category field data using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_field_data($select = array(), $where = array(), $order_by = 'cat_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('category_field_data', $select, $where, $order_by, $sort, $limit, $offset);
-
- }
-
- /**
- * Get category groups using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_group($group_id, $select = array('*'))
- {
- return $this->get_category_groups($select, array('group_id' => $group_id));
- }
-
- /**
- * Get category groups using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_by_group($group_id, $select = array('*'))
- {
- return $this->get_categories($select, array('group_id' => $group_id));
- }
-
- /**
- * Get category groups by using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_groups($select = array(), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('category_groups', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get the category posts by an entry id.
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_category_post($entry_id, $select = array('*'))
- {
- return $this->get_category_posts($select, array('entry_id' => $entry_id));
- }
-
- /**
- * Get the category posts using a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_category_posts($select = array(), $where = array(), $order_by = 'entry_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('category_posts', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get category groups by using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_categories($channel_id, $select = array(), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- $channel = $this->get_channel($channel_id);
- $new_where = array('group_id' => $channel->row('cat_group'));
-
- if($this->is_polymorphic($select))
- {
- if(!isset($select['where']))
- {
- $select['where'] = array();
- }
-
- $select['where'] = array_merge($select['where'], $new_where);
- }
- else
- {
- if(!is_array($where))
- {
- $where = array();
- }
-
- $where = array_merge($where, $new_where);
- }
-
- return $this->get('categories', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets a channel by specifying a channel_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_channel($channel_id, $select = array('*'))
- {
- return $this->get_channels($select, array('channel_id' => $channel_id));
- }
-
- /**
- * Get channel fields using a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channels($select = array(), $where = array(), $order_by = 'channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('channels', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets a channel by specifying a channel_name
- *
- * @access public
- * @param string A string containing a channel name
- * @param mixed An array or string of fields to select. Default: '*'
- * @return object
- */
-
- public function get_channel_by_name($channel_name, $select = array('*'))
- {
- return $this->get_channels($select, array('channel_name' => $channel_name));
- }
-
- /**
- * Get custom field from a specified field_id.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_field($field_id, $select = array('*'))
- {
- return $this->get_fields($select, array('field_id' => $field_id));
- }
-
- /**
- * Gets the custom fields by the group_id. This somehwat mimics the
- * the native get_channel_fields method.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_fields($channel_id = false, $select = array('*'), $where = array(), $order_by = 'field_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- if($channel_id !== FALSE)
- {
- $channel = $this->get_channel($channel_id)->row();
-
- if(isset($channel->field_group))
- {
- $group_id = array('group_id' => $channel->field_group);
- $where = array_merge($where, $group_id);
- }
- }
-
- return $this->get('channel_fields', $select, $where, $order_by, $sort, $limit, $offset);
-
- }
-
- /**
- * An alias to get_channel_fields and get_custom_fields.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_fields($select = array('*'), $where = array(), $order_by = 'field_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('channel_fields', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * An alias to get_channel_field and get_custom_field.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_field($field_id, $select = array('*'))
- {
- return $this->get_channel_field($field_id, $select);
- }
-
- /**
- * Get a custom field by specifying a field_name.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_field_by_name($field_name, $select = array('*'))
- {
- return $this->get_fields(array(
- 'select' => $select,
- 'where' => array(
- 'site_id' => config_item('site_id'),
- 'field_name' => $field_name
- )
- ));
- }
-
- /**
- * Get a custom field by specifying a field_name.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_fields_by_group($group_id = FALSE, $select = array('*'), $where = array(), $order_by = 'field_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
-
- if($this->is_polymorphic($select))
- {
- $select['where']['group_id'] = $group_id;
- }
- else
- {
- $where['group_id'] = $group_id;
- }
-
- return $this->get_fields($select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Alias to the get_fields_by_group method
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_field_group($group_id, $select = array('*'), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- if($this->is_polymorphic($select))
- {
- $select['where']['group_id'] = $group_id;
- }
- else
- {
- $where['group_id'] = $group_id;
- }
-
- return $this->get_field_groups($select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets all the field groups
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_field_groups($select = array('*'), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('field_groups', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get channel member groups by either a group_id or channel_id
- *
- * @access public
- * @param int
- * @param int
- * @return string
- */
-
- public function get_channel_member_group($group_id = FALSE, $channel_id = FALSE)
- {
- $where = array();
-
- if($group_id !== FALSE)
- $where['group_id'] = $group_id;
-
- if($channel_id !== FALSE)
- $where['channel_id'] = $channel_id;
-
- return $this->get('channel_member_groups', array(), $where, 'group_id', 'DESC', FALSE, 0);
- }
-
- /**
- * Get the channel member group using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_member_groups($channel_id, $select = array(), $where = array(), $order_by = 'channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('channel_member_groups', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets statuses by specifying a channel id. Polymorphic parameters are
- * still allowed.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_statuses($channel_id, $select = array('*'), $where = array(), $order_by = 'status_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- $channel = $this->get_channel($channel_id)->row();
-
- if(isset($channe->status_group))
- {
- if($this->is_polymorphic($select))
- {
- $select['where']['group_id'] = $channel->status_group;
- }
- else
- {
- $where['group_id'] = $channel->status_group;
- }
- }
-
- return $this->get('statuses', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get channel title using an entry id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_channel_title($entry_id, $select = array('*'))
- {
- return $this->get_channel_titles($select, array('entry_id' => $entry_id));
- }
-
- /**
- * Get channel titles using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_titles($select = array(), $where = array(), $order_by = 'channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('channel_titles', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get channel data using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_channel_data($select = array(), $where = array(), $order_by = 'channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('channel_data', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets channel entries using a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_entries($select = array('channel_data.entry_id', 'channel_data.channel_id', 'channel_titles.author_id', 'channel_titles.title', 'channel_titles.url_title', 'channel_titles.entry_date', 'channel_titles.expiration_date', 'status'), $where = array(), $order_by = 'channel_titles.channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get_channel_entries(FALSE, $select, $where = array(), $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Gets a single channel entry
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_entry($entry_id, $select = array('channel_data.entry_id', 'channel_data.channel_id', 'channel_titles.author_id', 'channel_titles.title', 'channel_titles.url_title', 'channel_titles.entry_date', 'channel_titles.expiration_date', 'status'))
- {
- return $this->get_channel_entry($entry_id, $select);
- }
-
- /**
- * Get a single entry specifying an entry id
- *
- * @access public
- * @param int
- * @param mixed
- * @return mixed
- */
-
- public function get_channel_entry($entry_id, $select = array('channel_data.entry_id', 'channel_data.channel_id', 'channel_titles.author_id', 'channel_titles.title', 'channel_titles.url_title', 'channel_titles.entry_date', 'channel_titles.expiration_date', 'status'))
- {
- $entry = $this->get_channel_title($entry_id);
-
- if($entry->num_rows() == 1)
- {
- $entry->row();
-
- return $this->get_channel_entries($entry->row('channel_id'), $select, array('channel_data.entry_id' => $entry_id));
- }
-
- return FALSE;
- }
-
- /**
- * Get entries by specifying a channel id. Polymorphic paramerts are
- * also accepted. The channel id is required.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
- public function get_channel_entries($channel_id, $select = array(), $where = array(), $order_by = 'channel_titles.channel_id', $sort = 'DESC', $limit = FALSE, $offset = 0, $debug = FALSE)
- {
- $default_select = array('channel_data.entry_id', 'channel_data.channel_id', 'channel_titles.author_id', 'channel_titles.title', 'channel_titles.url_title', 'channel_titles.entry_date', 'channel_titles.expiration_date', 'status');
-
- $default_select = ($select == array()) ? $default_select : (isset($select['select']) ? $select['select'] : $default_select);
-
- // If the parameter is polymorphic, then the variables are extracted
-
- if($this->is_polymorphic($select) && $polymorphic = $select)
- {
- extract($this->prepare_extract($select));
-
- foreach($this->reserved_terms as $term)
- {
- $var_name = str_replace(' ', '_', $term);
-
- if(!isset($polymorphic[$term]) && isset($$var_name) || isset($polymorphic[$term]))
- {
- $var_term = $$var_name;
-
- if($term == 'select' && !isset($var_term['select']))
- {
- $$var_name = $default_select;
- }
- else
- {
- $$var_name = isset($polymorphic[$term]) ? $polymorphic[$term] : $$var_name;
- }
- }
- }
- }
-
- if(count($select) == 0)
- {
- $select = $default_select;
- }
-
- // If the channel_id is not false then only the specified channel fields are
- // appended to the query. Otherwise, all fields are appended.
- $where_array = array();
-
- if($channel_id !== FALSE)
- {
- //$where_array = array('channel_data.channel_id' => $channel_id);
- $fields = $this->get_channel_fields($channel_id)->result();
- $this->EE->db->where('channel_data.channel_id', $channel_id);
- }
- else
- {
- $fields = $this->get_fields()->result();
- $select = array();
- }
-
- if(is_array($where))
- {
- $where_array = array_merge($where_array, $where);
- }
-
- $field_array = array();
-
- foreach($fields as $field)
- {
- $field_array[$field->field_name] = $field;
- }
-
- $select = $this->build_select($fields, 'channel_titles.', 'channel_data.');
- $where = $this->build_where($where_array, $field_array, $debug);
-
- // Joins the channel_data table
-
- $this->EE->db->join('channel_data', 'channel_titles.entry_id = channel_data.entry_id');
-
- if(!is_array($default_select))
- {
- $default_select = array($default_select);
- }
-
- $params = array(
- 'select' => array_merge($default_select, $select),
- 'where' => $where,
- 'order_by' => $this->check_ambiguity($order_by),
- 'sort' => $sort,
- 'limit' => $limit,
- 'offset' => $offset
- );
-
- foreach(array('join', 'inner join', 'left join', 'outer join', 'having', 'group_by') as $keyword)
- {
- $keyword_var = str_replace(' ', '_', $keyword);
-
- if(isset($$keyword_var))
- {
- $params[$keyword] = $$keyword_var;
- }
- }
-
- $this->convert_params($params, FALSE, FALSE, FALSE, FALSE, FALSE, $debug);
-
- return $this->EE->db->get('channel_titles');
- }
-
- /**
- * Get a single member by specifying a member_id. The custom fields
- * are automatically joined in the query just like entries.
- *
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_member($member_id, $select = array('member_data.*', 'members.*'))
- {
- return $this->get_members(array(
- 'select' => $select,
- 'where' => array(
- 'members.member_id' => $member_id
- )
- ));
- }
-
- /**
- * Get members using the standard polymorphic parameters. The custom
- * fields are automatically joined in the query just like entries.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_members($select = array('members.member_id', 'members.group_id', 'members.email', 'members.username', 'members.screen_name'), $where = array(), $order_by = 'member_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
-
- $fields = $this->get_member_fields()->result();
- $field_array = array();
- $field_select = array();
-
- //Default fields to select
-
- $default_select = array('members.*');
-
- // If the parameter is polymorphic, then the variables are extracted
-
- if($this->is_polymorphic($select) && $polymorphic = $select)
- {
- extract($this->prepare_extract($select));
-
- foreach($this->reserved_terms as $term)
- {
- $var_name = str_replace(' ', '_', $term);
-
- if(!isset($polymorphic[$term]) && isset($$var_name) || isset($polymorphic[$term]))
- {
- $var_term = $$var_name;
-
- if($term == 'select' && !isset($var_term['select']))
- {
- $$var_name = $default_select;
- }
- else
- {
- $$var_name = isset($polymorphic[$term]) ? $polymorphic[$term] : $$var_name;
- }
- }
- }
- }
-
- // Selects the appropriate field name and converts where converts
- // where parameters to their corresponding m_field_id's
- foreach($fields as $field)
- {
- if(!is_array($select))
- {
- $select = array($select);
- }
-
- $select[] = 'm_field_id_'.$field->m_field_id.' as \''.$field->m_field_name.'\'';
-
- foreach($where as $index => $value)
- {
- $index = $this->check_ambiguity($index);
-
- if($field->m_field_name == $index)
- {
- unset($where[$index]);
- $where['m_field_id_'.$field->m_field_id] = $value;
- }
- }
- }
-
- // Joins the channel_data table
-
- $this->EE->db->join('member_data', 'members.member_id = member_data.member_id', 'left');
-
- $params = array(
- 'select' => $select,
- 'where' => $where,
- 'order_by' => $order_by,
- 'sort' => $sort,
- 'limit' => $limit,
- 'offset' => $offset
- );
-
- // Converts the params into active record methods
-
- $this->convert_params($params, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE);
-
- return $this->EE->db->get('members');
- }
-
- /**
- * Get members directly using the standard polymorphic parameters.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_member_data($select = array(), $where = array(), $order_by = 'rel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('member_data', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get members fields using the standard polymorphic parameters.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_member_fields($select = array(), $where = array(), $order_by = 'm_field_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('member_fields', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get a single member field by specifying a field_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_member_field($field_id, $select = array('*'))
- {
- return $this->get_member_fields(array(
- 'select' => $select,
- 'where' => array(
- 'm_field_id' => $field_id
- )
- ));
- }
-
- /**
- * Get a single member field by specifying a field_name
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_member_field_by_name($field_name, $select = array('*'))
- {
- return $this->get_member_fields(array(
- 'select' => $select,
- 'where' => array(
- 'm_field_name' => $field_name
- )
- ));
- }
-
- /**
- * Get member groups using the standard polymorphic parameters.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_member_groups($select = array(), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('member_groups', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get a member group by specifying a group_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_member_group($group_id, $select = array('*'))
- {
- return $this->get_member_groups(array(
- 'select' => $select,
- 'where' => array(
- 'group_id' => $group_id
- )
- ));
- }
-
- /**
- * Get a member group by specifying a group_title
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_member_group_by_title($title, $select = array('*'))
- {
- return $this->get_member_groups(array(
- 'select' => $select,
- 'where' => array(
- 'group_title' => $title
- )
- ));
- }
-
- /**
- * Get a single relationship by specifying an relationship id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_relationship($rel_id, $select = array('*'))
- {
- return $this->get_relationships($select, array('rel_id' => $rel_id));
- }
-
- /**
- * Get relationships by using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_relationships($select = array(), $where = array(), $order_by = 'rel_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('relationships', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get child relationships by specifying an entry_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_related_child_entries($entry_id, $select = '*')
- {
- return $this->get_relationships(array(
- 'select' => $select,
- 'where' => array(
- 'rel_child_id' => $entry_id
- )
- ));
- }
-
- /**
- * Get parent relationships by specifying an entry_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_related_entries($entry_id, $select = '*')
- {
- return $this->get_relationships(array(
- 'select' => $select,
- 'where' => array(
- 'rel_parent_id' => $entry_id
- )
- ));
- }
-
- /**
- * Get related parent entries by specifying an entry_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_related_parent_entries($entry_id, $select = '*')
- {
- return $this->get_related_entries($entry_id, $select);
- }
-
- /**
- * Get status group by specifying a group_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_status_group($group_id, $select = '*')
- {
- return $this->get_status_groups($select, array(
- 'group_id' => $group_id
- ));
- }
-
- /**
- * Get status groups the standard polymorphic parameters.
- *
- * @access public
- * @param mixed
- * @param mixeds
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_status_groups($select = array(), $where = array(), $order_by = 'group_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('status_groups', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get status by specifying a status_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_status($status_id, $select = '*')
- {
- return $this->get_statuses($select, array(
- 'status_id' => $status_id
- ));
- }
-
- /**
- * Get statuses by specifying a group_id
- *
- * @access public
- * @param int
- * @param mixed
- * @return object
- */
-
- public function get_statuses_by_group($group_id, $select = '*', $where = array(), $order_by = 'status_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
-
- if($this->is_polymorphic($select))
- {
- $select['where']['group_id'] = $group_id;
- }
- else
- {
- $where['group_id'] = $group_id;
- }
-
- return $this->get_statuses($select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Get statuses by using on a series of polymorphic parameters
- * that returns an active record object.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return object
- */
-
- public function get_statuses($select = array(), $where = array(), $order_by = 'status_id', $sort = 'DESC', $limit = FALSE, $offset = 0)
- {
- return $this->get('statuses', $select, $where, $order_by, $sort, $limit, $offset);
- }
-
- /**
- * Return TRUE if category is a parent.
- *
- * @access public
- * @param int Category id
- * @return bool
- */
-
- public function is_parent_category($cat_id)
- {
- $category = $this->get_category($cat_id);
-
- if($category->num_rows() == 0)
- {
- return FALSE;
- }
-
- if($category->row('parent_id') == 0)
- {
- return TRUE;
- }
-
- return FALSE;
- }
-
- /**
- * Adds a set prefix to an ambigious database field
- *
- * @access public
- * @param string A database field name
- * @param string A prefix to add if the field is indeed ambiguous
- * @return object
- */
-
- public function check_ambiguity($field, $prefix = 'channel_titles.')
- {
- $field = str_replace($prefix, '', $field);
-
- foreach($this->ambigious_fields as $fields)
- {
- if($field == $fields)
- {
- $field = $prefix.$field;
- }
- }
-
- return $field;
- }
-
- /**
- * Convert Params
- *
- * Converts polymorphic parameters into an array that is used to
- * build the active record sequence.
- *
- * Example:
- *
- * $this->convert_params(array(
- * 'select' => array('channel_id', 'channel_name'),
- * 'where' => array('channel_id' => 1),
- * 'order_by' => 'channel_id'
- * ));
- *
- * $this->convert_params(array(
- * 'select' => '*',
- * 'order_by' => array('channel_description', 'channel_name'),
- * 'sort' => 'ASC'
- * ));
- *
- * $this->convert_params(array('*'), array('channel_id' => 1), 'channel_id', 'DESC', 1, 1);
- *
- * There are number of combinations possible that aren't even shown.
- *
- * @access public
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @param mixed
- * @return array
- */
-
- public function convert_params($select, $where, $order_by, $sort, $limit, $offset, $debug = FALSE)
- {
- if($this->is_polymorphic($select))
- {
- $subject = $select;
- unset($select);
-
- $keywords = $this->reserved_terms;
- foreach($keywords as $keyword)
- {
- $$keyword = isset($subject[$keyword]) ? $subject[$keyword] : (isset($$keyword) ? $$keyword : NULL);
- }
-
- if(isset($subject['select']))
- $select = $subject['select'];
- else
- if(!isset($select))
- $select = array('*');
- }
-
- $params = array(
- 'select' => $select,
- 'where' => $where,
- 'order_by' => $order_by,
- 'sort' => $sort,
- 'limit' => $limit,
- 'offset' => $offset
- );
-
- foreach(array('join', 'inner join', 'left join', 'outer join', 'having', 'group_by') as $keyword)
- {
- if(isset($$keyword))
- {
- $params[$keyword] = $$keyword;
- }
- }
-
- foreach($this->reserved_terms as $term)
- {
- if(isset($params[$term]) && $params[$term] !== FALSE)
- {
- $param = $params[$term];
-
- if($term == 'select')
- {
- if(!is_array($param))
- {
- $param = array($param);
- }
-
- foreach($param as $select)
- {
- $this->EE->db->select($select, FALSE, TRUE);
- }
- }
- else if($term == 'where')
- {
- $sql = $this->build_operators($param, TRUE, $debug);
-
- if(!empty($sql)) $this->EE->db->where($sql, FALSE, FALSE);
- }
- else if($term == 'order_by')
- {
- if(!is_array($param))
- {
- $order_params = array($param);
- }
-
- foreach($order_params as $param)
- {
- $sort = isset($sort) ? $sort : 'DESC';
-
- if($param)
- {
- $this->EE->db->order_by($param, $sort);
- }
- }
-
- }
- else if($term == 'limit')
- {
-
- if(!is_array($param))
- $param = array($param);
-
- $offset = isset($param['offset']) ? $param['offset'] : $offset;
- $offset = $offset !== FALSE ? $offset : 0;
-
- foreach($param as $param)
- $this->EE->db->limit($param, $offset);
-
- }
- else if(preg_match('/^(\w*|)( |)join/', $term, $matches))
- {
- if(is_array($param))
- {
- if(count($param) == 1)
- {
- $param = array($param);
- }
-
- foreach($param as $index => $row)
- {
- if(!is_array($row))
- {
- $row = array($index => $row);
- }
-
- foreach($row as $table => $on)
- {
- $this->EE->db->join($table, $on, !empty($matches[1]) ? $matches[1] : false);
- }
- }
- }
- }
- else if($term == 'having')
- {
- if(is_array($param))
- {
- $having_sql = array();
-
- foreach($param as $field => $value)
- {
- $field = preg_replace('/\{+\d+\}/', '', $field);
- if(!is_array($value)) $value = array($value);
-
- foreach($value as $where_val)
- {
- $where_field = trim($field);
-
- $concat = ' AND ';
-
- if(preg_match("/(^or\s.+)|(^OR\s.+)/", $where_field))
- {
- unset($params['where'][$field]);
-
- //$where_field = preg_replace("/^or.+/", "", $field);
-
- $where_field = trim(str_replace(array("or ", "OR "), '', $field));
- $concat = ' OR ';
- }
-
- $having_sql[] = $concat . $this->remove_conditionals($this->EE->db->protect_identifiers($where_field)) . $this->assign_conditional($where_field) . $this->EE->db->escape($where_val);
-
- }
- }
-
- $sql = trim(implode(' ', $having_sql));
- $sql = trim(ltrim(ltrim($sql, 'AND'), 'OR'));
-
- if(!empty($sql)) $this->EE->db->having($sql, FALSE, FALSE);
- }
- }
- else if($term == 'group_by')
- {
- if(is_string($param))
- {
- $this->EE->db->group_by($param);
- }
- }
- }
- }
-
- return $params;
- }
-
- /**
- * Strips conditionals from a string
- *
- * @access public
- * @param string
- * @return object
- */
-
- public function remove_conditionals($subject)
- {
- foreach($this->conditionals as $condition)
- {
- $match = str_replace('\\', '', $condition);
- $subject = str_replace($match, '', $subject);
- }
-
- return $subject;
- }
-
- /**
- * Assign a conditional based on the presence of a logical operator
- *
- * @access public
- * @param string
- * @return object
- */
-
- public function assign_conditional($str, $debug = FALSE)
- {
- $conditionals = $this->conditionals;
- $match = FALSE;
-
- foreach($conditionals as $condition)
- {
- $matches = array();
-
- if(preg_match('/\s+'.$condition.'/', $str, $matches))
- {
- $match = TRUE;
- $return = $condition;
-
- break;
- }
-
- if(!$match) $return = '=';
- }
-
- return ' '.str_replace('\\', '', $return).' ';
- }
-
- /**
- * Is Polymorphic
- *
- * Determines if a parameter is polymorphic
- *
- * @access public
- * @param mixed A mixed value variable
- * @return bool
- */
-
- public function is_polymorphic($param)
- {
- if(is_array($param))
- {
- foreach($this->reserved_terms as $term)
- {
- if(isset($param[$term]))
- {
- return TRUE;
- }
- }
-
- }
-
- return FALSE;
- }
-
- public function prepare_extract($vars)
- {
- if(!is_array($vars))
- {
- $vars = array($vars);
- }
-
- $new_array = array();
-
- foreach($vars as $index => $var)
- {
- $new_array[str_replace(' ', '_', $index)] = $var;
- }
-
- return $new_array;
- }
- }
-}
\ No newline at end of file
diff --git a/Channel_data/drivers/Channel_data_api.php b/Channel_data/drivers/Channel_data_api.php
deleted file mode 100644
index 5013dc0..0000000
--- a/Channel_data/drivers/Channel_data_api.php
+++ /dev/null
@@ -1,169 +0,0 @@
-get_module_info($module));
-
- if(file_exists($path))
- {
- include_once($path);
-
- if(class_exists($module_api))
- {
- return TRUE;
- }
- else
- {
- show_error('The class '.$module_name.' does not exist. Check that your files are named correctly, and that the module has a valid API (api.'.$module_name.'.php).');
- }
- }
- else
- {
- show_error('The '.$module_name.' API cannot be found. Double check that your module name is correct and that the module has a valid API (api.'.$module_name.'.php).');
- }
-
- return FALSE;
- }
-
- /**
- * Get Module Info
- *
- * Creates and array with information about the module
- *
- * @access public
- * @param type description
- * @return void
- */
-
- public function get_module_info($module)
- {
- return array(
- 'module' => $modulue = strtolower($module),
- 'module_api' => $module_api = ucfirst($module).'_api',
- 'package' => $package = PATH_THIRD . $module,
- 'path' => $package . '/api.' . $module . '.php'
- );
- }
-
- /**
- * Load
- *
- * Instantiates a new instance of the module class
- *
- * @access public
- * @param string Name of the module being loaded
- * @param array An array of parameters that will get passed to the
- * constructor method.
- * @param mixed You can (optionally) load the instance to a custom
- * object.
- * @return object
- */
-
-
- public function load($module, $params = array(), $object_name = false)
- {
- extract($this->get_module_info($module));
-
- if($this->does_api_exist($module))
- {
- $EE =& get_instance();
-
- $EE->load->add_package_path($package);
-
- $obj = new $module_api($params);
-
- if($object_name === FALSE)
- $EE->channel_data->$module = $obj;
- else
- $EE->channel_data->$object_name->$module = $obj;
-
- return $obj;
- }
-
- show_error('An unknown error has occurred while loading the API.');
- }
-
- /**
- * Usage
- *
- * Call the Usage method on a given module
- *
- * @access public
- * @param string Name of the module being loaded
- * @param array An array of parameters that will get passed to the
- * constructor method.
- * @return void
- */
-
-
- public function usage($module, $params = array())
- {
- extract($this->get_module_info($module));
-
- if($this->does_api_exist($module))
- {
- $EE =& get_instance();
-
- $EE->load->add_package_path($package);
-
- $obj = new $module_api($params);
-
- return $obj->usage();
- }
- }
-}
diff --git a/Channel_data/drivers/Channel_data_tmpl.php b/Channel_data/drivers/Channel_data_tmpl.php
deleted file mode 100644
index 14ab8b1..0000000
--- a/Channel_data/drivers/Channel_data_tmpl.php
+++ /dev/null
@@ -1,561 +0,0 @@
-EE->TMPL))
- {
- $this->init();
- }
- }
-
- public function init($tagdata = FALSE)
- {
- $orig_settings = FALSE;
-
- if(isset($this->EE->api_channel_fields->settings))
- {
- $orig_settings = $this->EE->api_channel_fields->settings;
- }
-
- $this->EE->load->library('typography');
- $this->EE->load->library('api');
- $this->EE->api->instantiate('channel_fields');
-
- $fields = $this->EE->api_channel_fields->fetch_custom_channel_fields();
-
- if($orig_settings)
- {
- $this->EE->api_channel_fields->settings = $orig_settings;
- }
-
- $parse_object = (object) array();
- }
-
- public function create_alias($tagdata = NULL)
- {
- $this->init();
-
- $obj = new EE_Template();
-
- if(isset($this->EE->TMPL))
- {
- $TMPL = $this->EE->TMPL;
- }
- else
- {
- $TMPL = $obj;
- }
-
- $this->EE->TMPL = $obj;
-
- $this->EE->TMPL->template = $tagdata ? $tagdata : $TMPL->tagdata;
-
- return $TMPL;
- }
-
- public function reset($TMPL)
- {
- $this->EE->TMPL = $TMPL;
- }
-
- public function parse_switch($tagdata, $count = 1)
- {
- // Match {switch="foo|bar"} variables
- $switch = array();
-
- if (preg_match_all("/".LD."(switch\s*=.+?)".RD."/i", $tagdata, $matches, PREG_SET_ORDER))
- {
- foreach ($matches as $match)
- {
- $sparam = $this->EE->functions->assign_parameters($match[1]);
-
- if (isset($sparam['switch']))
- {
- $sopt = explode("|", $sparam['switch']);
-
- $switch[$match[1]] = $sopt;
- }
- }
- }
-
- $row = array();
-
- // Set {switch} variable values
- foreach ($switch as $key => $val)
- {
- $row[$key] = $switch[$key][($count + count($val) -1) % count($val)];
- }
-
- return $this->EE->TMPL->parse_variables_row($tagdata, $row, FALSE);
- }
-
- public function parse_array($parse_array = array(), $parse_vars = array(), $entry_data = array(), $channels = FALSE, $channel_fields = array(), $prefix = '')
- {
- if(!$channel_fields)
- {
- $channel_fields = $this->get_channel_fields()->result_array();
- $channel_fields = $this->EE->channel_data->utility->reindex($channel_fields, 'field_name');
- }
-
- if(!$channels)
- {
- $channels = $this->get_channels()->result_array();
- $channels = $this->EE->channel_data->utility->reindex($channels, 'channel_id');
- }
-
- if(is_object($parse_array))
- {
- $parse_array = (array) $parse_array;
- }
-
- foreach($parse_array as $index => $value)
- {
- if(!empty($value) && is_string($value))
- {
- $parse_array[$index] = $this->parse($parse_vars, $entry_data, $channels, $channel_fields, $value, $prefix, $index);
-
- }
- }
-
- return $parse_array;
- }
-
- public function parse($parse_vars = array(), $entry_data = array(), $channels = FALSE, $channel_fields = FALSE, $tagdata = FALSE, $prefix = '', $index = FALSE)
- {
-
- if(!$tagdata)
- {
- $tagdata = $this->EE->TMPL->template;
- }
-
- if(!$channels)
- {
- $channels = $this->get_channels()->result_array();
- $channels = $this->EE->channel_data->utility->reindex($channels, 'channel_id');
- }
-
- if(!$channel_fields)
- {
- $channel_fields = $this->get_channel_fields()->result_array();
- $channel_fields = $this->EE->channel_data->utility->reindex($channel_fields, 'field_name');
- }
-
- if(is_object($parse_vars))
- {
- $parse_vars = (array) $parse_vars;
- }
-
- if(!isset($parse_vars[0]))
- {
- $parse_vars = array($parse_vars);
- }
-
- $TMPL = $this->EE->channel_data->tmpl->create_alias($tagdata);
-
- $this->EE->TMPL->template = $this->EE->functions->prep_conditionals($this->EE->TMPL->template, array_merge($parse_vars, (array) $entry_data));
-
- $this->EE->TMPL->template = $this->EE->TMPL->parse_variables($this->EE->TMPL->template, $parse_vars);
-
- $this->EE->TMPL->template = $this->parse_fieldtypes($entry_data, $channels, $channel_fields, $this->EE->TMPL->template, $prefix, $index);
-
- $this->EE->TMPL->parse($this->EE->TMPL->template);
-
- $this->EE->TMPL->template = $this->EE->TMPL->parse_globals($this->EE->TMPL->template);
-
- $return = $this->EE->TMPL->template;
-
- $this->EE->channel_data->tmpl->reset($TMPL);
-
- return $return;
- }
-
- public function parse_string($string, $parse_vars = array(), $entry_data = array(), $channels = array(), $channel_fields = array())
- {
- return $this->parse($parse_vars, $entry_data, $channels, $channel_fields, $string);
- }
-
- public function parse_fieldtypes($entry_data = array(), $channels = array(), $channel_fields = array(), $tagdata = FALSE, $prefix = '', $index = FALSE)
- {
- $parse_data = $entry_data;
-
- if(!$tagdata)
- {
- $tagdata = $this->EE->TMPL->template;
- }
-
- $vars = $this->EE->functions->assign_variables($tagdata);
-
- $tagdata = $this->parse_single_vars($vars, $entry_data, $channels, $channel_fields, $tagdata, $prefix, $index);
-
- $tagdata = $this->parse_var_pairs($vars, $entry_data, $channels, $channel_fields, $tagdata, $prefix, $index);
-
- return $tagdata;
- }
-
- public function parse_path_variables($vars = array(), $entry_data = array(), $tagdata = FALSE, $prefix = '')
- {
- foreach($vars as $key => $value)
- {
- // parse URL title path
- if(strncmp($key, $prefix.'url_title_path', 14) == 0)
- {
- $path = ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX') ? $this->EE->functions->extract_path($key).'/'.$entry_data->{$prefix.'url_title'} : $entry_data->{$prefix.'url_title'};
-
- $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->functions->create_url($path, FALSE), $tagdata);
- }
-
- // parse title permalink
- if (strncmp($key, $prefix.'title_permalink', 15) == 0)
- {
- $path = ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX') ? $this->EE->functions->extract_path($key).'/'.$entry_data->{$prefix.'url_title'} : $entry_data->{$prefix.'url_title'};
-
- $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->functions->create_url($path, FALSE), $tagdata);
- }
-
- // parse permalink
- if (strncmp($key, $prefix.'permalink', 9) == 0)
- {
- $path = ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX') ? $this->EE->functions->extract_path($key).'/'.$entry_data->{$prefix.'entry_id'} : $entry_data->{$prefix.'entry_id'};
-
- $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->functions->create_url($path, FALSE), $tagdata);
-
- }
-
- }
-
- /*
- if (count($channel_fields) > 0)
- {
- foreach($entry_data as $key => $value)
- {
- // parse URL title path
- if (strncmp($prefix.$key, $prefix.'url_title_path', 14) == 0)
- {
- var_dump($key);exit();
-
- $path = ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX') ? $this->EE->functions->extract_path($key).'/'.$row['url_title'] : $row['url_title'];
-
- $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->functions->create_url($path), $tagdata);
- }
- }
- }
- */
- return $tagdata;
- }
-
- public function parse_custom_date_fields($entry_data = array(), $channels = array(), $channel_fields = array(), $tagdata = FALSE, $prefix = '')
- {
- $custom_date_fields = array();
-
- if (count($channel_fields) > 0)
- {
- foreach($channel_fields as $key => $value)
- {
- if (strpos($tagdata, LD.$prefix.$key) === FALSE) continue;
-
- if (preg_match_all("/".LD.$prefix.$key."\s+format=[\"'](.*?)[\"']".RD."/s", $tagdata, $matches))
- {
-
- for ($j = 0; $j < count($matches[0]); $j++)
- {
- $matches[0][$j] = str_replace(array(LD,RD), '', $matches[0][$j]);
-
- $dkey = $matches[0][$j];
- $val = $matches[1][$j];
- $custom_date_fields[$matches[0][$j]] = $this->EE->localize->fetch_date_params($matches[1][$j]);
- }
-
-
- if(isset($entry_data->{$prefix.$key}))
- {
- $temp_val = $entry_data->{$prefix.$key};
- $field_id = $value->field_id;
-
- $localize = TRUE;
-
- if (isset($entry_data->{$prefix.'field_dt_'.$field_id}) AND !empty($entry_data->{$prefix.'field_dt_'.$field_id}))
- {
- $temp_val = $this->EE->localize->simpl_offset($temp_val, $entry_data->{$prefix.'field_dt_'.$field_id});
- $localize = FALSE;
- }
-
- $val = str_replace($custom_date_fields[$dkey], $this->EE->localize->convert_timestamp($custom_date_fields[$dkey], $temp_val, $localize), $val);
-
- $tagdata = $this->EE->TMPL->swap_var_single($dkey, $val, $tagdata);
- }
- }
- }
- }
-
- return $tagdata;
- }
-
- public function parse_single_vars($vars, $entry_data = array(), $channels = array(), $channel_fields = array(), $tagdata = FALSE, $prefix = '', $index = FALSE)
- {
- $entry_data = (object) $entry_data;
- $prefix_entry = (object) $this->EE->channel_data->utility->add_prefix($prefix, $entry_data, '');
-
- if(!$tagdata)
- {
- $tagdata = $this->EE->TMPL->template;
- }
-
- $tagdata = $this->parse_path_variables($vars['var_single'], $entry_data, $tagdata, $prefix);
-
- foreach($vars['var_single'] as $single_var => $single_var_value)
- {
- $tagdata = $this->parse_custom_date_fields($entry_data, $channels, $channel_fields, $tagdata, $prefix);
-
- $params = $this->EE->functions->assign_parameters($single_var);
-
- $single_var_array = explode(' ', $single_var);
-
- $field_name = preg_replace('/^'.$prefix.'|:.*/us', '', $single_var_array[0]);
-
- $call_method = preg_replace("/(^((?!:).)*$)|(^.*:)/us", "", preg_replace('/^'.$prefix.'/us', '', $single_var_array[0]));
-
- $call_method = 'replace_'.(!empty($call_method) ? $call_method : 'tag');
-
- $entry = FALSE;
-
- if(isset($channel_fields[$field_name]))
- {
- if(is_array($channel_fields[$field_name]))
- {
- $channel_fields[$field_name] = (object) $channel_fields[$field_name];
- }
-
- $field_type = $channel_fields[$field_name]->field_type;
- $field_id = $channel_fields[$field_name]->field_id;
-
- if(isset($entry_data->{$single_var_array[0]}))
- {
- $field_name = $single_var_array[0];
- }
-
- if(isset($entry_data->$field_name) || isset($entry_data->{'field_id_'.$field_id}))
- {
- $data = isset($entry_data->$field_name) ? $entry_data->$field_name : $entry_data->{'field_id_'.$field_id};
-
- if($this->EE->api_channel_fields->setup_handler($field_id))
- {
- $channel = isset($entry_data->{$prefix.'channel_id'}) ? $channels[$entry_data->{$prefix.'channel_id'}] : $channels[$entry_data->channel_id];
-
- $row = array_merge((array) $channel, (array) $entry_data);
-
- foreach($channel_fields as $channel_field)
- {
- $channel_field = (array) $channel_field;
-
- if(isset($row[$prefix.$channel_field['field_name']]) ||
- isset($row[$channel_field['field_name']]))
- {
- $row['field_id_'.$channel_field['field_id']] = $data;
- $row['field_ft_'.$channel_field['field_id']] = $channel_field['field_fmt'];
- unset($row[$channel_field['field_name']]);
- }
-
- }
-
- $this->EE->api_channel_fields->apply('_init', array(array('row' => $row)));
- // Preprocess
- $data = $this->EE->api_channel_fields->apply('pre_process', array($row['field_id_'.$field_id]));
-
- $entry = $this->EE->api_channel_fields->apply($call_method, array($data, $params, FALSE));
-
- $tagdata = $this->EE->TMPL->swap_var_single($single_var, $entry, $tagdata);
-
- $tagdata = $this->EE->TMPL->parse_variables_row($tagdata, array($prefix.$field_name => $data));
-
- }
- }
- }
- else
- {
- $var_name = preg_replace('/\s.*$/', '', $single_var);
-
- if(isset($prefix_entry->$var_name))
- {
- $tagdata = $this->EE->TMPL->parse_variables_row($tagdata, array(
- $var_name => $prefix_entry->$var_name
- ));
- }
- }
- }
-
- return $tagdata;
- }
-
- public function parse_var_pairs($vars, $entry_data = array(), $channels = array(), $channel_fields = array(), $tagdata = FALSE, $prefixes = '', $index = FALSE)
- {
- $entry_data = (array) $entry_data;
-
- if(!$tagdata)
- {
- $tagdata = $this->EE->TMPL->template;
- }
-
- if(!is_array($prefixes))
- {
- $prefixes = array($prefixes);
- }
-
- $pair_vars = array();
-
- foreach($vars['var_pair'] as $pair_var => $params)
- {
- if(preg_match("/exp(:\w*)*/", $pair_var))
- {
- continue;
- }
-
- foreach($prefixes as $prefix)
- {
-
- $pair_var_array = explode(' ', $pair_var);
-
- $field_name = preg_replace('/^'.$prefix.'|:.*/us', '', $pair_var_array[0]);
- $call_method = preg_replace("/(^((?!:).)*$)|(^.*:)/us", "", preg_replace('/^'.$prefix.'/us', '', $pair_var_array[0]));
- $call_method = 'replace_'.(!empty($call_method) ? $call_method : 'tag');
-
-
- $offset = 0;
-
- while (($end = strpos($tagdata, LD.'/'.$prefix.$field_name.RD, $offset)) !== FALSE)
- {
- if (preg_match("/\\".LD."{$prefix}{$field_name}(.*?)".RD."(.*?)".LD.'\/'.$prefix.$field_name.RD."/s", $tagdata, $matches, 0, $offset))
- {
- $chunk = $matches[0];
- $params = $matches[1];
- $inner = $matches[2];
-
- // We might've sandwiched a single tag - no good, check again (:sigh:)
- if ((strpos($chunk, LD.$prefix.$field_name, 1) !== FALSE) && preg_match_all("/\\".LD."{$prefix}{$field_name}(.*?)".RD."/s", $chunk, $match))
- {
- // Let's start at the end
- $idx = count($match[0]) - 1;
- $tag = $match[0][$idx];
-
- // Reassign the parameter
- $params = $match[1][$idx];
-
- // Cut the chunk at the last opening tag (PHP5 could do this with strrpos :-( )
- while (strpos($chunk, $tag, 1) !== FALSE)
- {
- $chunk = substr($chunk, 1);
- $chunk = strstr($chunk, LD.$prefix.$field_name);
- $inner = substr($chunk, strlen($tag), -strlen(LD.'/'.$prefix.$field_name.RD));
- }
- }
-
- $pair_vars[$field_name] = array($inner, $this->EE->functions->assign_parameters($params), $chunk);
- }
-
- $offset = $end + 1;
- }
- }
-
- foreach($pair_vars as $field_name => $pair_var)
- {
- if(!isset($channel_fields[$field_name]))
- {
- continue;
- }
- else
- {
- $channel_fields[$field_name] = (object) $channel_fields[$field_name];
- }
-
- $field_id = isset($channel_fields[$field_name]->field_id) ? $channel_fields[$field_name]->field_id : 0;
-
- if((isset($channel_fields[$field_name]) || isset($channel_fields['field_id_'.$field_id])) && (isset($channel_fields[$field_name]->field_type) || isset($channel_fields['field_id_'.$field_id]->field_type)))
- {
- $field_name = isset($channel_fields[$field_name]) ? $field_name : 'field_id_'.$field_id;
-
- $entry_data = (array) $entry_data;
- $field_type = $channel_fields[$field_name]->field_type;
- $field_id = $channel_fields[$field_name]->field_id;
-
- $data = isset($entry_data[$field_name]) ? $entry_data[$field_name] : NULL;
-
- if($this->EE->api_channel_fields->setup_handler($field_id))
- {
- $row = $entry_data;
-
- foreach($entry_data as $index => $value)
- {
- if(isset($channel_fields[$index]) && is_object($channel_fields[$index]) && isset($channel_fields[$index]->field_id) && !isset($row['field_id_'.$channel_fields[$index]->field_id]))
- {
- $row['field_id_'.$channel_fields[$index]->field_id] = $value;
- $row['field_ft_'.$channel_fields[$index]->field_id] = $channel_fields[$index]->field_fmt;
- }
- else
- {
- $row[$index] = $value;
- }
- }
-
- $this->EE->api_channel_fields->apply('_init', array(array('row' => $row)));
- $entry = $this->EE->api_channel_fields->apply($call_method, array($data, $pair_var[1], $pair_var[0]));
-
- $test = $entry_data;
- $tagdata = $this->parse_string(str_replace($pair_var[2], $entry, $tagdata), $entry_data, $channels, $channel_fields);
-
-
- }
- }
- }
-
- $entry = FALSE;
- }
-
- return $tagdata;
- }
-
- /* @deprecated */
- public function parse_entry($entry_data, $channels = array(), $channel_fields = array(), $tagdata = FALSE, $count = 1)
- {
- $TMPL = $this->EE->channel_data->tmpl->create_alias($tagdata);
-
- if(is_string($entry_data) || is_int($entry_data))
- {
- $entry_data = $this->get_channel_entry($entry_data)->row();
- }
-
- if(is_array($entry_data))
- {
- $entry_data = (object) $entry_data;
- }
-
- $this->EE->TMPL->template = $this->EE->TMPL->parse_variables_row($this->EE->TMPL->template, (array) $entry_data);
-
- $this->EE->TMPL->parse($this->EE->TMPL->template);
-
- $this->EE->TMPL->template = $this->parse_fieldtypes($channels, $channel_fields);
-
- $return = $this->EE->channel_data->tmpl->parse_switch($this->EE->TMPL->template, $count);
-
- $this->EE->channel_data->tmpl->reset($TMPL);
-
- return $return;
- }
-}
\ No newline at end of file
diff --git a/Channel_data/drivers/Channel_data_utility.php b/Channel_data/drivers/Channel_data_utility.php
deleted file mode 100644
index 461d9f0..0000000
--- a/Channel_data/drivers/Channel_data_utility.php
+++ /dev/null
@@ -1,250 +0,0 @@
- $data_value)
- {
- if(is_array($data_value) && preg_match('/\d/', $data_index))
- {
- if(isset($data_value[0]) && !is_array($data_value[0]))
- {
- $new_row = array();
-
- foreach($data_value as $inner_index => $inner_value)
- {
- $new_row[$prefix . $delimeter . $inner_index] = $inner_value;
- }
-
- $new_data[$data_index] = $new_row;
- }
- else
- {
- $new_data[$data_index] = $this->add_prefix($prefix, $data_value, $delimeter);
- }
-
- }
- else
- {
- $new_data[$prefix . $delimeter . $data_index] = $data_value;
- }
- }
- }
- else
- {
- $new_data = $data;
- }
-
- return $new_data;
- }
-
- /**
- * Merge an array to any nested array. Useful for merging data into arrays
- * before they are used to parse the templates.
- *
- * @access public
- * @param array The array to merge
- * @param array The subject and data to be returned
- * @param string The starting point
- * @param string The ending point
- * @return array
- */
- public function merge_array($array, $subject, $start = 0, $stop = FALSE)
- {
- if($stop === FALSE)
- {
- $stop = count($subject);
- }
-
- for($y=$start; $y < $stop; $y++)
- {
- if(isset($subject[$y]))
- {
- $subject[$y] = array_merge($subject[$y], $array);
- }
- else
- {
- $subject[$y] = $array;
- }
- }
-
- return $subject;
- }
-
- /**
- * Prepare an entry to be added/edited using the channel entries API
- *
- * @access public
- * @param mixed The channel id
- * @param array The entry data
- * @param prefix Delete a consistent prefix from entry data
- * @param string The ending point
- * @return array
- */
- public function prepare_entry($channel_id, $data, $prefix = '')
- {
- $this->EE->api->instantiate('channel_fields');
- $this->EE->api_channel_fields->fetch_custom_channel_fields();
-
- $fields = $this->EE->channel_data->get_channel_fields($channel_id);
-
- if(is_object($data))
- {
- $data = (array) $data;
- }
-
- $required_fields = array(
- 'entry_date' => $this->EE->localize->now,
- 'url_title' => url_title($data[$prefix.'title']),
- 'expiration_date' => NULL,
- 'author_id' => $this->EE->session->userdata['member_id'],
- 'status' => 'open',
- 'sticky' => 'n',
- 'allow_comments' => 'n',
- 'recent_comment_date' => 0
- );
-
- foreach($required_fields as $key => $value)
- {
- if(!isset($data[$prefix.$key]))
- {
- $data[$prefix.$key] = $value;
- }
- }
-
- $post = array_merge($data, array(
- 'title' => $data[$prefix.'title'],
- 'url_title' => $data[$prefix.'url_title'],
- 'entry_date' => $data[$prefix.'entry_date'],
- 'expiration_date' => $data[$prefix.'expiration_date'],
- 'author_id' => $data[$prefix.'author_id'],
- 'status' => $data[$prefix.'status']
- ));
-
- foreach($fields->result() as $field)
- {
- $post_value = $this->EE->input->post($field->field_name);
-
- $post['field_id_'.$field->field_id] = $post_value ? $post_value : (isset($data->{$field->field_name}) ? $data->{$field->field_name} : NULL);
- $post['field_ft_'.$field->field_id] = $field->field_fmt;
- }
-
- return $post;
- }
-
- public function reindex($data, $index)
- {
- if(is_string($data))
- {
- $old_index = $index;
- $index = $data;
- $data = $old_index;
- }
-
- $array = array();
-
- foreach($data as $key => $value)
- {
- if(is_array($value))
- {
- $array[$value[$index]] = $value;
- }
-
- if(is_object($value))
- {
- $array[$value->$index] = $value;
- }
- }
-
- return $array;
- }
-
- /**
- * Submits an entry using the channel entries API
- *
- * @access public
- * @param mixed The channel id
- * @param array The entry data
- * @return int
- */
- public function submit_entry($channel_id, $data)
- {
- $this->EE->load->library('api');
- $this->EE->api->instantiate('channel_entries');
- $this->EE->api->instantiate('channel_fields');
-
- $this->EE->session->userdata['group_id'] = 1;
-
- $this->EE->api_channel_fields->setup_entry_settings($channel_id, $data);
-
- $this->EE->api_channel_entries->submit_new_entry($channel_id, $data);
-
- if(count($this->EE->api_channel_entries->errors) > 0)
- {
- return $this->EE->api_channel_entries->errors;
- }
-
- return $this->EE->api_channel_entries->entry_id;
- }
-
- /**
- * Updates an entry using the channel entries API
- *
- * @access public
- * @param mixed The channel id
- * @param mixed The entry id
- * @param array The entry data
- * @return int
- */
- public function update_entry($channel_id, $entry_id, $data)
- {
- $this->EE->load->library('api');
- $this->EE->api->instantiate('channel_entries');
-
- $data['entry_id'] = $entry_id;
- $data['channel_id'] = $channel_id;
-
- $this->EE->session->userdata['group_id'] = 1;
-
- $this->EE->api_channel_entries->update_entry($entry_id, $data);
-
- if(count($this->EE->api_channel_entries->errors) > 0)
- {
- return $this->EE->api_channel_entries->errors;
- }
-
- return TRUE;
- }
-
-}
\ No newline at end of file
diff --git a/README.markdown b/README.markdown
deleted file mode 100644
index e45790d..0000000
--- a/README.markdown
+++ /dev/null
@@ -1,185 +0,0 @@
-Channel Data
-============
-
-### Version 0.8.8 - 20121021
-
-#### By Justin Kimbrell / Objective HTML
-
-Overview
---------
-
-Channel Data is designed to give you access to a concise and memorable syntax. The current API's to retrieve channel data seem cumbersome and often require many lines of code just to get your entry data along with the custom fields. Native API's also have parameters that aren't consistent, resulting in code that is repeatedly looked up for what should be basic tasks. Simply put, Channel Data just works and speeds add-on development up tremendously.
-
-Channel Data also provided a simple and effective interface for developers to interact with other add-ons using a standards based approach. By using the Channel Data API to create an API for your add-on, you can easily allow other developers to programmatically interact with your add-ons in ways that weren't possible before.
-
-Table of Contents
------------------
-
- 1. [Basic Usage]( #basicusage "Go to Basic Usage")
- 2. [Polymorphic Parameters]( #polymorphicparameters "Go to 'Polymorphic Parameters' section")
- 3. [Channel Data Library]( #channeldatalibrary "Go to the 'Channel Data Library' section")
- 4. [What's to come?](#whatstocome "Go to the 'What's to come' section")
- 5. [Contributors](#contributors "Go to the 'Contributors' section")
- 6. [Disclaimer](#disclaimer "Go to the Disclaimer section")
-
-Basic Usage
------------
-
-Channel Data is a modified CodeIgniter driver and has two parts to the architecture, the library, and the add-on API framework. The library potion attempts provides all the methods one would need to easily retrieve data from your channels using a familiar polymorphic syntax. Native libraries are inconstant in nomenclature, are undocumented, and usually don't even do what you need without loading 4 or 5 models and writing 20 or 30 lines of code. It gets tedious and time consuming after a while, and the code looks like a mess. The Channel Library provides a clean and flexible API that is capable of performing complex queries, and is very easy to remember. The nomenclature is logical and makes send. For example, get_channel_entries($channel_id, …) actually gets the channel entries AND joins the custom fields in one nice easy to remember method.
-
-The add-on API framework allows you load third-party add-on API's. It can also help you create an API for your add-ons that other developers can use. The add-on API framework extends the Channel Data Library, so you inherently get access to all the library functions within you API. Since Channel Data is a modified CodeIgniter driver, to get access to third-party API's you must load them as such. API's are files inside the parent add-on directory with the naming scheme: __api.your_module_name.php__. Once the driver is loaded, it becomes a child to the Channel Data object.
-
-#### Example A - Using the Channel Data Library
-
- $this->EE->load->driver('channel_data');
-
- $channels = $this->EE->channel_data->get_channels();
- $entries = $this->EE->channel_data->get_entries();
- $fields = $this->EE->channel_data->get_fields();
-
-#### Example B - Loading Channel Data drivers
-
- $this->EE->load->channel_data->api->load('gmap');
-
- $location = $this->EE->channel_data->gmap->geocode('MT Elbert');
-
-#### Example C - Sample Gmap API
-
- EE->load->library('Google_maps');
-
- return $this->EE->google_maps->geocode($query, $limit, $offset);
- }
-
- }
-
- // End of File
- // ./system/expressionengine/third_party/gmap/api.gmap.php
- ?>
-
-_By extending the Base_API class, you inherent the Channel Data object. Now, find cool way to extend add-ons in a easier and much more powerful way._
-
-[Back to Top](#channeldata "Go to the top of the page")
-
-Polymorphic Parameters
-----------------------
-
-Almost all of the methods have polymorphic parameters. Helper methods are used to quickly retrieve a single entry _do not_ use polymorphic parameters. However, helper methods than quickly grab data in relation to a channel_id generally do accept polymorphic parameters.
-
-Unless the method only returns a single row, the select parameter is always used for polymorphic values. In these polymorphic parameters, you can either fields to select, or you can define an active record array. It's really just a preference, there are reasons to use both, but really it just makes for a really versatile and functional API and more memorable. Complex queries are generally a lot easier to comprehend when using polymorphic parameters.
-
-#### Example A
-
- $channel_id = 1;
- $select = array('*');
- $where = array('channel_data.entry_id >' => 5); //Note, on shared columns you must specify a table name
- $order_by = 'title';
- $sort = 'ASC';
- $limit = 1;
- $offset = 5;
-
- $entries = $this->EE->channel_data->get_channel_entries($channel_id, $select, $where, $order_by, $sort, $limit, $offset);
-
-_This example uses the standard parameters are select, where, order_by, sort, limit, and offset. When present, all these parameters are always in this order. Unless a method is designed to pull a single entry, it will almost always contain these parameters._
-
-#### Example B
-
- $entries = $this->EE->channel_data->get_channel_entries($channel_id, array(
- 'select' => array('*'),
- 'where' => array('channel_data.entry_id >' => 5),
- 'order_by' => 'title',
- 'sort' => 'ASC',
- 'limit' => 1,
- 'offset' => 5
- ));
-
- $entries = $this->EE->channel_data->get_channel_entries($channel_id, array(
- 'select' => array('*'),
- 'where' => array(
- 'channel_data.entry_id >' => 5,
- 'channel_data.channel_id !=' => 4,
- 'or channel_data.entry_id' => 1
- '{2} or channel_data.entry_id' => 2
- '{3} or channel_data.entry_id' => 3,
- 'channel_data.entry_id' => array(
- '1',
- 'OR 2',
- 'OR 3'
- )
- ),
- 'order_by' => 'title',
- 'sort' => 'ASC',
- 'limit' => 1,
- 'offset' => 5
- ));
-
-_Or... You can use the alternative syntax. This array is referred to an active record array. Notice you can use OR and AND prefixes and logical operators as the suffix. If not logical operator exists, then '=' is assumed._
-
-#### Examples C
-
- object(CI_DB_mysql_result)#45 (7) {
- ["conn_id"]=>
- resource(36) of type (mysql link)
- ["result_id"]=>
- resource(150) of type (mysql result)
- ["result_array"]=>
- array(0) {
- }
- ["result_object"]=>
- array(0) {
- }
- ["current_row"]=>
- int(0)
- ["num_rows"]=>
- int(1)
- ["row_data"]=>
- NULL
- }
-
-_The returned object would look something like this, also known as an active record object…_
-
-[Back to Top](#channeldata "Go to the top of the page")
-
-Channel Data Library
---------------------
-
-I am currently working to fully documenting the source code and properly generate a dynamic documentation form the comments within the code. Until then, refer to __Channel_data_lib.php__ source code file to reference methods. I realize this is pretty terrible, but this stuff comes in phases, and this is a free library built in conjunction with the projects I build for paying clients… I will get the new docs created as soon as I learn the overly complicated systems that exist to create real documentation without re-typing everything 3 times.
-
-[Back to Top](#channeldata "Go to the top of the page")
-
-
-What's to come?
----------------
-
-As the project start to mature, the main goal is get to people to start adopting this library and using to it to create rich third-party API's for their add-ons. API's are awesome and allow us all to make better products. If we can all make an effort to create add-ons with API's I bet we start to see even more cool things built.
-
-[Back to Top](#channeldata "Go to the top of the page")
-
-
-Contributors
-------------
-
-Using feedback from others is a critical part of success. Become a contributor by simply helping me improve the library by giving me some feedback on how to improve it, or even forking the library and changing it yourself.
-
- - [@wesrice](#https://www.twitter.com/wesrice "Go to @wesrice's Twitter page") - Thanks for the inspiration and ideas to include an add-on API
-
-[Back to Top](#channeldata "Go to the top of the page")
-
-
-Disclaimer
-----------
-
-This is library still very beta. If you have any complaints, dislikes, improvements, suggestions, or anything else, please feel free to fork the code or contact me directly. I want this to be a rock solid library, but it first needs to be scrutinized by the community. Contact me on Twitter @objectivehtml.
-
-License
--------
-Channel Data is licensed using the BSD 2-Clause License. In a nutshell, do whatever you want with it so long as you leave the copyright information and don't take credit for my work. The idea is for everyone to benefit from the library. For a full copy of the license, refer to license.txt in the download package.
-
-[Back to Top](#channeldata "Go to the top of the page")
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..02ac364
--- /dev/null
+++ b/README.md
@@ -0,0 +1,688 @@
+# Channel Data
+
+##### Version 1.0-rc2 (2013-12-16)
+
+Created By [Objective HTML](https://objectivehtml.com)
+
+---
+
+## Table of Contents
+
+1. [Overview](#overview)
+2. [System Requirements](#system-requirements)
+3. [Getting Started](#getting-started)
+4. [QueryBuilder](#querybuilder)
+4. [QueryResponse](#queryresponse)
+5. [QueryString](#querystring)
+5. [Collections](#collections)
+6. [Models](#models)
+6. [Channel Models](#channel-models)
+
+---
+
+## Overview
+
+Channel Data was created to provide a universal and abstract set of models for you to use within your [ExpressionEngine](http://ellislab.com/expressionengine) applications and addons. Channel Data is now based on the Eloquent ORM, so the syntax should be familiar to those that have used it.
+
+Why didn't we just port Eloquent to ExpressionEngine? Others have done so, and it's definitely possible. However, after a lot of consideration, it was decided to rewrite the code from scratch specifically for ExpressionEngine. This will make it easier to integrate Channel Data into existing applications and maintain the codebase as ExpressionEngine evolves.
+
+---
+
+## System Requirements
+
+PHP 5.3+
+
+ExpressionEngine 2.4+
+
+*(Earlier versions of ExpressionEngine may work, but are untested)*
+
+---
+
+## Getting Started
+
+To get started using Channel Data, you need to copy `channel_data` into your `system/expressionengine/third_party` directory. Channel Data is packages as its own *module* so you an reuse the same libary with all of your add-ons. This is also convenient when you upgrade ExpressionEngine since you don't have to worry about override files stored in the system directories.
+
+Channel Data includes some core modules for you to use. Core models belong to the `ChannelData\Model` namespace, and can be reused within your application. You can create your own models using the following structure:
+
+
+##### Instantiate Channel Data
+
+The key thing to note when instantiating Channel Data is that you need to do 3 things.
+
+ /**
+ * Required Steps
+ *
+ * 1. Load the Channel Data package into your add-on
+ * 2. Load the Channel Data driver from the package
+ * 3. Tell Channel Data where the auto loader should look for your files.
+ **/
+
+ ee()->load->add_package_path(PATH_THIRD . 'your_addon_name');
+
+ // Load the driver and directories at once
+ ee()->load->driver('ChannelData', array(
+ 'directories' => array(
+ PATH_THIRD . 'your_addon_name/models'
+ )
+ ));
+
+ // Or use the autoload() method to pass a directory path
+ ee()->channeldata->autoload(PATH_THIRD . 'your_addon_name/models');
+
+ // You can also pass an array of directories
+ ee()->channeldata->autoload(array(
+ PATH_THIRD . 'your_addon_name/models',
+ PATH_THIRD . 'your_addon_name/models/channels'
+ ));
+
+
+*Note, Channel Data is a CodeIgniter driver, not a library. You must load it using the `driver` method.*
+
+----
+
+## QueryBuilder
+
+QueryBuilder is a standalone class that provides a clean syntax for building SQL statements based on the Eloquent ORM. QueryBuilder can be used as a standalone class, or within the [Models](#models) themselves.
+
+### Instantiate
+
+ $builder = new QueryBuilder();
+
+### Response
+
+After you are finished building your query, you need to instantiate a `QueryResponse` object by running the `get()` method.
+
+ $response = $builder->get();
+
+Or you can skip the response and just grab the results. If a model has been defined, a `Collection` will be returned. Otherwise, an array of standard objects will be returned.
+
+ $response = $builder->result();
+
+### Select
+
+ // Select all
+ $builder->select('*');
+
+ // Select columns from a specific table
+ $builder->select('members.member_id');
+
+ // Select multiple columns with an array
+ $builder->select(array('username', 'email', 'screen_name'));
+
+ // Select columns with an alias
+ $builder->select('members.email', 'email_address');
+
+ // Select columns with a closure
+ $builder->select(function($table) {
+ $table->select('email');
+ $table->select('username');
+ });
+
+ // Select data using a raw query string
+ $builder->select(QueryString::raw('`username` as \'user\''));
+
+### From
+
+ // Specify a table name
+ $builder->from('members');
+
+ // Specify data using a raw query string
+ $builder->select(QueryString::raw('`exp_members` as \'member\''));
+
+### Where
+
+ // A basic conditional with operator
+ $builder->where('username', '=', 'Justin');
+
+ // A basic conditional with out operator
+ $builder->where('username', 'Justin');
+
+ // Add an "OR" conditional
+ $builder->orWhere('username', 'Justin');
+
+ // Add an "and" conditional (this is an alias to where())
+ $builder->andWhere('username', 'Justin');
+
+ // Perform a "WHERE IN" conditional against an array
+ $builder->whereIn('member_is', array(1, 2, 3));
+ $builder->andWhereIn('member_is', array(1, 2, 3));
+ $builder->orWhereIn('member_is', array(1, 2, 3));
+
+ // Perform nested conditionals with a closure
+ $builder->where(function($table) {
+ $table->where('screen_name', 'Justin Kimbrell');
+ $table->orWhere('screen_name', 'Objective HTML');
+ });
+
+### Having
+
+ // A basic conditional with operator
+ $builder->having('username', '=', 'Justin');
+
+ // A basic conditional with out operator
+ $builder->having('username', 'Justin');
+
+ // Add an "OR" conditional
+ $builder->orHaving('username', 'Justin');
+
+ // Add an "and" conditional (this is an alias to where())
+ $builder->andHaving('username', 'Justin');
+
+ // Perform a "WHERE IN" conditional against an array
+ $builder->havingIn('member_is', array(1, 2, 3));
+ $builder->andHavingIn('member_is', array(1, 2, 3));
+ $builder->orHavingIn('member_is', array(1, 2, 3));
+
+ // Perform nested conditionals with a closure
+ $builder->having(function($table) {
+ $table->having('screen_name', 'Justin Kimbrell');
+ $table->orHaving('screen_name', 'Objective HTML');
+ });
+
+### Join
+
+ // Basic
+ $builder->join('table2', 'table1.id', '=', 'table2.id');
+
+ // Left
+ $builder->leftJoin('table2', 'table1.id', '=', 'table2.id');
+
+ // Right
+ $builder->rightJoin('table2', 'table1.id', '=', 'table2.id');
+
+ // Outer
+ $builder->outerJoin('table2', 'table1.id', '=', 'table2.id');
+
+ // Inner
+ $builder->innerJoin('table2', 'table1.id', '=', 'table2.id');
+
+ // Raw String
+ $builder->join(QueryString::raw('table2 ON table1.id = table2.id'));
+
+### Order By
+
+ // Basic
+ $builder->orderBy('id', 'asc')
+
+ // Raw String
+ $builder->orderBy(QueryString::raw('id ASC'));
+
+### Sort
+
+ $builder->sort('ASC');
+
+### Limit
+
+ // Limit with offset at 0
+ $builder->limit(10);
+
+ // Limit with offset at 10
+ $builder->limit(10, 10);
+
+### Offset
+
+ $builder->offset(5);
+
+----
+
+## QueryResponse
+
+`QueryResponse` is a class that is instantiated when the `get` method is ran on the `QueryResponse` object.
+
+### count()
+
+Returns the total number of items in the response
+
+ $response = $builder->get();
+ $response->count();
+
+### each()
+
+This method loops through the entire collection and passes each item to a closure.
+
+ $response = $builder->get();
+
+ $response->each(function($i, $row) {
+ $row->some_field = 'Some new value';
+ });
+
+### first()
+
+This method returns the first row in the result array
+
+ $response = $builder->get();
+
+ $row = $response->first();
+
+### last()
+
+This method returns the last row in the result array
+
+ $response = $builder->get();
+
+ $row = $response->last();
+
+### index()
+
+This method returns a row in the result by index, or if no index is exists, NULL will be returned.
+
+ $response = $builder->get();
+
+ $row = $response->index(2);
+
+### next()
+
+This method returns the next row in the result set.
+
+ $response = $builder->get();
+
+ $row = $response->next();
+
+### prev()
+
+This method returns the previous row in the result set.
+
+ $response = $builder->get();
+
+ $row = $response->next();
+
+### result()
+
+This method returns the result array
+
+ $response = $builder->get();
+
+ $row = $response->result();
+
+### row()
+
+This method returns the first row in the result array
+
+ $response = $builder->get();
+
+ $row = $response->row();
+
+
+----
+
+## QueryString
+
+`QueryString` is a class that can be passed into any parameter that will output a raw string. `QueryString` also has a number of static helper methods to manipulate strings for common uses within SQL.
+
+### Instantiate
+
+ $rawString = new QueryString('This is a raw string');
+
+ var_dump((string) $rawString);
+
+### QueryString::protect($str, $table = FALSE)
+
+This method will attempt to protect strings from SQL syntax and formatting errors. It will encapsulate table and field names with backticks.
+
+ // Returns `field`
+ QueryString::protect('field');
+
+ // Returns `exp_table`.`field`
+ QueryString::protect('field', 'table');
+
+ // Returns `exp_table`.`field`
+ QueryString::protect('table.field');
+
+### QueryString::raw($str)
+
+This method will instantiate a QueryString object.
+
+ // Returns QueryString object
+ QueryString::raw('This is a test');
+
+
+### QueryString::table($str)
+
+This method will convert a string into a properly prefixed table name.
+
+ // Returns 'exp_table_name'
+ QueryString::table('table_name');
+
+
+### QueryString::strip($str)
+
+This method will strip unnecessary formatting from strings. It's important to note, this will also strip numeric prefixes that can be used in indexes within arrays (to make them unique).
+
+ // Returns 'table_name'
+ QueryString::strip('`table_name`');
+
+ // Returns 'table_name'
+ QueryString::strip('{1} `table_name`');
+
+ // Returns 'table_name'
+ QueryString::strip('{2} `table_name`');
+
+
+### QueryString::clean($str)
+
+This method will trim and clean excess conditional keywords from strings
+
+ // Returns 'field1 OR field2'
+ QueryString::clean(' AND field1 OR field2 ');
+
+---
+
+## Collections
+
+When a model processes QueryBuilder objects, it will take those results and instantiate the respected objects and pass an array of items to the `Collection` class.
+
+### each($closure)
+
+This method loops through the entire collection and passes each item to a closure.
+
+ $members = Member::all();
+
+ $members->each(function($i, Member $member) {
+ $member->some_field = 'Some new value';
+ $member->save();
+ });
+
+### items()
+
+This method returns an array of instantiated model objects.
+
+ $members = Member::all();
+
+ foreach($members->$items() as $i => $member)
+ {
+ $member->some_field = 'Some new value';
+ $member->save();
+ }
+
+### first()
+
+This method returns the first model in the collection.
+
+ $members = Member::all();
+
+ $member = $members->first()
+
+### last()
+
+This method returns the last model in the collection.
+
+ $members = Member::all();
+
+ $member = $members->last()
+
+### get($index = FALSE, $default = NULL)
+
+This method returns an item in the collection by index, or if no index is exists, all items will be returned.
+
+ $member = Member::all()->get(2);
+ $member = Member::all()->get(12, 'some default value');
+
+### count()
+
+Returns the total number of items in the collection
+
+ $count = Member::all()->count();
+
+----
+
+## Models
+
+Models are really the key component behind Channel Data. Each model is assigned to a database table and comes complete with a full CRUD controller. Models can be instantiated and be accessed statically. All models should extend the `BaseModel` class, and are located in the `models` directory within `ChannelData`, within the `models` directory inside your add-on, or in the global `models` directory.
+
+ where(...);
+
+### MyModel::all()
+
+Return all the results in the model
+
+ $members = Member::all();
+
+### MyModel::find($id)
+
+Find a model by ID
+
+ $members = Member::find(1);
+
+### MyModel::findByUid($id)
+
+Find a model by UID. The `uidField` inmust be defined in your model class to use this method.
+
+ $members = Member::findByUid('ak20f-2dajd-2adawwad-zjadafj3');
+
+### MyModel::query()
+
+Instantiate a `QueryBuilder` object.
+
+ $query = Member::query()->where(...);
+
+### MyModel::table()
+
+Return the table that is being searched
+
+ $table = Member::table();
+
+##### Instance Methods
+
+### id()
+
+Returns the id of the model
+
+ $memberId = $member->id();
+
+### uid()
+
+Returns the uid of the model. This field required the `uidField` property to be set in the model.
+
+ $memberId = $member->id();
+
+### getAttributes()
+
+Returns all the attributes for the model.
+
+ $attributes = $member->getAttributes();
+
+### getAttribute($name)
+
+Returns a single the attributes for the model.
+
+ $attribute = $member->getAttribute('username');
+
+### setAttributes($data)
+
+Sets an array of attributes. Ignores the security filters.
+
+ $member->setAttributes(array(
+ 'username' => 'Justin Kimbre',
+ 'company' => 'Objective HTML'
+ ));
+
+### setAttribute($prop, $value)
+
+Sets an single attribute. Ignores the security filters.
+
+ $member->setAttributes('company', 'Objective HTML');
+
+### fill($data = array())
+
+Fill the model with an array data. Respects the security filters.
+
+ $member->fill(array)
+
+### save($data = array())
+
+Save the model data. If an array is passed, the model data is passed to the `fill` method.
+
+ $member->save();
+
+### update($data = array())
+
+Update the model data. If an array is passed, the model data is passed to the `fill` method.
+
+ $member->update();
+
+### delete()
+
+Delete the model.
+
+ $member->delete();
+
+### toArray()
+
+Output the model as an associative array
+
+ $member->toArray();
+
+### toJson()
+
+Output the model as a JSON string
+
+ $member->toJson();
+
+----
+
+## Channel Models
+
+Channel Models extend the `BaseModel` class and are specifically built to work with Channel Entries.
+
+ field_name
+
+ 5 => 'your_field_name'
+ );
+
+
+##### Instance Methods
+
+#### getErrors()
+
+Get the array of errors in the `$errors` property (which is protected).
+
+
+##### Static Methods
+
+#### MyModel::findByUrlTitle()
+
+Get the entry by the `url_title`.
+
+
+#### MyModel::channelId()
+
+Get the `channel_id` of the model.
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/base/BaseModel.php b/channel_data/libraries/Channeldata/base/BaseModel.php
new file mode 100644
index 0000000..a9d959c
--- /dev/null
+++ b/channel_data/libraries/Channeldata/base/BaseModel.php
@@ -0,0 +1,465 @@
+columns() as $column)
+ {
+ if(!property_exists($this, $column))
+ {
+ $this->$column = NULL;
+ }
+ }
+
+ $this->fill($data);
+
+ if($setId && isset($data->{$this->idField}))
+ {
+ if($this->idField)
+ {
+ $this->setAttribute($this->idField, $data->{$this->idField});
+ }
+
+
+ if($this->uidField && isset($data->{$this->uidField}))
+ {
+ $this->setAttribute($this->uidField, $data->{$this->uidField});
+ }
+ }
+
+ if($this->getAttribute($this->idField))
+ {
+ $this->exists = TRUE;
+ }
+ else
+ {
+ $this->setAttribute($this->uidField, md5(uniqid()));
+ }
+ }
+
+ public function __call($method, $args)
+ {
+ $prefix = $this->prefix ? $this->prefix : NULL;
+
+ if(isset($this->{$prefix.$method}))
+ {
+ return $this->{$prefix.$method};
+ }
+
+ throw new \Exception('"'.$method.'" is not a valid method', 1);
+
+ return NULL;
+ }
+
+ public function __get($property)
+ {
+ if (property_exists($this, $property))
+ {
+ return $this->$property;
+ }
+ else
+ {
+ $class = self::caller();
+
+ throw new \Exception("The {$property} property does not exist within the {$class} class.");
+ }
+ }
+
+ public function fill($data)
+ {
+ if(is_object($data))
+ {
+ $data = (array) $data;
+ }
+
+ if(is_array($data) && count($data) > 0)
+ {
+ foreach($data as $index => $value)
+ {
+ if($this->prefix && property_exists($this, $this->prefix.$index))
+ {
+ $index = $this->prefix.$index;
+ }
+
+ if( in_array($index, $this->fillable) ||
+ in_array($index, $this->required))
+ {
+ $this->setAttribute($index, $value);
+ }
+ }
+ }
+ }
+
+ public function save($data = FALSE)
+ {
+ if($data)
+ {
+ $this->fill($data);
+ }
+
+ if(!$this->exists)
+ {
+ return $this->_createRecord($data);
+ }
+ else
+ {
+ return $this->_updateRecord($data);
+ }
+ }
+
+ public function toArray()
+ {
+ $array = array();
+
+ foreach($this->columns() as $index)
+ {
+ if(!in_array($index, $this->hidden))
+ {
+ $array[$index] = $this->getAttribute($index);
+ }
+ }
+
+ return $array;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this->toArray());
+ }
+
+ public function update($array = FALSE)
+ {
+ if($array)
+ {
+ $this->fill($array);
+ }
+
+ return $this->save();
+ }
+
+ public function delete()
+ {
+ if($this->exists)
+ {
+ ee()->db->where($this->idField, $this->id());
+ ee()->db->delete($this->table);
+
+ $this->exists = FALSE;
+ $this->deleted = TRUE;
+ }
+
+ return $this;
+ }
+
+ public function getAttributes()
+ {
+ $return = array();
+
+ foreach($this as $prop => $index)
+ {
+ if(property_exists($this, $prop))
+ {
+ $return[$prop] = $this->getAttribute($prop);
+ }
+ }
+
+ return $return;
+ }
+
+ public function getAttribute($name)
+ {
+ if(property_exists($this, $name))
+ {
+ return $this->$name;
+ }
+
+ return NULL;
+ }
+
+ public function setAttributes($data)
+ {
+ foreach($data as $index => $value)
+ {
+ $this->setAttribute($index, $value);
+ }
+ }
+
+ public function setAttribute($prop, $value)
+ {
+ if(!empty($prop))
+ {
+ $this->$prop = $value;
+ }
+ }
+
+ protected function _createRecord($data = array())
+ {
+ if(count($data))
+ {
+ $this->fill($data);
+ }
+
+ $data = $this->data();
+
+ if($this->uidField)
+ {
+ $data[$this->uidField] = md5(uniqid());
+ }
+
+ ee()->db->insert($this->table, $data);
+
+ $this->exists = TRUE;
+ $this->setAttribute($this->idField, ee()->db->insert_id());
+
+ return $this;
+ }
+
+ protected function _updateRecord($data = array())
+ {
+ if(count($data))
+ {
+ $this->fill($data);
+ }
+
+ ee()->db->where($this->idField, $this->id());
+ ee()->db->update($this->table, $this->data());
+
+ return $this;
+ }
+
+ public function id()
+ {
+ if($id = $this->{$this->idField})
+ {
+ return $id;
+ }
+
+ return NULL;
+ }
+
+ public function uid()
+ {
+ if(property_exists($this, 'uidField'))
+ {
+ $uid = $this->{$this->uidField};
+
+ if($uid !== NULL)
+ {
+ return $uid;
+ }
+ }
+
+ return NULL;
+ }
+
+ public function data()
+ {
+ $data = array();
+
+ foreach($this->columns() as $field)
+ {
+ $value = $this->getAttribute($field);
+
+ if($value !== NULL && !in_array($field, $this->guarded))
+ {
+ $data[$field] = $value;
+ }
+ }
+
+ return $data;
+ }
+
+ public function columns()
+ {
+ if($this->columns)
+ {
+ return $this->columns;
+ }
+
+ return $this->columns = ee()->db->list_fields($this->table);
+ }
+
+ public static function create($array)
+ {
+ $class = get_called_class();
+ $obj = new $class($array);
+
+ $obj->save();
+
+ return $obj;
+ }
+
+ public static function find($id)
+ {
+ $class = self::caller();
+ $obj = self::instantiate();
+
+ return $class::where($obj->table.'.'.$obj->idField, $id)->get()->first();
+ }
+
+ public static function findByUid($uid)
+ {
+ $class = self::caller();
+ $obj = self::instantiate();
+
+ return $class::where($obj->uidField, $uid)->get()->first();
+ }
+
+ public static function all()
+ {
+ $class = self::caller();
+
+ return $class::query()->result();
+ }
+
+ public static function select()
+ {
+ $class = self::caller();
+
+ return $class::call($class::query(), 'select', func_get_args());
+ }
+
+ public static function where($subject, $operator = NULL, $value = NULL, $concat = 'AND')
+ {
+ $class = self::caller();
+
+ return $class::query()->where($subject, $operator, $value, $concat);
+ }
+
+ public static function whereIn($subject, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::query()->whereIn($subject, $value);
+ }
+
+ public static function orWhereIn($subject, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::query()->orWhereIn($subject, $value);
+ }
+
+ public static function andWhereIn($subject, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::query()->andWhereIn($subject, $value);
+ }
+
+ public static function orWhere($subject, $operator = NULL, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::where($subject, $operator, $value, 'OR');
+ }
+
+ public static function andWhere($subject, $operator = NULL, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::where($subject, $operator, $value, 'AND');
+ }
+
+ public static function having($subject, $operator = NULL, $value = NULL, $concat = 'AND')
+ {
+ $class = self::caller();
+
+ return $class::query()->having($subject, $operator, $value, $concat);
+ }
+
+ public static function orHaving($subject, $operator = NULL, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::having($subject, $operator, $value, 'OR');
+ }
+
+ public static function andHaving($subject, $operator = NULL, $value = NULL)
+ {
+ $class = self::caller();
+
+ return $class::having($subject, $operator, $value, 'AND');
+ }
+
+ public static function call($obj, $method, $args = array())
+ {
+ return call_user_func_array(array($obj, $method), $args);
+ }
+
+ public static function query()
+ {
+ $class = self::instantiate();
+
+ $query = new QueryBuilder();
+ $query->model = get_class($class);
+
+ $query->from($class::table());
+ $query->select('*');
+
+ return $query;
+ }
+
+ public static function init($result)
+ {
+ $class = self::caller();
+
+ if($result->num_rows() == 0)
+ {
+ return NULL;
+ }
+
+ $return = new $class();
+ $return->exists = TRUE;
+ $return->setAttributes($result->row());
+
+ return $return;
+ }
+
+ public static function table()
+ {
+ $class = self::caller();
+
+ return $class::instantiate()->table;
+ }
+
+ public static function caller()
+ {
+ return get_called_class();
+ }
+
+ public static function instantiate()
+ {
+ $class = self::caller();
+
+ return new $class();
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/base/ChannelModel.php b/channel_data/libraries/Channeldata/base/ChannelModel.php
new file mode 100644
index 0000000..491133d
--- /dev/null
+++ b/channel_data/libraries/Channeldata/base/ChannelModel.php
@@ -0,0 +1,314 @@
+lang->loadfile('content');
+
+ $this->uidField = $this->prefix.'uid';
+ $this->required[] = $this->prefix.'uid';
+
+ $this->fillable = array_merge($this->fillable, $this->fields());
+
+ parent::__construct($data);
+ }
+
+ public function __get($property)
+ {
+ if(property_exists($this, $this->prefix.$property))
+ {
+ return $this->{$this->prefix.$property};
+ }
+
+ throw new \Exception("Invalid property \'".$property."\'", 1);
+ }
+
+ public function __set($property, $value)
+ {
+ if(property_exists($this, $this->prefix.$property))
+ {
+ $property = $this->prefix.$property;
+ }
+
+ $this->$property = $value;
+
+ if($property == 'title')
+ {
+ $this->url_title = QueryString::url_title(strtolower($this->title));
+ }
+ }
+
+ public function getErrors()
+ {
+ return $this->errors;
+ }
+
+ public function hasErrors()
+ {
+ return count($this->errors) ? TRUE : FALSE;
+ }
+
+ public function channel()
+ {
+ if(!$this->channel)
+ {
+ return FALSE;
+ }
+
+ $channel = Channel::findByName($this->channel);
+
+ if(!$channel)
+ {
+ show_error('The '.$this->channel.' id set in the config is incorrect');
+ }
+
+ return $channel;
+ }
+
+ public function delete()
+ {
+ if($this->exists)
+ {
+ ee()->load->library('api');
+ ee()->api->instantiate('channel_entries');
+ ee()->api_channel_entries->delete_entry(array($this->entry_id));
+
+ $this->deleted = TRUE;
+ $this->exists = FALSE;
+ }
+
+ return $this;
+ }
+
+ protected function _createRecord($data = array())
+ {
+ if(count($data))
+ {
+ $this->fill($data);
+ }
+
+ $this->apiResponse = ChannelEntriesApi::submit_entry($this->channel()->channel_id, $this->data());
+ $this->setAttribute($this->idField, $this->apiResponse);
+
+ if(!is_int($this->apiResponse))
+ {
+ $this->errors = $this->apiResponse;
+ }
+ else
+ {
+ $this->exists = TRUE;
+ }
+
+ return $this;
+ }
+
+ protected function _updateRecord($data)
+ {
+ if(count($data))
+ {
+ $this->fill($data);
+ }
+
+ $this->apiResponse = ChannelEntriesApi::update_entry($this->channel_id, $this->entry_id, $this->data());
+
+ if(!is_int($this->apiResponse))
+ {
+ $this->errors = $this->apiResponse;
+ }
+
+ return $this;
+ }
+
+ public function data()
+ {
+ $channel = Channel::findByName($this->channel);
+
+ $data = parent::data();
+
+ foreach($channel->fields()->items() as $row)
+ {
+ if(isset($data[$row->field_name]) && $value = $data[$row->field_name])
+ {
+ unset($data[$row->field_name]);
+ }
+ else
+ {
+ $value = NULL;
+ }
+
+ $data['field_id_'.$row->field_id] = $value;
+ $data['field_ft_'.$row->field_id] = $row->field_fmt;
+ }
+
+ return $data;
+ }
+
+ public function columns()
+ {
+ return array_merge(
+ ee()->db->list_fields('channel_titles'),
+ $this->fields()
+ );
+ }
+
+ public function fields()
+ {
+ if($this->fields)
+ {
+ return $this->fields;
+ }
+
+ if($channel = $this->channel())
+ {
+ foreach($channel->fields()->items() as $field)
+ {
+ $this->fields[$field->field_id] = $field->field_name;
+ }
+ }
+ else
+ {
+ foreach(ChannelField::all()->items() as $field)
+ {
+ $this->fields[$field->field_id] = $field->field_name;
+ }
+ }
+
+ return $this->fields;
+ }
+
+ public static function findOpen($entry_id)
+ {
+ return self::where('channel_data.entry_id', '=', $entry_id)
+ ->where('status', '=', 'open')
+ ->get()
+ ->first();
+ }
+
+ public static function findByAuthorId($author_id)
+ {
+ return self::where('author_id', '=', $author_id)->get();
+ }
+
+ public static function findByUrlTitle($urlTitle)
+ {
+ if($urlTitle === FALSE)
+ {
+ return NULL;
+ }
+
+ return self::where('url_title', '=', $urlTitle)->get()->first();
+ }
+
+ public static function channelId()
+ {
+ $class = new static;
+
+ if(!$class->channel)
+ {
+ return FALSE;
+ }
+
+ return Channel::findByName($class->channel)->id();
+ }
+
+ public static function table()
+ {
+ return 'channel_titles';
+ }
+
+ public static function query()
+ {
+ $class = new static;
+
+ $query = new ChannelQueryBuilder();
+ $query->model = get_class($class);
+
+ $query->from('channel_titles');
+ $query->leftJoin('channel_data', 'channel_titles.entry_id', '=', 'channel_data.entry_id');
+ $query->select('*', NULL, 'channel_titles');
+
+ foreach($class->fields() as $field_id => $field_name)
+ {
+ $query->select('field_id_'.$field_id, $field_name, 'channel_data');
+ }
+
+ if($class->channelId())
+ {
+ $query->where('channel_data.channel_id', '=', $class->channelId());
+ }
+
+ return $query;
+ }
+
+ public function entries()
+ {
+ $parser = new ChannelEntriesParser();
+
+ return $parser->entries(array(
+ 'entry_id' => $this->id()
+ ));
+ }
+}
diff --git a/channel_data/libraries/Channeldata/channeldata.php b/channel_data/libraries/Channeldata/channeldata.php
new file mode 100644
index 0000000..2426ca3
--- /dev/null
+++ b/channel_data/libraries/Channeldata/channeldata.php
@@ -0,0 +1,148 @@
+channeldata))
+ {
+ foreach(ee()->channeldata->directories() as $directory)
+ {
+ $filePath = $directory . '/' . $fileName;
+
+ if(file_exists($filePath))
+ {
+ require_once($filePath);
+ }
+ }
+ }
+ }
+
+}
+
+if(!function_exists('is_closure'))
+{
+ function is_closure($t)
+ {
+ return is_object($t) && ($t instanceof Closure);
+ }
+}
+
+/**
+ * ChannelData CodeIgniter Driver
+ *
+ * Dummy class to trigger autoloading, and give access to helper methods
+ *
+ * @return void
+ */
+
+
+use ChannelData\Model\Channel;
+use ChannelData\Model\ChannelField;
+
+class ChannelData {
+
+ protected $directories = array();
+
+ public function __construct($data = array())
+ {
+ foreach($data as $index => $value)
+ {
+ $this->$index = $value;
+ }
+ }
+
+ public function autoload($file)
+ {
+ if(!is_array($file))
+ {
+ $file = array($file);
+ }
+
+ $this->directories[] = $file;
+ }
+
+ public function directories()
+ {
+ if(!is_array($this->directories))
+ {
+ $this->directories = array($this->directories);
+ }
+
+ return $this->directories;
+ }
+
+ public static function prefix($prefix, $data, $delimeter = ':')
+ {
+ $new_data = array();
+
+ if(!empty($prefix))
+ {
+ foreach($data as $data_index => $data_value)
+ {
+ if(is_array($data_value) && preg_match('/\d/', $data_index))
+ {
+ if(isset($data_value[0]) && !is_array($data_value[0]))
+ {
+ $new_row = array();
+
+ foreach($data_value as $inner_index => $inner_value)
+ {
+ $new_row[$prefix . $delimeter . $inner_index] = $inner_value;
+ }
+
+ $new_data[$data_index] = $new_row;
+ }
+ else
+ {
+ $new_data[$data_index] = self::prefix($prefix, $data_value, $delimeter);
+ }
+
+ }
+ else
+ {
+ $new_data[$prefix . $delimeter . $data_index] = $data_value;
+ }
+ }
+ }
+ else
+ {
+ $new_data = $data;
+ }
+
+ return $new_data;
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/ChannelCollection.php b/channel_data/libraries/Channeldata/components/ChannelCollection.php
new file mode 100644
index 0000000..cdbbd59
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/ChannelCollection.php
@@ -0,0 +1,10 @@
+response->entries();
+ }
+
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/ChannelEntriesApi.php b/channel_data/libraries/Channeldata/components/ChannelEntriesApi.php
new file mode 100644
index 0000000..1389bc0
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/ChannelEntriesApi.php
@@ -0,0 +1,64 @@
+load->library('api');
+ ee()->api->instantiate('channel_entries');
+ ee()->api->instantiate('channel_fields');
+
+ ee()->session->userdata['group_id'] = 1;
+
+ ee()->api_channel_fields->setup_entry_settings($channel_id, $data);
+
+ ee()->api_channel_entries->submit_new_entry($channel_id, $data);
+
+ if(count(ee()->api_channel_entries->errors) > 0)
+ {
+ return ee()->api_channel_entries->errors;
+ }
+
+ return ee()->api_channel_entries->entry_id;
+ }
+
+ /**
+ * Updates an entry using the channel entries API
+ *
+ * @access public
+ * @param mixed The channel id
+ * @param mixed The entry id
+ * @param array The entry data
+ * @return int
+ */
+ public static function update_entry($channel_id, $entry_id, $data)
+ {
+ ee()->load->library('api');
+ ee()->api->instantiate('channel_entries');
+ ee()->api->instantiate('channel_fields');
+
+ $data['entry_id'] = $entry_id;
+ $data['channel_id'] = $channel_id;
+
+ ee()->session->userdata['group_id'] = 1;
+
+ ee()->api_channel_fields->setup_entry_settings($channel_id, $data);
+
+ ee()->api_channel_entries->update_entry($entry_id, $data);
+
+ if(count(ee()->api_channel_entries->errors) > 0)
+ {
+ return ee()->api_channel_entries->errors;
+ }
+
+ return TRUE;
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/ChannelEntriesParser.php b/channel_data/libraries/Channeldata/components/ChannelEntriesParser.php
new file mode 100644
index 0000000..eff6f9f
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/ChannelEntriesParser.php
@@ -0,0 +1,271 @@
+TMPL->no_results = $tagdata;
+ }
+
+ public function cache_no_results()
+ {
+ ee()->session->set_cache('entries_lib', 'no_results', ee()->TMPL->no_results);
+ }
+
+ public function reset_no_results($cache = TRUE)
+ {
+ if($cache)
+ {
+ $this->cache_no_results();
+ }
+
+ ee()->TMPL->no_results = NULL;
+ }
+
+ public function restore_no_results()
+ {
+ if(isset(ee()->session->cache['entries_lib']['no_results']))
+ {
+ $this->reset_no_results(FALSE);
+ $this->set_no_results(ee()->session->cache['entries_lib']['no_results']);
+ }
+
+ ee()->session->set_cache('entries_lib', 'no_results', array());
+
+ return $this->get_params();
+ }
+
+ public function no_results()
+ {
+ return $this->get_no_results();
+ }
+
+ public function get_no_results()
+ {
+ return ee()->TMPL->no_results;
+ }
+
+ public function set_param($param, $value = FALSE)
+ {
+ $this->set_params(array(
+ $param => $value
+ ));
+ }
+
+ public function set_params($params = array())
+ {
+ if(is_array($params))
+ {
+ foreach($params as $param => $value)
+ {
+ if($value !== FALSE)
+ {
+ ee()->TMPL->tagparams[$param] = $value;
+ }
+ else
+ {
+ unset(ee()->TMPL->tagparams[$param]);
+ }
+ }
+ }
+ else
+ {
+ ee()->TMPL->tagparams = FALSE;
+ }
+ }
+
+ public function get_params()
+ {
+ return ee()->TMPL->tagparams;
+ }
+
+ public function get_param($param)
+ {
+ return ee()->TMPL->fetch_param($param);
+ }
+
+ public function cache_params()
+ {
+ ee()->session->set_cache('entries_lib', 'params', $this->get_params());
+ }
+
+ public function reset_params($cache = TRUE)
+ {
+ if($cache)
+ {
+ $this->cache_params();
+ }
+
+ ee()->TMPL->tagparams = array();
+ }
+
+ public function restore_params()
+ {
+ if(isset(ee()->session->cache['entries_lib']['params']))
+ {
+ $this->reset_params(FALSE);
+ $this->set_params(ee()->session->cache['entries_lib']['params'], TRUE);
+ }
+
+ ee()->session->set_cache('entries_lib', 'params', array());
+
+ return $this->get_params();
+ }
+
+ public function cache_tagdata()
+ {
+ ee()->session->set_cache('entries_lib', 'tagdata', $this->get_tagdata());
+ }
+
+ public function reset_tagdata()
+ {
+ $this->cache_tagdata();
+
+ ee()->TMPL->tagdata = FALSE;
+ }
+
+ public function restore_tagdata()
+ {
+ if(isset(ee()->session->cache['entries_lib']['tagdata']))
+ {
+ $this->set_tagdata(ee()->session->cache['entries_lib']['tagdata']);
+ }
+
+ ee()->session->set_cache('entries_lib', 'tagdata', FALSE);
+
+ return $this->get_tagdata();
+ }
+
+ public function get_tagdata()
+ {
+ return ee()->TMPL->tagdata;
+ }
+
+ public function set_tagdata($tagdata)
+ {
+ ee()->TMPL->tagdata = $tagdata;
+ }
+
+ public function channel($params = array())
+ {
+ require_once APPPATH.'modules/channel/mod.channel.php';
+
+ unset(ee()->channel);
+
+ $channel = new \Channel();
+
+ $this->set_params($params);
+
+ $this->channel = $channel;
+
+ return $channel;
+ }
+
+ public function entries($params = array(), $channel = FALSE)
+ {
+ $default_params = array(
+ 'dynamic' => 'no',
+ 'disable' => 'member_data|categories|category_fields|pagination'
+ );
+
+ if($enable = $this->get_param('enable'))
+ {
+ $enable = explode('|', $enable);
+
+
+ $default_params['disable'] = str_replace($enable, '', $default_params['disable']);
+ }
+
+ foreach($default_params as $param => $value)
+ {
+ $user_param = $this->get_param($param);
+
+ if($user_param)
+ {
+ $params[$param] = $user_param;
+ }
+ else
+ {
+ $params[$param] = $value;
+ }
+ }
+
+ $tagdata = $this->get_tagdata();
+
+ $this->set_params($params);
+
+ if($channel)
+ {
+ $this->channel = $channel;
+ }
+ else
+ {
+ $this->channel();
+ }
+
+ if($prefix = $this->get_param('prefix'))
+ {
+ $this->set_tagdata(preg_replace('/(('.LD.'|\/)|(|if)\s)'.$prefix.'\d*/', '$1', $this->get_tagdata()));
+
+ foreach(ee()->TMPL->var_single as $index => $value)
+ {
+ unset(ee()->TMPL->var_single[$index]);
+ ee()->TMPL->var_single[str_replace($prefix, '', $index)] = str_replace($prefix, '', $value);
+ }
+
+ foreach(ee()->TMPL->var_pair as $index => $value)
+ {
+ unset(ee()->TMPL->var_pair[$index]);
+
+ ee()->TMPL->var_pair[str_replace($prefix, '', $index)] = $value !== FALSE ? str_replace($prefix, '', $value) : FALSE;
+ }
+
+ $tagdata = ee()->TMPL->tagdata;
+
+ foreach(ee()->TMPL->tag_data as $index => $tag_data)
+ {
+ $block = $tag_data['block'];
+ //ee()->TMPL->tag_data[$index]['chunk'] = str_replace($block, $tagdata, $tag_data['chunk']);
+ //ee()->TMPL->tag_data[$index]['block'] = $tagdata;
+ }
+
+ if(preg_match('/\\'.LD.'if no_results\\'.RD.'.*?\\'.LD.'\\/if\\'.RD.'/us', $this->get_tagdata(), $matches))
+ {
+ ee()->TMPL->no_results = ee()->TMPL->parse_variables_row($matches[0], array(
+ 'no_results' => 1
+ ));
+ }
+ }
+
+ $entries = trim($this->channel->entries());
+
+ $this->set_tagdata($tagdata);
+
+ return $entries;
+ }
+
+ public static function noResults()
+ {
+ $obj = new static;
+
+ $prefix = '';
+
+ if($obj->get_param('prefix'))
+ {
+ $prefix = $obj->get_param('prefix');
+
+ $obj->set_tagdata(preg_replace('/(('.LD.'|\/)|(|if)\s)'.$prefix.'\d*/', '$1', $obj->get_tagdata()));
+ }
+
+ if(preg_match('/\\'.LD.'if no_results\\'.RD.'.*?\\'.LD.'\\/if\\'.RD.'/us', $obj->get_tagdata(), $matches))
+ {
+ ee()->TMPL->no_results = ee()->TMPL->parse_variables_row($matches[0], array(
+ 'no_results' => 1
+ ));
+ }
+
+ return ee()->TMPL->no_results();
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/ChannelQueryBuilder.php b/channel_data/libraries/Channeldata/components/ChannelQueryBuilder.php
new file mode 100644
index 0000000..c14b95b
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/ChannelQueryBuilder.php
@@ -0,0 +1,64 @@
+where('entry_date', '>', $date);
+ }
+
+ public function past($date = FALSE)
+ {
+ if(!$date)
+ {
+ $date = time();
+ }
+
+ return $this->where('entry_date', '<', $date);
+ }
+
+ public function expired($date = FALSE)
+ {
+ if(!$date)
+ {
+ $date = time();
+ }
+
+ return $this->where('expired_entries', '<=', $date);
+ }
+
+ public function open()
+ {
+ return $this->where('status', 'open');
+ }
+
+ public function closed()
+ {
+ return $this->where('status', 'closed');
+ }
+
+ public function notClosed()
+ {
+ return $this->where('status', '!=', 'closed');
+ }
+
+ public function notOpen()
+ {
+ return $this->where('status', '!=', 'open');
+ }
+
+ public function get()
+ {
+ return new ChannelResponse($this, $this->model);
+ }
+
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/Collection.php b/channel_data/libraries/Channeldata/components/Collection.php
new file mode 100644
index 0000000..23e3a89
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/Collection.php
@@ -0,0 +1,106 @@
+response = $response;
+ $this->model = $model;
+
+ foreach($data as $index => $row)
+ {
+ $this->items[] = new $this->model($row);
+ }
+ }
+
+ public function ids()
+ {
+ $ids = array();
+
+ foreach($this->items as $item)
+ {
+ $ids[] = $item->id();
+ }
+
+ return $ids;
+ }
+
+ public function reindex($index)
+ {
+ $return = array();
+
+ foreach($this->items() as $item)
+ {
+ $return[$item->$index] = $item->toArray();
+ }
+
+ return $return;
+ }
+
+ public function each($closure)
+ {
+ if(is_closure($closure))
+ {
+ foreach($this->items() as $index => $item)
+ {
+ $closure($index, $item);
+ }
+ }
+ else
+ {
+ throw new Exception('Closure is expected, '.ucfirst(gettype($closure)).' given.', 1);
+
+ }
+ }
+ public function items()
+ {
+ return $this->items;
+ }
+
+ public function first()
+ {
+ return $this->get(0);
+ }
+
+ public function last()
+ {
+ return $this->get($this->count() - 1);
+ }
+
+ public function all()
+ {
+ return $this->items();
+ }
+
+ public function get($index = FALSE, $default = NULL)
+ {
+ return $index !== FALSE && isset($this->items[$index]) ? $this->items[$index] : NULL;
+ }
+
+ public function count()
+ {
+ return count($this->items);
+ }
+
+ public function toArray()
+ {
+ $response = array();
+
+ foreach($this->items as $item)
+ {
+ $response[] = $item->toArray();
+ }
+
+ return $response;
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/QueryBuilder.php b/channel_data/libraries/Channeldata/components/QueryBuilder.php
new file mode 100644
index 0000000..c4a110c
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/QueryBuilder.php
@@ -0,0 +1,434 @@
+$prop))
+ {
+ return $this->$prop;
+ }
+ }
+
+ if(preg_match('/^set/', $method))
+ {
+ $prop = strtolower(preg_replace('/^set/', '', $method));
+
+ if(isset($this->$prop))
+ {
+ return $this->$prop = $args[0];
+ }
+ }
+
+ throw new \Exception("{$method} is not a valid method");
+ }
+
+ public function groupBy($field)
+ {
+ $this->groupBy[] = QueryString::table($field);
+
+ return $this;
+ }
+
+ public function from($table)
+ {
+ if(!is_object($table))
+ {
+ $table = QueryString::table($table);
+ }
+
+ $this->from[] = (string) $table;
+ }
+
+ public function join($table, $subject = NULL, $operator = NULL, $value = NULL, $type = 'JOIN')
+ {
+ if(is_closure($table))
+ {
+ $this->join[] = $this->_closure('join', $table, ' ', FALSE);
+ }
+ else if(is_object($table) && $subject === NULL && $operator === NULL)
+ {
+ $this->join[] = $type.' '.(string) $table;
+ }
+ else
+ {
+ $this->join[] = $type.' '.
+ QueryString::table($table).' ON '.
+ QueryString::table($subject).' '.
+ QueryString::operator($operator).' '.
+ QueryString::table($value);
+ }
+
+ return $this;
+ }
+
+ public function leftJoin($table, $subject = NULL, $operator = NULL, $value = NULL)
+ {
+ return $this->join($table, $subject, $operator, $value, 'LEFT JOIN');
+ }
+
+ public function rightJoin($table, $subject = NULL, $operator = NULL, $value = NULL)
+ {
+ return $this->join($table, $subject, $operator, $value, 'RIGHT JOIN');
+ }
+
+ public function innerJoin($table, $subject = NULL, $operator = NULL, $value = NULL)
+ {
+ return $this->join($table, $subject, $operator, $value, 'INNER JOIN');
+ }
+
+ public function outerJoin($table, $subject = NULL, $operator = NULL, $value = NULL)
+ {
+ return $this->join($table, $subject, $operator, $value, 'OUTER JOIN');
+ }
+
+ public function select($select, $as = NULL, $table = FALSE)
+ {
+ if(is_array($select))
+ {
+ foreach($select as $field)
+ {
+ $this->select($this->protect($field), $as, $table);
+ }
+ }
+ else if(is_closure($select))
+ {
+ $this->select[] = $this->_closure('select', $select, ', ');
+ }
+ else
+ {
+ $select = $this->protect($select);
+
+ if($table)
+ {
+ $select = $this->table($table) . '.' . $select;
+ }
+
+ if($as)
+ {
+ $select .= ' as '.$this->escape($as);
+ }
+
+ $this->select[] = $select;
+ }
+
+ return $this;
+ }
+
+ public function where($subject, $operator = NULL, $value = NULL, $concat = 'AND')
+ {
+ return $this->_conditional('where', $subject, $operator, $value, $concat);
+ }
+
+ public function whereIn($subject, $value = NULL)
+ {
+ return $this->where($subject, QueryString::raw('IN'), $value, 'AND');
+ }
+
+ public function orWhereIn($subject, $value = NULL)
+ {
+ return $this->where($subject, QueryString::raw('IN'), $value, 'OR');
+ }
+
+ public function andWhereIn($subject, $value = NULL)
+ {
+ return $this->where($subject, QueryString::raw('IN'), $value);
+ }
+
+ public function andWhere($subject, $operator = NULL, $value = NULL)
+ {
+ return $this->where($subject, $operator, $value);
+ }
+
+ public function orWhere($subject, $operator = NULL, $value = NULL)
+ {
+ return $this->where($subject, $operator, $value, 'OR');
+ }
+
+ public function having($subject, $operator = NULL, $value = NULL, $concat = 'AND')
+ {
+ return $this->_conditional('having', $subject, $operator, $value, $concat);
+ }
+
+ public function havingIn($subject, $value = NULL)
+ {
+ return $this->having($subject, QueryString::raw('IN'), $value, 'AND');
+ }
+
+ public function orHavingIn($subject, $value = NULL)
+ {
+ return $this->having($subject, QueryString::raw('IN'), $value, 'OR');
+ }
+
+ public function andHavingIn($subject, $value = NULL)
+ {
+ return $this->having($subject, QueryString::raw('IN'), $value);
+ }
+
+ public function andHaving($subject, $operator, $value)
+ {
+ return $this->having($subject, $operator, $value);
+ }
+
+ public function orHaving($subject, $operator, $value)
+ {
+ return $this->having($subject, $operator, $value, 'OR');
+ }
+
+ public function orderBy($field, $sort = FALSE)
+ {
+ $this->orderBy = $this->protect($field);
+
+ if($sort)
+ {
+ $this->sort($sort);
+ }
+
+ return $this;
+ }
+
+ public function sort($sort)
+ {
+ $this->sort = !is_object($sort) ? strtoupper($sort) : (string) $sort;
+
+ return $this;
+ }
+
+ public function limit($limit, $offset = FALSE)
+ {
+ $this->limit = $limit;
+
+ if($offset !== FALSE)
+ {
+ $this->offset = $offset;
+ }
+
+ return $this;
+ }
+
+ public function offset($offset)
+ {
+ $this->offset = !is_object($offset) ? $offset : (string) $sort;
+
+ return $this;
+ }
+
+ public function table($protect)
+ {
+ return QueryString::table($protect);
+ }
+
+ public function protect($protect)
+ {
+ return QueryString::protect($protect);
+ }
+
+ public function operator($operator)
+ {
+ return QueryString::operator($operator);
+ }
+
+ public function escape($value)
+ {
+ return QueryString::escape($value);
+ }
+
+ public function get()
+ {
+ return new QueryResponse($this, $this->model);
+ }
+
+ public function count()
+ {
+ return $this->get()->count();
+ }
+
+ public function result()
+ {
+ return $this->get()->result();
+ }
+
+ public function sql()
+ {
+ $query = array();
+
+ $select = $this->select;
+ $from = NULL;
+ $having = NULL;
+ $where = NULL;
+ $join = NULL;
+ $orderBy = NULL;
+ $groupBy = NULL;
+ $limit = NULL;
+
+ if(empty($this->select))
+ {
+ $select = '*';
+ }
+ else
+ {
+ $select = implode(', ', $this->select);
+ }
+
+ if(count($this->having))
+ {
+ $having = 'HAVING '.QueryString::clean($this->having);
+ }
+
+ if(count($this->where))
+ {
+ $where = 'WHERE '.QueryString::clean($this->where);
+ }
+
+ if(count($this->join))
+ {
+ $join = QueryString::clean($this->join);
+ }
+
+ if($this->orderBy)
+ {
+ $orderBy = trim('ORDER BY '.$this->orderBy.' '.$this->sort);
+ }
+
+ if($this->groupBy)
+ {
+ $groupBy = trim('GROUP BY '.QueryString::clean($this->groupBy));
+ }
+
+ if($this->limit)
+ {
+ $limit = trim('LIMIT '.$this->offset.', '.$this->limit);
+ }
+
+ if($this->from)
+ {
+ $from = 'FROM '.implode(' ', $this->from);
+ }
+
+ $sql = trim('
+ SELECT
+ '.$select.'
+ '.$from.'
+ '.$join.'
+ '.$where.'
+ '.$having.'
+ '.$groupBy.'
+ '.$orderBy.'
+ '.$limit.'
+ ');
+
+ return $sql;
+ }
+
+ public function _conditional($type, $subject, $operator = NULL, $value = NULL, $concat = 'AND')
+ {
+ if(is_closure($subject))
+ {
+ $append = trim($concat) . ' ' . $this->_closure($type, $subject, ' ');
+ }
+ else if(is_array($subject))
+ {
+ $append = NULL;
+
+ if($operator === NULL)
+ {
+ $operator = '=';
+ }
+
+ foreach($subject as $field => $value)
+ {
+ $this->$type($field, $operator, $value, $concat);
+ }
+ }
+ else if(is_object($subject) && $operator === NULL && $value === NULL)
+ {
+ $append = $concat.' ('.(string) $subject.')';
+ }
+ else
+ {
+ if(is_string($value))
+ {
+ if(strtoupper($value) == 'AND' || strtoupper($value) == 'OR')
+ {
+ $concat = $value;
+ $value = NULL;
+ }
+ }
+
+ if(!is_null($operator) && is_null($value))
+ {
+ if($subject != 'entry_date')
+ { }
+
+ $value = $operator;
+ $operator = $this->defaultOperator;
+ }
+
+ if(is_array($value))
+ {
+ foreach($value as $index => $val)
+ {
+ $value[$index] = $this->escape($val);
+ }
+
+ $value = QueryString::raw('('.implode(', ', $value).')');
+ }
+
+ $append = $concat.' ('.
+ $this->protect($subject).' '.
+ $this->operator($operator).' '.
+ $this->escape($value).')';
+ }
+
+ $this->$type = array_merge($this->$type, array($append));
+
+ return $this;
+ }
+
+ private function _closure($prop, $closure, $glue, $encapsulate = TRUE)
+ {
+ $builder = new QueryBuilder();
+ $method = 'get'.ucfirst($prop);
+
+ $closure($builder);
+
+ $return = QueryString::clean(implode($glue, $builder->$method()));
+
+ if($encapsulate)
+ {
+ $return = '('.$return.')';
+ }
+
+ return $return;
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/components/QueryString.php b/channel_data/libraries/Channeldata/components/QueryString.php
new file mode 100644
index 0000000..d89cb48
--- /dev/null
+++ b/channel_data/libraries/Channeldata/components/QueryString.php
@@ -0,0 +1,156 @@
+str = $str;
+ }
+
+ public function __toString()
+ {
+ return $this->str;
+ }
+
+ public static function url_title($str, $separator = 'dash', $lowercase = TRUE)
+ {
+ if (UTF8_ENABLED)
+ {
+ $CI =& get_instance();
+ $CI->load->helper('text');
+
+ $str = utf8_decode($str);
+ $str = preg_replace_callback('/(.)/', 'convert_accented_characters', $str);
+ }
+
+ $separator = ($separator == 'dash') ? '-' : '_';
+
+ $trans = array(
+ '&\#\d+?;' => '',
+ '&\S+?;' => '',
+ '\s+|/+' => $separator,
+ '[^a-z0-9\-\._]' => '',
+ $separator.'+' => $separator,
+ '^[-_]+|[-_]+$' => '',
+ '\.+$' => ''
+ );
+
+ $str = strip_tags($str);
+
+ foreach ($trans as $key => $val)
+ {
+ $str = preg_replace("#".$key."#i", $val, $str);
+ }
+
+ if ($lowercase === TRUE)
+ {
+ $str = strtolower($str);
+ }
+
+ return trim(stripslashes($str));
+ }
+
+ public static function protect($str, $table = FALSE)
+ {
+ if(!is_object($str))
+ {
+ $parts = explode('.', $str);
+
+ foreach($parts as $index => $part)
+ {
+ $part = trim(self::strip($part));
+
+ if(!preg_match('/\*/', $part))
+ {
+ $part = '`'.$part.'`';
+ }
+
+ $parts[$index] = $part;
+ }
+
+ if(count($parts) > 1)
+ {
+ $parts[0] = self::table($parts[0]);
+ }
+ else if($table && count($parts))
+ {
+ array_unshift($parts, self::table($table));
+ }
+
+ return implode('.', $parts);
+ }
+
+ return (string) $str;
+ }
+
+ public static function raw($str)
+ {
+ return new QueryString($str);
+ }
+
+ public static function escape($str)
+ {
+ if(!is_object($str))
+ {
+ return ee()->db->escape($str);
+ }
+
+ return (string) $str;
+ }
+
+ public static function operator($str)
+ {
+ if(!is_object($str))
+ {
+ return $str;
+ }
+
+ return (string) $str;
+ }
+
+ public static function table($str)
+ {
+ if(is_string($str))
+ {
+ $str = self::strip($str);
+
+ if(!preg_match('/^exp_/', $str))
+ {
+ $str = ee()->db->dbprefix($str);
+ }
+
+ return self::protect($str);
+ }
+
+ return (string) $str;
+ }
+
+ static function strip($str)
+ {
+ $str = preg_replace('/^\`|\`$/', '', $str);
+ $str = preg_replace('/\{\d*\}/', '', $str);
+
+ return $str;
+ }
+
+ public static function clean($sql)
+ {
+ if(is_array($sql))
+ {
+ $sql = implode(' ', $sql);
+ }
+
+ $sql = trim($sql);
+
+ foreach(array('AND', 'OR') as $value)
+ {
+ $sql = ltrim($sql, $value);
+ }
+
+ return trim($sql);
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/Action.php b/channel_data/libraries/Channeldata/models/Action.php
new file mode 100644
index 0000000..0c701c7
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/Action.php
@@ -0,0 +1,29 @@
+get();
+ }
+
+ public static function findByMethod($method)
+ {
+ return self::where('method', '=', $method)->get();
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/Channel.php b/channel_data/libraries/Channeldata/models/Channel.php
new file mode 100644
index 0000000..4f83343
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/Channel.php
@@ -0,0 +1,88 @@
+channel_name;
+ }
+
+ public function fields()
+ {
+ return ChannelField::findByGroup($this->field_group);
+ }
+
+ public static function findByEntry($entry_id)
+ {
+ $title = ChannelTitle::find($entry_id);
+
+ if(!$title)
+ {
+ return NULL;
+ }
+
+ return Channel::find($title->channel_id);
+ }
+
+ public static function findByName($name)
+ {
+ return self::query()->where('channel_name', $name)->get()->first();
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/ChannelData.php b/channel_data/libraries/Channeldata/models/ChannelData.php
new file mode 100644
index 0000000..b593109
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/ChannelData.php
@@ -0,0 +1,58 @@
+fill($data);
+
+ foreach(ChannelField::all()->items() as $item)
+ {
+
+ }
+ }
+ */
+
+ public static function findByChannel($channel)
+ {
+ $obj = new static;
+
+ $fillable = array();
+
+ $query = $obj->query();
+
+ foreach(ChannelField::findByChannel($channel)->all() as $field)
+ {
+ $fillable[] = 'field_id_'.$field->id();
+ $query->select('field_id_'.$field->id(), $field->name());
+ }
+
+
+
+ $obj->setAttribute('columns', $fillable);
+
+
+ /*
+ $return = $class::where('channel_data.channel_id', $channel)
+ ->join('channel_titles', 'channel_data.entry_id', '=', 'channel_titles.entry_id');
+ */
+
+
+ var_dump($query->get()->result()->first()->toArray());exit();
+
+ return $return->get();
+ }
+
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/ChannelEntry.php b/channel_data/libraries/Channeldata/models/ChannelEntry.php
new file mode 100644
index 0000000..ba846fc
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/ChannelEntry.php
@@ -0,0 +1,36 @@
+toArray(), $data->toArray());
+
+ /*
+ $channel = Channel::find($title->channel_id);
+ $class = ucfirst($channel->name());
+
+ if(class_exists($class))
+ {
+ exit('true');
+ }
+ */
+
+ var_dump('false');exit();
+ }
+
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/ChannelField.php b/channel_data/libraries/Channeldata/models/ChannelField.php
new file mode 100644
index 0000000..a27bde0
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/ChannelField.php
@@ -0,0 +1,88 @@
+field_label;
+ }
+
+ public function name()
+ {
+ return $this->field_name;
+ }
+
+ public static function findByEntry($entry)
+ {
+ $channel = Channel::findByEntry($entry);
+
+ if(!$channel)
+ {
+ return NULL;
+ }
+
+ return ChannelField::findByGroup($channel->field_group);
+ }
+
+ public static function findByChannel($channel)
+ {
+ $channel = Channel::find($channel);
+
+ if(!$channel)
+ {
+ return NULL;
+ }
+
+ return self::findByGroup($channel->field_group);
+ }
+
+ public static function findByName($name)
+ {
+ return self::query()->where('field_name', $name)->get()->first();
+ }
+
+ public static function findByGroup($groupId)
+ {
+ return self::query()->where('group_id', $groupId)->result();
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/models/ChannelTitle.php b/channel_data/libraries/Channeldata/models/ChannelTitle.php
new file mode 100644
index 0000000..e606ae3
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/ChannelTitle.php
@@ -0,0 +1,37 @@
+each(function($i, $field) use($self, $data) {
+ $self->setAttribute($field->name(), $data->{$field->name()});
+ });
+
+ parent::__construct($data);
+
+ if(isset($data->member_id))
+ {
+ $this->member_id = $data->member_id;
+ }
+
+ if(isset($data->group_id))
+ {
+ $this->group_id = $data->group_id;
+ }
+ }
+
+ public function memberFields()
+ {
+ $self = $this;
+ $array = array();
+
+ MemberField::all()->each(function($i, $field) use($self, &$array) {
+ $value = $self->getAttribute($field->name());
+
+ $array['m_field_id_'.$field->m_field_id] = $value;
+ });
+
+ return $array;
+ }
+
+ protected function _createRecord($data = array())
+ {
+ parent::_createRecord($data);
+
+ if(count($this->memberFields()))
+ {
+ ee()->db->insert('member_data', array_merge(
+ array('member_id' => $this->id()),
+ $this->memberFields()
+ ));
+ }
+
+ return $this;
+ }
+
+ protected function _updateRecord($data = array())
+ {
+ parent::_updateRecord($data);
+
+ if(count($this->memberFields()))
+ {
+ ee()->db->where($this->idField, $this->id());
+ ee()->db->update('member_data', $this->memberFields());
+ }
+
+ return $this;
+ }
+
+ public static function findByUsername($name)
+ {
+ return self::where('username', '=', $name)->get()->first();
+ }
+
+ public static function query()
+ {
+ $class = self::instantiate();
+
+ $query = new QueryBuilder();
+ $query->model = get_class($class);
+
+ $query->select('*');
+
+ MemberField::all()->each(function($i, $field) use ($query) {
+ $query->select('m_field_id_'.$field->id(), $field->m_field_name);
+ });
+
+ $query->from($class::table());
+ $query->join('member_data', 'members.member_id', '=', 'member_data.member_id');
+
+ return $query;
+ }
+}
diff --git a/channel_data/libraries/Channeldata/models/MemberField.php b/channel_data/libraries/Channeldata/models/MemberField.php
new file mode 100644
index 0000000..ce164cd
--- /dev/null
+++ b/channel_data/libraries/Channeldata/models/MemberField.php
@@ -0,0 +1,31 @@
+result()->ids();
+ }
+
+ public function entries($fixedOrder = FALSE)
+ {
+ $parser = new ChannelEntriesParser();
+
+ if($this->count() == 0)
+ {
+ return ChannelEntriesParser::noResults();
+ }
+
+ $ids = implode('|', $this->entryIds());
+
+ $params = array(
+ 'entry_id' => $ids
+ );
+
+ if($fixedOrder)
+ {
+ $params['fixed_order'] = $ids;
+ }
+
+ return $parser->entries($params);
+ }
+
+ protected function _collection($data)
+ {
+ if($this->model) {
+ return new ChannelCollection($data, $this, $this->model);
+ }
+
+ return $data;
+ }
+}
\ No newline at end of file
diff --git a/channel_data/libraries/Channeldata/responses/QueryResponse.php b/channel_data/libraries/Channeldata/responses/QueryResponse.php
new file mode 100644
index 0000000..2dc89f8
--- /dev/null
+++ b/channel_data/libraries/Channeldata/responses/QueryResponse.php
@@ -0,0 +1,101 @@
+builder = $builder;
+ $this->model = $model;
+
+ $this->query = ee()->db->query($this->builder->sql());
+ }
+
+ public function count()
+ {
+ return $this->query->num_rows();
+ }
+
+ public function each($closure)
+ {
+ return $this->result()->each($closure);
+ }
+
+ public function first()
+ {
+ if($this->count())
+ {
+ return $this->_model($this->query->first_row());
+ }
+
+ return NULL;
+ }
+
+ public function index($index)
+ {
+ $data = $this->result();
+
+ return isset($data[$index]) ? $this->_model($data[$index]) : NULL;
+ }
+
+ public function last()
+ {
+ return $this->_model($this->query->last_row());
+ }
+
+ public function next()
+ {
+ return $this->_model($this->query->next_row());
+ }
+
+ public function prev()
+ {
+ return $this->_model($this->query->prev_row());
+ }
+
+ public function result()
+ {
+ return $this->_collection($this->query->result());
+ }
+
+ public function get()
+ {
+ return $this->_collection($this->query->result());
+ }
+
+ public function row()
+ {
+ return $this->_model($this->query->row());
+ }
+
+ public function toArray()
+ {
+ return $this->_model($this->query->row())->toArray();
+ }
+
+ protected function _model($data)
+ {
+ if($this->model) {
+ return new $this->model($data);
+ }
+
+ return $data;
+ }
+
+ protected function _collection($data)
+ {
+ if($this->model) {
+ return new Collection($data, $this, $this->model);
+ }
+
+ return $data;
+ }
+}
\ No newline at end of file