[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 class SqlResultIterator implements Iterator{ 12 function __construct($adb, $result){ 13 $this->result = $result; 14 $this->adb = $adb; 15 $this->pos = 0; 16 } 17 18 public function rewind(){ 19 $this->pos = 0; 20 } 21 22 function valid(){ 23 $adb = $this->adb; 24 return $this->pos < $adb->num_rows($this->result); 25 } 26 27 public function next(){ 28 $this->pos+=1; 29 } 30 31 public function current(){ 32 $adb = $this->adb; 33 $data = $adb->raw_query_result_rowdata($this->result, $this->pos); 34 return new SqlResultIteratorRow($data); 35 } 36 37 public function key(){ 38 return $this->pos; 39 } 40 41 42 /** 43 * Return the contents of the resultset as an array. Destroys a running iterator's state. 44 * 45 * This method will reset the iterator using the rewind method. 46 * 47 * $copyFields specify which fields of the result to copy to the array. 48 * If not specified the function will return values for all the fields. 49 */ 50 function toArray($copyFields=null){ 51 $adb = $this->adb; 52 $this->rewind(); 53 54 if($copyFields===null){ 55 $columnData = $adb->getFieldsDefinition($this->result); 56 $columnNames = array(); 57 foreach($columnData as $column){ 58 $columnNames[]=$column->name; 59 } 60 $copyFields = $columnNames; 61 } 62 63 $arr=array(); 64 foreach($this as $row){ 65 $rowArr = array(); 66 foreach($copyFields as $name){ 67 $rowArr[$name]=$row->$name; 68 } 69 $arr[]=$rowArr; 70 } 71 return $arr; 72 $this->rewind(); 73 } 74 } 75 76 class SqlResultIteratorRow{ 77 function __construct($data){ 78 $this->data = $data; 79 } 80 81 function get($column){ 82 return $this->data[$column]; 83 } 84 85 function __get($column){ 86 return $this->get($column); 87 } 88 89 } 90 91 92 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |