This repository has been archived by the owner on Oct 27, 2018. It is now read-only.
/
ActsController.php
85 lines (75 loc) · 2.12 KB
/
ActsController.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
<?php
namespace App\Controller;
use App\Model\Table\ActsTable;
use Cake\ORM\TableRegistry;
/**
* Acts Controller
*
* @property ActsTable $Acts
*/
class ActsController extends AppController
{
/**
* Config value, like strings and model names.
* Filled in initialize();
*
* @var array
*/
public $config = [
'strings' => [],
'models' => [],
];
/**
* Loads additionnal models and create the configuration array
*
* @return void
*/
public function initialize()
{
parent::initialize();
// Create config strings
$this->config = [
'strings' => [
'edit' => __d('elabs', 'has been updated'),
'delete' => __d('elabs', 'has been removed'),
],
'models' => [
'Files' => __d('elabs', 'File'),
'Posts' => __d('elabs', 'Article'),
'Projects' => __d('elabs', 'Project'),
'Notes' => __d('elabs', 'Note'),
'Albums' => __d('elabs', 'Album'),
]
];
// Load models
foreach ($this->config['models'] as $model => $item) {
$this->$model = TableRegistry::get($model);
}
}
/**
* Index method
*
* @param string $updateFilter Hides the updates, 'yes' or 'no'
*
* @return void
*/
public function index($updateFilter = 'showUpdates')
{
// Prepare the pagination and filter
$this->paginate = [
'maxLimit' => 30,
'limit' => 30,
'sortWhitelist' => []
];
if ($updateFilter === 'hideUpdates') {
$this->paginate['conditions']['type'] = 'add';
}
// Order is defined here to limit manual order
$query = $this->Acts->find('default', ['sfw' => !$this->seeNSFW])->order(['Acts.created' => 'desc']);
// Pass variables to view
$this->set('filterUpdates', $updateFilter);
$this->set('acts', $this->paginate($query));
$this->set('config', $this->config);
$this->set('_serialize', ['acts']);
}
}