PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/Fields/Model/DbTable/Abstract.php

https://github.com/grandison/budo16
PHP | 98 lines | 66 code | 14 blank | 18 comment | 9 complexity | b8003fcd0bc44a55d95cb7f85584da75 MD5 | raw file
  1. <?php
  2. /**
  3. * SocialEngine
  4. *
  5. * @category Application_Core
  6. * @package Fields
  7. * @copyright Copyright 2006-2010 Webligo Developments
  8. * @license http://www.socialengine.net/license/
  9. * @version $Id: Abstract.php 7244 2010-09-01 01:49:53Z john $
  10. * @author John
  11. */
  12. /**
  13. * @category Application_Core
  14. * @package Fields
  15. * @copyright Copyright 2006-2010 Webligo Developments
  16. * @license http://www.socialengine.net/license/
  17. * @author John
  18. */
  19. abstract class Fields_Model_DbTable_Abstract extends Engine_Db_Table
  20. {
  21. protected $_fieldType;
  22. protected $_fieldTableType;
  23. protected $_rowsetClass = 'Fields_Model_Rowset';
  24. static public function factory($itemType, $tableType, $config = array())
  25. {
  26. if( !is_string($itemType) || !is_string($tableType) ) {
  27. throw new Fields_Model_Exception('Item type and table type must be strings');
  28. }
  29. $class = 'Fields_Model_DbTable_' . ucfirst($tableType);
  30. Engine_Loader::loadClass($class);
  31. return new $class($itemType, $tableType, $config);
  32. }
  33. public function __construct($itemType, $tableType, $config = array())
  34. {
  35. if( !is_string($itemType) || !is_string($tableType) ) {
  36. throw new Fields_Model_Exception('Item type and table type must be strings');
  37. }
  38. $this->_fieldType = $itemType;
  39. $this->_fieldTableType = $tableType;
  40. $config['name'] = $itemType . '_fields_' . $tableType;
  41. parent::__construct($config);
  42. }
  43. public function getFieldType()
  44. {
  45. if( null === $this->_fieldType ) {
  46. throw new Fields_Model_Exception('Type must be a string');
  47. }
  48. return $this->_fieldType;
  49. }
  50. public function getFieldTableType()
  51. {
  52. if( null === $this->_fieldTableType ) {
  53. $this->_fieldTableType = strtolower(trim(strrchr(get_class($this), '_'), '_'));
  54. }
  55. return $this->_fieldTableType;
  56. }
  57. // Caching stuff
  58. public function flushCache()
  59. {
  60. $this->_flushCache();
  61. return $this;
  62. }
  63. protected function _setCache($data)
  64. {
  65. if( Zend_Registry::isRegistered('Zend_Cache') &&
  66. ($cache = Zend_Registry::get('Zend_Cache')) instanceof Zend_Cache_Core ) {
  67. return $cache->save($data, get_class($this) . '__' . $this->_fieldType);
  68. }
  69. }
  70. protected function _getCache()
  71. {
  72. if( Zend_Registry::isRegistered('Zend_Cache') &&
  73. ($cache = Zend_Registry::get('Zend_Cache')) instanceof Zend_Cache_Core ) {
  74. return $cache->load(get_class($this) . '__' . $this->_fieldType);
  75. }
  76. }
  77. protected function _flushCache()
  78. {
  79. if( Zend_Registry::isRegistered('Zend_Cache') &&
  80. ($cache = Zend_Registry::get('Zend_Cache')) instanceof Zend_Cache_Core ) {
  81. return $cache->remove(get_class($this) . '__' . $this->_fieldType);
  82. }
  83. }
  84. }