/** * Deletes a Profile Field Category */ public function actionDeleteCategory() { $this->forcePostRequest(); $id = (int) Yii::app()->request->getQuery('id'); $category = ProfileFieldCategory::model()->findByPk($id); if ($category == null) { throw new CHttpException(500, Yii::t('AdminModule.controllers_UserprofileController', 'Could not load category.')); } if (count($category->fields) != 0) { throw new CHttpException(500, Yii::t('AdminModule.controllers_UserprofileController', 'You can only delete empty categories!')); } $category->delete(); $this->redirect(Yii::app()->createUrl('//admin/userprofile')); }
/** * Returns The Form Definition to edit the ProfileField Model. * * @return Array CForm Definition */ public function getFormDefinition() { $categories = ProfileFieldCategory::model()->findAll(array('order' => 'sort_order')); $definition = array('ProfileField' => array('type' => 'form', 'elements' => array('internal_name' => array('type' => 'text', 'maxlength' => 32, 'class' => 'form-control'), 'title' => array('type' => 'text', 'maxlength' => 32, 'class' => 'form-control'), 'description' => array('type' => 'textarea', 'class' => 'form-control'), 'sort_order' => array('type' => 'text', 'maxlength' => 32, 'class' => 'form-control'), 'translation_category' => array('type' => 'text', 'maxlength' => 32, 'class' => 'form-control', 'value' => $this->getTranslationCategory()), 'ldap_attribute' => array('type' => 'text', 'maxlength' => 255, 'class' => 'form-control'), 'required' => array('type' => 'checkbox'), 'visible' => array('type' => 'checkbox'), 'show_at_registration' => array('type' => 'checkbox'), 'editable' => array('type' => 'checkbox'), 'profile_field_category_id' => array('type' => 'dropdownlist', 'items' => CHtml::listData($categories, 'id', 'title'), 'class' => 'form-control'), 'field_type_class' => array('type' => 'dropdownlist', 'items' => ProfileFieldType::getFieldTypes(), 'class' => 'form-control')))); // Field Type and Internal Name cannot be changed for existing records // So disable these fields. if (!$this->isNewRecord) { $definition['ProfileField']['elements']['field_type_class']['disabled'] = true; $definition['ProfileField']['elements']['internal_name']['readonly'] = true; } return $definition; }
/** * Returns all profile field categories with some user data * * @todo Optimize me * @return Array ProfileFieldCategory */ public function getProfileFieldCategories() { $categories = array(); foreach (ProfileFieldCategory::model()->findAll(array('order' => 'sort_order')) as $category) { if (count($this->getProfileFields($category)) != 0) { $categories[] = $category; } } return $categories; }
</div> <div class="panel-body"> <?php echo HHtml::link('Add new category', $this->createUrl('//admin/userprofile/editCategory'), array('class' => 'btn btn-primary')); ?> <?php echo HHtml::link('Add new field', $this->createUrl('//admin/userprofile/editField'), array('class' => 'btn btn-primary')); ?> <hr> <ul> <?php foreach (ProfileFieldCategory::model()->findAll(array('order' => 'sort_order')) as $category) { ?> <li> <a href="<?php echo $this->createUrl('editCategory', array('id' => $category->id)); ?> ">Category: <?php echo $category->title; ?> </a> <ul class="admin-userprofiles-fields"> <?php foreach (ProfileField::model()->findAllByAttributes(array('profile_field_category_id' => $category->id), array('order' => 'sort_order')) as $field) { ?> <li class="admin-userprofiles-field" data-id="<?php echo $field->id;