/
content_frontpages_controller.php
125 lines (113 loc) · 3.94 KB
/
content_frontpages_controller.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Comment Template.
*
* @todo -c Implement .this needs to be sorted out.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://www.dogmatic.co.za
* @package sort
* @subpackage sort.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*/
class ContentFrontpagesController extends CmsAppController
{
var $name = 'ContentFrontpages';
/**
* Helpers.
*
* @access public
* @var array
*/
var $helpers = array( 'Filter.Filter' );
function index()
{
$this->ContentFrontpage->recursive = 0;
$this->set( 'contentFrontpages', $this->paginate() );
}
function admin_index()
{
$this->ContentFrontpage->recursive = 0;
$this->paginate = array(
'fields' => array(
'ContentFrontpage.id',
'ContentFrontpage.content_id',
'ContentFrontpage.ordering',
'ContentFrontpage.created',
'ContentFrontpage.modified'
),
'contain' => array(
'Content' => array(
'fields' => array(
'Content.id',
'Content.title',
'Content.active',
),
'Category' => array(
'fields' => array(
'Category.id',
'Category.title'
)
)
)
)
);
$contentFrontpages = $this->paginate();
$this->set( 'contentFrontpages', $contentFrontpages );
$this->set( 'filterOptions', $this->Filter->filterOptions );
}
function admin_add()
{
if ( !empty( $this->data ) )
{
$this->ContentFrontpage->create();
if ( $this->ContentFrontpage->save( $this->data ) )
{
$this->Session->setFlash( __( 'The content frontpage has been saved', true ) );
$this->redirect( array( 'action' => 'index' ) );
}
else
{
$this->Session->setFlash( __( 'The content frontpage could not be saved. Please, try again.', true ) );
}
}
/**
* check what is already in the table so that the list only shows
* what is available.
*/
$content_ids = $this->ContentFrontpage->find(
'list',
array(
'fields' => array(
'ContentFrontpage.content_id',
'ContentFrontpage.content_id'
)
)
);
/**
* only get the content itmes that are not being used.
*/
$contents = $this->ContentFrontpage->Content->find(
'list',
array(
'conditions' => array(
'Content.id NOT IN ( '.implode( ',', ( ( !empty( $content_ids ) ) ? $content_ids : array( 0 ) ) ).' )'
)
)
);
if ( empty( $contents ) )
{
$this->Session->setFlash( __( 'You have all the items on your home page.', true ) );
$this->redirect( $this->referer() );
}
$this->set( compact( 'contents' ) );
}
}
?>