C_DataMapper_Driver_Base

Class C_DataMapper_Driver_Base.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/datamapper/package.module.datamapper.php  
  1. class C_DataMapper_Driver_Base extends C_Component 
  2. var $_object_name; 
  3. var $_model_factory_method = FALSE; 
  4. var $_columns = array(); 
  5. var $_table_columns = array(); 
  6. var $_serialized_columns = array(); 
  7. function define($object_name = FALSE, $context = FALSE) 
  8. parent::define($context); 
  9. $this->add_mixin('Mixin_DataMapper_Driver_Base'); 
  10. $this->implement('I_DataMapper_Driver'); 
  11. $this->_object_name = $object_name; 
  12. function initialize() 
  13. parent::initialize(); 
  14. $this->_cache = array(); 
  15. if ($this->has_method('define_columns')) { 
  16. $this->define_columns(); 
  17. $this->lookup_columns(); 
  18. /** 
  19. * Gets the object name 
  20. * @return string 
  21. */ 
  22. function get_object_name() 
  23. return $this->_object_name; 
  24. /** 
  25. * Gets the name of the table 
  26. * @global string $table_prefix 
  27. * @return string 
  28. */ 
  29. function get_table_name() 
  30. global $table_prefix; 
  31. global $wpdb; 
  32. $prefix = $table_prefix; 
  33. if ($wpdb != null && $wpdb->prefix != null) { 
  34. $prefix = $wpdb->prefix; 
  35. return apply_filters('ngg_datamapper_table_name', $prefix . $this->_object_name, $this->_object_name); 
  36. /** 
  37. * Looks up using SQL the columns existing in the database, result is cached 
  38. */ 
  39. function lookup_columns() 
  40. // Avoid doing multiple SHOW COLUMNS if we can help it 
  41. $key = C_Photocrati_Transient_Manager::create_key('col_in_' . $this->get_table_name(), 'columns'); 
  42. $this->_table_columns = C_Photocrati_Transient_Manager::fetch($key, FALSE); 
  43. if (!$this->_table_columns) { 
  44. $this->object->update_columns_cache(); 
  45. return $this->_table_columns; 
  46. /** 
  47. * Looks up using SQL the columns existing in the database 
  48. */ 
  49. function update_columns_cache() 
  50. $key = C_Photocrati_Transient_Manager::create_key('col_in_' . $this->get_table_name(), 'columns'); 
  51. global $wpdb; 
  52. $this->_table_columns = array(); 
  53. $sql = "SHOW COLUMNS FROM `{$this->get_table_name()}`"; 
  54. foreach ($wpdb->get_results($sql) as $row) { 
  55. $this->_table_columns[] = $row->Field; 
  56. C_Photocrati_Transient_Manager::update($key, $this->_table_columns); 
  57. /** 
  58. * Determines whether a column is present for the table 
  59. * @param string $column_name 
  60. * @return string 
  61. */ 
  62. function has_column($column_name) 
  63. if (empty($this->object->_table_columns)) { 
  64. $this->object->lookup_columns(); 
  65. return array_search($column_name, $this->object->_table_columns) !== FALSE; 
  66. /** 
  67. * Sets the name of the factory method used to create a model for this entity 
  68. * @param string $method_name 
  69. */ 
  70. function set_model_factory_method($method_name) 
  71. $this->_model_factory_method = $method_name; 
  72. /** 
  73. * Gets the name of the factory method used to create a model for this entity 
  74. */ 
  75. function get_model_factory_method() 
  76. return $this->_model_factory_method; 
  77. /** 
  78. * Gets the name of the primary key column 
  79. * @return string 
  80. */ 
  81. function get_primary_key_column() 
  82. return $this->_primary_key_column; 
  83. /** 
  84. * Gets the class name of the driver used 
  85. * @return string 
  86. */ 
  87. function get_driver_class_name() 
  88. return get_called_class(); 
  89. function cache($key, $results) 
  90. if ($this->object->_use_cache) { 
  91. $this->_cache[$key] = $results; 
  92. function get_from_cache($key, $default = NULL) 
  93. if ($this->object->_use_cache && isset($this->_cache[$key])) { 
  94. return $this->_cache[$key]; 
  95. } else { 
  96. return $default;