| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/web_app/src/fetcher/lmbFetcher.class.php'); 10 lmb_require('limb/dbal/src/lmbTableGateway.class.php'); 11 lmb_require('limb/core/src/lmbClassPath.class.php'); 12 lmb_require('limb/core/src/lmbCollection.class.php'); 13 lmb_require('limb/core/src/lmbCollection.class.php'); 14 lmb_require('limb/active_record/src/lmbActiveRecord.class.php'); 15 16 /** 17 * class lmbActiveRecordFetcher. 18 * 19 * @package web_app 20 * @version $Id: lmbActiveRecordFetcher.class.php 5945 2007-06-06 08:31:43Z pachanga $ 21 */ 22 class lmbActiveRecordFetcher extends lmbFetcher 23 { 24 protected $class_path; 25 protected $record_id; 26 protected $record_ids; 27 protected $find; 28 protected $find_params = array(); 29 30 function setClassPath($value) 31 { 32 $this->class_path = $value; 33 } 34 35 function setRecordId($value) 36 { 37 if(!$value) 38 $value = ''; 39 $this->record_id = $value; 40 } 41 42 function setFind($find) 43 { 44 $this->find = $find; 45 } 46 47 function addFindParam($value) 48 { 49 $this->find_params[] = $value; 50 } 51 52 function setFindParams($find_params) 53 { 54 $this->find_params = $find_params; 55 } 56 57 function setRecordIds($value) 58 { 59 if(!is_array($value)) 60 $this->record_ids = array(); 61 else 62 $this->record_ids = $value; 63 } 64 65 function _createDataSet() 66 { 67 if(!$this->class_path) 68 throw new lmbException('Class path is not defined!'); 69 70 $class_path = new lmbClassPath($this->class_path); 71 $class_path->import(); 72 $class_name = $class_path->getClassName(); 73 74 if(is_null($this->record_id) && is_null($this->record_ids)) 75 { 76 if(!$this->find) 77 { 78 return lmbActiveRecord :: find($class_name); 79 } 80 else 81 { 82 $method = 'find' . lmb_camel_case($this->find); 83 $callback = array($class_name, $method); 84 if(!is_callable($callback)) 85 throw new lmbException('Active record of class "'. $class_name . '" does not support method "'. $method . '"'); 86 return call_user_func_array($callback, $this->find_params); 87 } 88 } 89 90 if($this->record_id) 91 { 92 try 93 { 94 if($this->find) 95 { 96 $method = 'find' . lmb_camel_case($this->find); 97 $callback = array($class_name, $method); 98 if(!is_callable($callback)) 99 throw new lmbException('Active record of class "'. $class_name . '" does not support method "'. $method . '"'); 100 $record = call_user_func_array($callback, array($this->record_id)); 101 } 102 else 103 $record = lmbActiveRecord :: findById($class_name, $this->record_id); 104 } 105 catch(lmbARNotFoundException $e) 106 { 107 $record = array(); 108 } 109 110 return $this->_singleItemCollection($record); 111 } 112 elseif($this->record_ids) 113 { 114 return lmbActiveRecord :: findByIds($class_name, $this->record_ids); 115 } 116 117 return new lmbCollection(); 118 } 119 120 protected function _singleItemCollection($ar) 121 { 122 return new lmbCollection(array($ar)); 123 } 124 } 125 126 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 14 04:47:40 2008 | Cross-referenced by PHPXref 0.7 |