Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ManageController.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  */
12 {
13 
14  /**
15  * Returns filers array
16  *
17  * @return array
18  */
19  public function filters()
20  {
21  return array(
22  'accessControl'
23  );
24  }
25 
26  /**
27  * returns filter rules
28  *
29  * @return array
30  */
31  public function accessRules()
32  {
33  return array(
34  array(
35  'allow',
36  'roles' => array('Admin')
37  ),
38  array(
39  'deny',
40  'users' => array('*')
41  )
42  );
43  }
44 
45  /**
46  * saves personalisation attribute
47  *
48  * @throws CHttpException
49  *
50  * @return void
51  */
52  public function actionSaveAttribute()
53  {
54  if (!isset($_POST['parent_id'], $_POST['id'], $_POST['name'], $_POST['title'])) {
55  throw new CHttpException(400);
56  }
57 
58  if (strpos($_POST['id'], 'tmp_') === 0) {
59  $attribute = new PersonalisationAttribute();
60  if ($_POST['parent_id'] !== 'root') {
61  $attribute->childOf(PersonalisationAttribute::model()->findByPk($_POST['parent_id']));
62  }
63  } else {
64  $attribute = PersonalisationAttribute::model()->findByPk($_POST['id']);
65  if (!$attribute) {
66  throw new CHttpException(400);
67  }
68  }
69  $attribute->name = $_POST['name'];
70  $attribute->title = !empty($_POST['title']) ? $_POST['title'] : $_POST['name'];
71  if ($attribute->save()) {
72  echo CJSON::encode(array('id' => $attribute->id, 'parent_id' => $attribute->parent_id, 'name' => $attribute->name, 'title' => $attribute->title));
73  Yii::app()->end();
74  } else {
75  $errorsString = array();
76  foreach ($attribute->getErrors() as $field => $errors) {
77  $errorsString[] = $field . ': ' . implode(', ', $errors);
78  }
79  echo CJSON::encode(array('error' => implode('; ', $errorsString)));
80  Yii::app()->end();
81  }
82  }
83 
84  /**
85  * Deletes personalisation attribute
86  *
87  * @throws CHttpException
88  *
89  * @return void
90  */
91  public function actionDeleteAttribute()
92  {
93  if (isset($_POST['id'])) {
94  $pa = PersonalisationAttribute::model()->findByPk($_POST['id']);
95  if ($pa->delete()) {
96  echo CJSON::encode(array());
97  } else {
98  echo CJSON::encode(array('error' => PersonalisationModule::t('Can\'t delete attribute')));
99  }
100  Yii::app()->end();
101  } else {
102  throw new CHttpException(400);
103  }
104  }
105 
106  /**
107  * Updates user personalisation attribute
108  *
109  * @return void
110  */
111  public function actionUpdateUserAttribute()
112  {
113  if (isset($_POST['user_id']) && isset($_POST['id']) && isset($_POST['state']) && User::model()->findByPk($_POST['user_id'])) {
114  if ($_POST['state'] == 1) {
115  if (PersonalisationAttribute::model()->findByPk($_POST['id'])) {
116  $upa = new UserPersonalisationAttribute();
117  $upa->user_id = $_POST['user_id'];
118  $upa->personalisation_attribute_id = $_POST['id'];
119  $upa->save();
120  }
121  } else {
122  UserPersonalisationAttribute::model()->deleteAllByAttributes(array('user_id' => $_POST['user_id'], 'personalisation_attribute_id' => $_POST['id']));
123  }
124  }
125  }
126 
127 }