1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35:
36: class Mage_Reports_Model_Test extends Varien_Object
37: {
38:
39: public function getUsersCountries( )
40: {
41: return file_get_contents( Mage::getModuleDir('etc','Mage_Reports').DS.'flexTestDataCountries.xml' );
42: }
43:
44: public function getUsersCities( $countryId )
45: {
46: $dom = new DOMDocument();
47: $dom -> preserveWhiteSpace = false;
48: $dom -> load( Mage::getModuleDir('etc','Mage_Reports').DS.'flexTestDataCities.xml' );
49:
50: $root = $dom -> documentElement;
51: $rows = $root -> getElementsByTagName( 'row' );
52:
53: $childsToRemove = array();
54: for( $i = 0; $i < $rows -> length; $i++)
55: {
56: for( $j = 0; $j < $rows -> item($i) -> childNodes -> length; $j ++ )
57: if(
58: $rows -> item($i) -> childNodes -> item($j) -> nodeType == XML_ELEMENT_NODE
59: &&
60: $rows -> item($i) -> childNodes -> item($j) -> nodeName == 'countryId'
61: &&
62: $rows -> item($i) -> childNodes -> item($j) -> nodeValue != $countryId
63: )
64: $childsToRemove[] = $rows -> item($i);
65: }
66:
67: foreach( $childsToRemove as $child )
68: $root -> removeChild( $child );
69:
70: return $dom -> saveXML();
71: }
72:
73: public function getTimelineData( )
74: {
75: return file_get_contents( Mage::getModuleDir('etc','Mage_Reports').DS.'flexTestDataTimeline.xml' );
76: }
77:
78: public function getAllLinearExample( )
79: {
80: $session = Mage::getModel('session_data/');
81:
82: $startPoint = time() - 24*60*60;
83:
84: $allData = array();
85: $countOfStartData = 12;
86: for($i = 1; $i<= $countOfStartData; $i++)
87: {
88: $allData[] = array( 'time'=>date("Y-m-d H:i",$startPoint), 'value'=>rand(1, 100) );
89: $startPoint += 30*60;
90: }
91:
92: $allData[] = array( 'time'=>date("Y-m-d H:i",$startPoint+(90*60)));
93:
94: $session -> setData('startPoint', $startPoint);
95:
96: return $this -> returnAsDataSource( $allData );
97: }
98:
99: public function getNewLinearData()
100: {
101: $session = Mage::getModel('session_data/');
102:
103:
104: $startPoint = $session -> getData('startPoint');
105:
106: $reset = 12;
107:
108:
109: $newData = array(
110: array( 'time'=> date("Y-m-d H:i", $startPoint), 'value'=>rand(1, 100) )
111: );
112:
113: $startPoint += 30*60;
114: $newData[] = array( 'time'=> date("Y-m-d H:i", $startPoint+(90*60)) );
115:
116: $session -> setData('startPoint', $startPoint);
117:
118: return $this -> returnAsDataSource( $newData, $reset );
119: }
120:
121: private function returnAsDataSource( &$array , $reset = 0)
122: {
123: $dom = new DOMDocument();
124: $dom -> preserveWhiteSpace = false;
125: $dom -> loadXML( "<"."?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n<dataSource></dataSource>" );
126: $root = $dom ->documentElement;
127: if($reset)
128: {
129: $resetItem = $dom -> createElement("reset");
130: $resetItem -> nodeValue = $reset;
131: $root->appendChild($resetItem);
132: }
133: foreach($array as $item )
134: {
135: $row = $dom->createElement('row');
136: foreach( $item as $key => $val)
137: {
138: $valItem = $dom->createElement( $key );
139: $valItem->nodeValue = $val;
140: $row->appendChild($valItem);
141: }
142:
143: $root->appendChild($row);
144: }
145:
146: return $dom->saveXML();
147: }
148: }
149: