-
Notifications
You must be signed in to change notification settings - Fork 2
/
Disk.php
executable file
·88 lines (75 loc) · 2.16 KB
/
Disk.php
1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class Convenient_AdminGrid_Model_Resource_Collection_Disk extends Convenient_Data_Collection_NoDb
{
protected $objectCachedData = null;
/**
* Create a filterable admin panel grid by reading in data.csv
*
* @return $this|array
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
protected function fetchData()
{
if (is_null($this->objectCachedData)) {
$data = $this->getFromCache();
if (!$data) {
$data = array();
$handle = fopen('data.csv', 'r');
if (!$handle) {
die("Failed to open file");
}
$headersData = fgetcsv($handle);
if ($headersData == false) {
die("Failed to load file headers");
}
while (($line = fgetcsv($handle)) !== false) {
$temp = array_combine($headersData, $line);
$item = $this->getNewEmptyItem();
$item->addData($temp);
$data[] = $item;
}
fclose($handle);
$this->saveToCache($data);
}
$this->objectCachedData = $data;
}
return $this->objectCachedData;
}
/**
* @return bool|mixed
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
public function getFromCache()
{
$data = $this->getCacheInstance()->load('convenient_admingrid_collection_disk_access');
if ($data) {
return unserialize($data);
}
return false;
}
/**
* @param $data
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
public function saveToCache($data)
{
$this->getCacheInstance()->save(
serialize($data),
'convenient_admingrid_collection_disk_access',
array(),
3600
);
}
/**
* @return Mage_Core_Model_Cache
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
protected function getCacheInstance()
{
return Mage::app()->getCacheInstance();
}
}