forked from dereuromark/cakephp-data
/
CountriesController.php
67 lines (55 loc) · 1.57 KB
/
CountriesController.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
<?php
namespace Data\Controller;
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Data\Controller\DataAppController;
use Cake\Event\Event;
class CountriesController extends DataAppController {
public $paginate = ['order' => ['Country.sort' => 'DESC']];
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
if ($specific = Configure::read('Country.image_path')) {
$this->imageFolder = WWW_ROOT . 'img' . DS . $specific . DS;
} else {
$this->imageFolder = Plugin::path('Data') . DS . 'webroot' . DS . 'img' . DS . 'country_flags' . DS;
}
if (isset($this->Auth)) {
$this->Auth->allow('index');
/*
$this->Auth->actionMap = array_merge($this->Auth->actionMap, array(
'admin_down' => 'edit',
'admin_up' => 'edit'
));
*/
}
}
/**
* CountriesController::index()
*
* @return void
*/
public function index() {
$countries = $this->paginate();
$this->set(compact('countries'));
}
protected function _icons() {
$useCache = true;
if (!empty($this->request->params['named']['reset'])) {
$useCache = false;
}
if ($useCache && ($iconNames = Cache::read('country_icon_names')) !== false) {
$this->Flash->info('Cache Used');
return $iconNames;
}
$handle = new Folder($this->imageFolder);
$icons = $handle->read(true, true);
$iconNames = [];
foreach ($icons[1] as $icon) { # only use files (not folders)
$iconNames[] = strtoupper(extractPathInfo('filename', $icon));
}
Cache::write('country_icon_names', $iconNames);
return $iconNames;
}
}