36 'roles' => array(
'Admin')
54 if (!isset($_POST[
'parent_id'], $_POST[
'id'], $_POST[
'name'], $_POST[
'title'])) {
55 throw new CHttpException(400);
58 if (strpos($_POST[
'id'],
'tmp_') === 0) {
60 if ($_POST[
'parent_id'] !==
'root') {
66 throw new CHttpException(400);
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));
75 $errorsString = array();
76 foreach ($attribute->getErrors() as $field => $errors) {
77 $errorsString[] = $field .
': ' . implode(
', ', $errors);
79 echo CJSON::encode(array(
'error' => implode(
'; ', $errorsString)));
93 if (isset($_POST[
'id'])) {
96 echo CJSON::encode(array());
102 throw new CHttpException(400);
113 if (isset($_POST[
'user_id']) && isset($_POST[
'id']) && isset($_POST[
'state']) &&
User::model()->findByPk($_POST[
'user_id'])) {
114 if ($_POST[
'state'] == 1) {
117 $upa->user_id = $_POST[
'user_id'];
118 $upa->personalisation_attribute_id = $_POST[
'id'];