/datasource_classes/RetrieveFM7VerboseData.class.php

https://github.com/matsuo/fxphp · PHP · 205 lines · 178 code · 11 blank · 16 comment · 48 complexity · ae1a5e8b9432c02a376ca69573d7da7e MD5 · raw file

  1. <?php
  2. require_once('RetrieveFM7Data.class.php');
  3. #### Part of FX.php #####################################################
  4. # #
  5. # License: Artistic License and addendum (included with release) #
  6. # Web Site: www.iviking.org #
  7. # #
  8. #########################################################################
  9. class RetrieveFM7VerboseData extends RetrieveFM7Data {
  10. var $currentFlag = '';
  11. var $currentRecord = '';
  12. var $currentSubrecordIndex;
  13. var $currentField = '';
  14. var $currentFieldIndex;
  15. var $isInRelatedSet = false;
  16. var $relatedSetTOC = '';
  17. // these values overwrite those in the parent class
  18. var $fmDataFile = 'fmresultset.xml';
  19. var $xmlStartHandler = 'elementStartVerbose';
  20. var $xmlContentHandler = 'elementContentsVerbose';
  21. var $xmlEndHandler = 'elementEndVerbose';
  22. /*
  23. * The functions for new XML parsing begin here
  24. */
  25. function elementStartVerbose ($parser, $name, $attrs) {
  26. switch(strtolower($name)) {
  27. case 'data':
  28. $this->currentFlag = "parseData";
  29. if ($this->FX->useInnerArray) {
  30. $this->FX->currentData[$this->currentRecord][$this->currentField][$this->currentFieldIndex] = "";
  31. } else {
  32. if ($this->isRemainName($this->currentField)) {
  33. if ($this->FX->portalAsRecord ) {
  34. $this->FX->currentData[$this->currentRecord][$this->getTOCName($this->currentField)][$this->currentSubrecordIndex][$this->currentField] = '';
  35. } else {
  36. $this->FX->currentData[$this->currentRecord][$this->currentField][$this->currentFieldIndex] = "";
  37. }
  38. } else {
  39. $this->FX->currentData[$this->currentRecord][$this->currentField] = "";
  40. }
  41. }
  42. break;
  43. case 'field':
  44. if ($this->isInRelatedSet) {
  45. $this->currentFieldIndex = $this->currentSubrecordIndex;
  46. }
  47. else $this->currentFieldIndex = 0;
  48. $this->currentField = $attrs['NAME'];
  49. if ($this->FX->useInnerArray && !$this->isInRelatedSet) {
  50. $this->FX->currentData[$this->currentRecord][$this->currentField] = array();
  51. } else if ($this->isRemainName($this->currentField) && !$this->FX->portalAsRecord) {
  52. $this->FX->currentData[$this->currentRecord][$this->currentField] = array();
  53. }
  54. break;
  55. case 'record':
  56. $recordID = $attrs['RECORD-ID'];
  57. if (substr_count($this->dataURL, '-dbnames') > 0) {
  58. $modID = count($this->FX->currentData);
  59. }
  60. else {
  61. $modID = $attrs['MOD-ID'];
  62. }
  63. if ($this->isInRelatedSet) {
  64. if ($this->FX->usePortalIDs) $this->currentSubrecordIndex = $recordID . '.' . $modID;
  65. if ($this->FX->portalAsRecord) {
  66. $this->FX->currentData[$this->currentRecord] = array( '-recid' => $recordID, '-modid' => $modID );
  67. }
  68. }
  69. else {
  70. $this->currentRecord = $recordID . '.' . $modID;
  71. $this->FX->currentData[$this->currentRecord] = array();
  72. }
  73. break;
  74. case 'relatedset':
  75. if ($attrs['COUNT'] > 0) {
  76. $this->isInRelatedSet = true;
  77. $this->currentSubrecordIndex = 0;
  78. $this->relatedSetTOC = $attrs['TABLE'];
  79. }
  80. break;
  81. case 'datasource':
  82. // TODO: Do we want to allow use of the additional data provided here now?
  83. $this->FX->dateFormat = $attrs['DATE-FORMAT'];
  84. $this->FX->timeFormat = $attrs['TIME-FORMAT'];
  85. $this->FX->totalRecordCount = $attrs['TOTAL-COUNT'];
  86. break;
  87. case 'field-definition':
  88. if ($this->FX->charSet != '' && function_exists('mb_convert_encoding')) {
  89. $this->FX->fieldInfo[$this->FX->fieldCount]['name'] = mb_convert_encoding($attrs['NAME'], $this->FX->charSet, 'UTF-8');
  90. }
  91. else {
  92. $this->FX->fieldInfo[$this->FX->fieldCount]['name'] = $attrs['NAME'];
  93. }
  94. $this->FX->fieldInfo[$this->FX->fieldCount]['emptyok'] = (($attrs['NOT-EMPTY'] == 'yes')?'no':'yes');
  95. $this->FX->fieldInfo[$this->FX->fieldCount]['maxrepeat'] = $attrs['MAX-REPEAT'];
  96. $this->FX->fieldInfo[$this->FX->fieldCount]['type'] = $attrs['RESULT'];
  97. $this->FX->fieldInfo[$this->FX->fieldCount]['extra'] = ''; // for compatibility w/ SQL databases
  98. if (substr_count($this->dataURL, '-view') < 1) {
  99. $this->FX->fieldCount++;
  100. }
  101. break;
  102. case 'resultset':
  103. $this->FX->foundCount = (int)$attrs['COUNT'];
  104. break;
  105. case 'error':
  106. $this->FX->fxError = $attrs['CODE'];
  107. break;
  108. case 'product':
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. function elementContentsVerbose($parser, $data) {
  115. switch($this->currentFlag) {
  116. case 'parseData':
  117. if ($this->FX->useInnerArray) {
  118. $this->FX->currentData[$this->currentRecord][$this->currentField][$this->currentFieldIndex] .= $this->xmlDecode($data);
  119. } else {
  120. if ($this->isRemainName($this->currentField)) {
  121. if ( $this->FX->portalAsRecord ) {
  122. $this->FX->currentData[$this->currentRecord][$this->relatedSetTOC][$this->currentSubrecordIndex][$this->currentField] .= $this->xmlDecode($data);
  123. } else {
  124. $this->FX->currentData[$this->currentRecord][$this->currentField][$this->currentFieldIndex] .= $this->xmlDecode($data);
  125. }
  126. } else {
  127. $this->FX->currentData[$this->currentRecord][$this->currentField] .= $this->xmlDecode($data);
  128. }
  129. }
  130. break;
  131. default:
  132. break;
  133. }
  134. }
  135. function elementEndVerbose($parser, $name) {
  136. switch(strtolower($name)) {
  137. case 'data':
  138. if (!$this->isInRelatedSet) ++$this->currentFieldIndex;
  139. $this->currentFlag = "";
  140. break;
  141. case 'field':
  142. break;
  143. case 'record':
  144. if ($this->isInRelatedSet && !$this->FX->usePortalIDs) ++$this->currentSubrecordIndex;
  145. if (strlen(trim($this->FX->customPrimaryKey)) > 0) {
  146. if ($this->FX->useInnerArray) {
  147. $this->FX->currentData[$this->FX->currentData[$this->currentRecord][$this->FX->customPrimaryKey][0]]
  148. = $this->FX->currentData[$this->currentRecord];
  149. } else {
  150. if ($this->isRemainName($this->currentField)) {
  151. if ($this->FX->portalAsRecord) {
  152. //
  153. } else {
  154. $this->FX->currentData[$this->FX->currentData[$this->currentRecord][$this->FX->customPrimaryKey][0]]
  155. = $this->FX->currentData[$this->currentRecord];
  156. }
  157. } else {
  158. $this->FX->currentData[$this->FX->currentData[$this->currentRecord][$this->FX->customPrimaryKey]]
  159. = $this->FX->currentData[$this->currentRecord];
  160. }
  161. }
  162. unset($this->FX->currentData[$this->currentRecord]);
  163. }
  164. elseif (!$this->isInRelatedSet) {
  165. // add any missing fields as blank data
  166. foreach ($this->FX->fieldInfo as $tempField) {
  167. if (!isset($this->FX->currentData[$this->currentRecord][$tempField['name']])) {
  168. if ($this->FX->useInnerArray) {
  169. $this->FX->currentData[$this->currentRecord][$tempField['name']] = array();
  170. }
  171. else {
  172. $this->FX->currentData[$this->currentRecord][$tempField['name']] = '';
  173. }
  174. }
  175. }
  176. }
  177. break;
  178. case 'relatedset':
  179. $this->isInRelatedSet = false;
  180. break;
  181. default:
  182. break;
  183. }
  184. }
  185. /*
  186. * The functions for new XML parsing end here
  187. */
  188. function xmlDecode ($value) {
  189. if ($this->FX->dataParamsEncoding != '' && function_exists('mb_convert_encoding')) {
  190. return mb_convert_encoding($value, $this->FX->charSet, 'UTF-8');
  191. }
  192. return preg_replace_callback($this->UTF8SpecialChars, array($this, 'utf8HTMLEntities'), $value);
  193. }
  194. }