|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package content |
|
4
|
|
|
*/ |
|
5
|
|
|
/** |
|
6
|
|
|
* The AjaxReorder page is used for reordering objects in the Symphony |
|
7
|
|
|
* backend through Javascript. At the moment this is only supported for |
|
8
|
|
|
* Pages and Sections. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
class contentAjaxReorder extends XMLPage |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
const kREORDER_PAGES = 0; |
|
|
|
|
|
|
14
|
|
|
const kREORDER_SECTIONS = 1; |
|
|
|
|
|
|
15
|
|
|
const kREORDER_EXTENSION = 2; |
|
|
|
|
|
|
16
|
|
|
const kREORDER_UNKNOWN = 3; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function view() |
|
19
|
|
|
{ |
|
20
|
|
|
$items = $_REQUEST['items']; |
|
21
|
|
|
|
|
22
|
|
|
if (!is_array($items) || empty($items)) { |
|
23
|
|
|
return; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$destination = self::kREORDER_UNKNOWN; |
|
27
|
|
|
|
|
28
|
|
|
if ($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') { |
|
29
|
|
|
$destination = self::kREORDER_PAGES; |
|
30
|
|
|
} elseif ($this->_context[0] == 'blueprints' && $this->_context[1] == 'sections') { |
|
31
|
|
|
$destination = self::kREORDER_SECTIONS; |
|
32
|
|
|
} elseif ($this->_context[0] == 'extensions') { |
|
33
|
|
|
$destination = self::kREORDER_EXTENSION; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
switch ($destination) { |
|
37
|
|
|
case self::kREORDER_PAGES: |
|
38
|
|
|
foreach ($items as $id => $position) { |
|
39
|
|
|
if (!PageManager::edit($id, array('sortorder' => $position))) { |
|
40
|
|
|
$this->setHttpStatus(self::HTTP_STATUS_ERROR); |
|
41
|
|
|
$this->_Result->setValue(__('A database error occurred while attempting to reorder.')); |
|
42
|
|
|
break; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
break; |
|
46
|
|
|
case self::kREORDER_SECTIONS: |
|
47
|
|
|
foreach ($items as $id => $position) { |
|
48
|
|
|
if (!SectionManager::edit($id, array('sortorder' => $position))) { |
|
49
|
|
|
$this->setHttpStatus(self::HTTP_STATUS_ERROR); |
|
50
|
|
|
$this->_Result->setValue(__('A database error occurred while attempting to reorder.')); |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
break; |
|
55
|
|
|
case self::kREORDER_EXTENSION: |
|
56
|
|
|
// TODO |
|
57
|
|
|
break; |
|
58
|
|
|
case self::kREORDER_UNKNOWN: |
|
59
|
|
|
default: |
|
60
|
|
|
$this->setHttpStatus(self::HTTP_STATUS_BAD_REQUEST); |
|
61
|
|
|
break; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.