BriefBlocksController.php
1.9 KB
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
<?php
namespace controllers;
class BriefBlocksController extends \Phalcon\Mvc\Controller
{
function indexAction()
{
$data = \fields::find(array("type='services_sales' ","order" => 'id'));
$this->view->setVars([
'data' => $data,
]);
}
function setAction()
{
}
function addAction()
{
if($this->request->getPost()){
$id = $this->request->getPost('id');
$section_id = $this->request->getPost('section_id');
$model = \briefBlocksFields::findFirst("field_id=$section_id AND block_id=$id");
if($model instanceof \briefBlocksFields){
die("{$model->id}");
} else {
$model = new \briefBlocksFields();
$model->field_id = $section_id;
$model->block_id = $id;
$model->save();
die("{$model->id}");
}
} else {
echo "doesn't have any request ";
}
die();
}
function deleteAction($id)
{
$model = \briefBlocksFields::findFirst('id='.$id);
if($model instanceof \briefBlocksFields){
$model->delete();
}
}
function updateFieldsAction($id){
if($this->request->getPost()){
$model = \briefBlocksFields::findFirst("id=$id");
foreach($this->request->getPost() as $k => $v){
$model->$k = $v;
}
$model->save();
}
}
function updateAction($id)
{
$model = \briefBlocksFields::find("field_id = '$id' ORDER BY id");
$this->assets
->addJs('js/BriefBlockConstructor/HtmlConstructor.js')
->addJs('js/brief-block-constructor.js');
$this->view->pick( 'brief_blocks/addEdit' );
$this->view->setVars([
'data' => $model,
'section_id' => $id
]);
}
}