Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ProfileFieldController Class Reference
Inheritance diagram for ProfileFieldController:
Controller BaseController

Public Member Functions

 filters ()
 accessRules ()
 actionView ()
 afterAction ($action)
 registerScript ()
 actionCreate ()
 actionUpdate ()
 actionDelete ()
 actionAdmin ()
 loadModel ()
 fieldType ($type)

Static Public Member Functions

static getWidgets ($fieldType= '')

Public Attributes

 $defaultAction = 'admin'
- Public Attributes inherited from Controller
 $menu = array()
 $breadcrumbs = array()
- Public Attributes inherited from BaseController
 $layout = '//layouts/gportal'
 $mailLayout = '//layouts/mail'

Additional Inherited Members

- Protected Member Functions inherited from BaseController
 beforeAction ($action)

Detailed Description

Definition at line 3 of file ProfileFieldController.php.

Member Function Documentation

ProfileFieldController::accessRules ( )

Specifies the access control rules. This method is used by the 'accessControl' filter.

Returns
array access control rules

Definition at line 28 of file ProfileFieldController.php.

{
return array(
// array('allow', // allow all users to perform 'index' and 'view' actions
// 'actions' => array('*'),
// 'users' => array('*'),
// ),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions' => array('create', 'update', 'view', 'admin', 'delete'),
'roles' => array('Admin'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
ProfileFieldController::actionAdmin ( )

Manages all models.

Definition at line 461 of file ProfileFieldController.php.

{
$model = new ProfileField('search');
$model->field_size = null;
$model->required = null;
$model->position = null;
$model->visible = null;
if (isset($_GET['ProfileField'])) {
$model->attributes = $_GET['ProfileField'];
}
$this->render('admin', array(
'model' => $model,
));
}
ProfileFieldController::actionCreate ( )

Creates a new model. If creation is successful, the browser will be redirected to the 'view' page.

Definition at line 327 of file ProfileFieldController.php.

References fieldType(), Profile\model(), and registerScript().

{
$model = new ProfileField;
$scheme = get_class(Yii::app()->db->schema);
if (isset($_POST['ProfileField'])) {
$model->attributes = $_POST['ProfileField'];
if ($model->validate()) {
$sql = 'ALTER TABLE ' . Profile::model()->tableName() . ' ADD `' . $model->varname . '` ';
$sql .= $this->fieldType($model->field_type);
if (
$model->field_type != 'TEXT'
&& $model->field_type != 'DATE'
&& $model->field_type != 'BOOL'
&& $model->field_type != 'BLOB'
&& $model->field_type != 'BINARY'
)
$sql .= '(' . $model->field_size . ')';
$sql .= ' NOT NULL ';
if ($model->field_type != 'TEXT' && $model->field_type != 'BLOB' || $scheme != 'CMysqlSchema') {
if ($model->default)
$sql .= " DEFAULT '" . $model->default . "'";
else
$sql .= ((
$model->field_type == 'TEXT'
|| $model->field_type == 'VARCHAR'
|| $model->field_type == 'BLOB'
|| $model->field_type == 'BINARY'
) ? " DEFAULT ''" : (($model->field_type == 'DATE') ? " DEFAULT '0000-00-00'" : " DEFAULT 0"));
}
$model->dbConnection->createCommand($sql)->execute();
$model->save();
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->registerScript();
$this->render('create', array(
'model' => $model,
));
}
ProfileFieldController::actionDelete ( )

Deletes a particular model. If deletion is successful, the browser will be redirected to the 'index' page.

Definition at line 393 of file ProfileFieldController.php.

References loadModel(), and Profile\model().

{
/* row below was commented out to allow delete fields from GET requests too*/
//if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$scheme = get_class(Yii::app()->db->schema);
$model = $this->loadModel();
if ($scheme == 'CSqliteSchema') {
$attr = Profile::model()->attributes;
unset($attr[$model->varname]);
$attr = array_keys($attr);
$connection = Yii::app()->db;
$transaction = $connection->beginTransaction();
$status = true;
try {
$sql = '';
$connection->createCommand(
"CREATE TEMPORARY TABLE " . Profile::model()->tableName() . "_backup (" . implode(',', $attr) . ")"
)->execute();
$connection->createCommand(
"INSERT INTO " . Profile::model()->tableName() . "_backup SELECT " . implode(',', $attr) . " FROM " . Profile::model()->tableName()
)->execute();
$connection->createCommand(
"DROP TABLE " . Profile::model()->tableName()
)->execute();
$connection->createCommand(
"CREATE TABLE " . Profile::model()->tableName() . " (" . implode(',', $attr) . ")"
)->execute();
$connection->createCommand(
"INSERT INTO " . Profile::model()->tableName() . " SELECT " . implode(',', $attr) . " FROM " . Profile::model()->tableName() . "_backup"
)->execute();
$connection->createCommand(
"DROP TABLE " . Profile::model()->tableName() . "_backup"
)->execute();
$transaction->commit();
} catch (Exception $e) {
$transaction->rollBack();
$status = false;
}
if ($status) {
$model->delete();
}
} else {
$sql = 'ALTER TABLE ' . Profile::model()->tableName() . ' DROP `' . $model->varname . '`';
if ($model->dbConnection->createCommand($sql)->execute()) {
$model->delete();
}
}
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_POST['ajax'])) {
$this->redirect(array('admin'));
}
/* rows below were commented out to allow delete fields from GET requests too*/
//} else
// throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
ProfileFieldController::actionUpdate ( )

Updates a particular model. If update is successful, the browser will be redirected to the 'view' page.

Definition at line 374 of file ProfileFieldController.php.

References loadModel(), and registerScript().

{
$model = $this->loadModel();
if (isset($_POST['ProfileField'])) {
$model->attributes = $_POST['ProfileField'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->registerScript();
$this->render('update', array(
'model' => $model,
));
}
ProfileFieldController::actionView ( )

Displays a particular model.

Definition at line 48 of file ProfileFieldController.php.

References loadModel().

{
$this->render('view', array(
'model' => $this->loadModel(),
));
}
ProfileFieldController::afterAction (   $action)

Clear cache to load new db schema

Definition at line 57 of file ProfileFieldController.php.

{
Yii::app()->cache->flush();
}
ProfileFieldController::fieldType (   $type)

MySQL field type

Parameters
$typestring
Returns
string

Definition at line 497 of file ProfileFieldController.php.

Referenced by actionCreate().

{
$type = str_replace('UNIX-DATE', 'INTEGER', $type);
return $type;
}
ProfileFieldController::filters ( )
Returns
array action filters

Definition at line 16 of file ProfileFieldController.php.

{
return CMap::mergeArray(parent::filters(), array(
'accessControl', // perform access control for CRUD operations
));
}
ProfileFieldController::loadModel ( )

Returns the data model based on the primary key given in the GET variable. If the data model is not found, an HTTP exception will be raised.

Definition at line 481 of file ProfileFieldController.php.

References ProfileField\model().

Referenced by actionDelete(), actionUpdate(), and actionView().

{
if ($this->_model === null) {
if (isset($_GET['id']))
$this->_model = ProfileField::model()->findbyPk($_GET['id']);
if ($this->_model === null)
throw new CHttpException(404, 'The requested page does not exist.');
}
return $this->_model;
}
ProfileFieldController::registerScript ( )

Register Script

Definition at line 66 of file ProfileFieldController.php.

References UserModule\t().

Referenced by actionCreate(), and actionUpdate().

{
// $basePath=Yii::getPathOfAlias('application.modules.user.views.asset');
$basePath = Yii::app()->getModule('user')->getBasePath() . '/views/asset';
$baseUrl = Yii::app()->getModule('user')->getAssetsUrl();
$cs = Yii::app()->getClientScript();
$coreBaseUrl = $cs->getCoreScriptUrl();
$cs->registerCoreScript('jquery');
$cs->registerCssFile($coreBaseUrl . '/jui/css/base/jquery-ui.css', '', null, false);
$cs->registerCssFile($baseUrl . '/css/style.css');
$cs->registerScriptFile($coreBaseUrl . '/jui/js/jquery-ui.min.js');
$cs->registerScriptFile($baseUrl . '/js/form.js');
$cs->registerScriptFile($baseUrl . '/js/jquery.json.js');
$widgets = self::getWidgets();
$wgByTypes = ProfileField::itemAlias('field_type');
foreach ($wgByTypes as $k => $v) {
$wgByTypes[$k] = array();
}
foreach ($widgets[1] as $widget) {
if (isset($widget['fieldType']) && count($widget['fieldType'])) {
foreach ($widget['fieldType'] as $type) {
array_push($wgByTypes[$type], $widget['name']);
}
}
}
//echo '<pre>'; print_r($widgets[1]); die();
$js = "
var name = $('#name'),
value = $('#value'),
allFields = $([]).add(name).add(value),
tips = $('.validateTips');
var listWidgets = jQuery.parseJSON('" . str_replace("'", "\'", CJavaScript::jsonEncode($widgets[0])) . "');
var widgets = jQuery.parseJSON('" . str_replace("'", "\'", CJavaScript::jsonEncode($widgets[1])) . "');
var wgByType = jQuery.parseJSON('" . str_replace("'", "\'", CJavaScript::jsonEncode($wgByTypes)) . "');
var fieldType = {
'INTEGER':{
'hide':['match','other_validator','widgetparams'],
'val':{
'field_size':10,
'default':'0',
'range':'',
'widgetparams':''
}
},
'VARCHAR':{
'hide':['widgetparams'],
'val':{
'field_size':255,
'default':'',
'range':'',
'widgetparams':''
}
},
'TEXT':{
'hide':['field_size','range','widgetparams'],
'val':{
'field_size':0,
'default':'',
'range':'',
'widgetparams':''
}
},
'DATE':{
'hide':['field_size','field_size_min','match','range','widgetparams'],
'val':{
'field_size':0,
'default':'0000-00-00',
'range':'',
'widgetparams':''
}
},
'FLOAT':{
'hide':['match','other_validator','widgetparams'],
'val':{
'field_size':'10,2',
'default':'0.00',
'range':'',
'widgetparams':''
}
},
'BOOL':{
'hide':['field_size','field_size_min','match','widgetparams'],
'val':{
'field_size':0,
'default':0,
'range':'1==" . UserModule::t('Yes') . ";0==" . UserModule::t('No') . "',
'widgetparams':''
}
},
'BLOB':{
'hide':['field_size','field_size_min','match','widgetparams'],
'val':{
'field_size':0,
'default':'',
'range':'',
'widgetparams':''
}
},
'BINARY':{
'hide':['field_size','field_size_min','match','widgetparams'],
'val':{
'field_size':0,
'default':'',
'range':'',
'widgetparams':''
}
}
};
function showWidgetList(type) {
$('div.widget select').empty();
$('div.widget select').append('<option value=\"\">" . UserModule::t('No') . "</option>');
if (wgByType[type]) {
for (var k in wgByType[type]) {
$('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');
}
}
}
function setFields(type) {
if (fieldType[type]) {
if (" . ((isset($_GET['id'])) ? 0 : 1) . ") {
showWidgetList(type);
$('#widgetlist option:first').attr('selected', 'selected');
}
$('div.row').addClass('toshow').removeClass('tohide');
if (fieldType[type].hide.length) $('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');
if ($('div.widget select').val()) {
$('div.widgetparams').removeClass('tohide');
}
$('div.toshow').show(500);
$('div.tohide').hide(500);
" . ((!isset($_GET['id'])) ? "
for (var k in fieldType[type].val) {
$('div.'+k+' input').val(fieldType[type].val[k]);
}" : '') . "
}
}
function isArray(obj) {
if (obj.constructor.toString().indexOf('Array') == -1)
return false;
else
return true;
}
$('#dialog-form').dialog({
autoOpen: false,
height: 400,
width: 400,
modal: true,
buttons: {
'" . UserModule::t('Save') . "': function() {
var wparam = {};
var fparam = {};
$('#dialog-form fieldset .wparam').each(function(){
if ($(this).val()) wparam[$(this).attr('name')] = $(this).val();
});
var tab = $('#tabs ul li.ui-tabs-selected').text();
fparam[tab] = {};
$('#dialog-form fieldset .tab-'+tab).each(function(){
if ($(this).val()) fparam[tab][$(this).attr('name')] = $(this).val();
});
if ($.JSON.encode(wparam)!='{}') $('div.widgetparams input').val($.JSON.encode(wparam));
if ($.JSON.encode(fparam[tab])!='{}') $('div.other_validator input').val($.JSON.encode(fparam));
$(this).dialog('close');
},
'" . UserModule::t('Cancel') . "': function() {
$(this).dialog('close');
}
},
close: function() {
}
});
$('#widgetparams').focus(function() {
var widget = widgets[$('#widgetlist').val()];
var html = '';
var wparam = ($('div.widgetparams input').val())?$.JSON.decode($('div.widgetparams input').val()):{};
var fparam = ($('div.other_validator input').val())?$.JSON.decode($('div.other_validator input').val()):{};
// Class params
for (var k in widget.params) {
html += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';
html += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />';
}
// Validator params
if (widget.other_validator) {
var tabs = '';
var li = '';
for (var t in widget.other_validator) {
tabs += '<div id=\"tab-'+t+'\" class=\"tab\">';
li += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';
for (var k in widget.other_validator[t]) {
tabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';
if (isArray(widget.other_validator[t][k])) {
tabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';
for (var i in widget.other_validator[t][k]) {
tabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>';
}
tabs += '</select>';
} else {
tabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';
}
}
tabs += '</div>';
}
html += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';
}
$('#dialog-form fieldset').html(html);
$('#tabs').tabs();
// Show form
$('#dialog-form').dialog('open');
});
$('#field_type').change(function() {
setFields($(this).val());
});
$('#widgetlist').change(function() {
if ($(this).val()) {
$('div.widgetparams').show(500);
} else {
$('div.widgetparams').hide(500);
}
});
// show all function
$('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">" . UserModule::t('Show all') . "</a>');
$('#showAll').click(function(){
$('div.row').show(500);
return false;
});
// init
setFields($('#field_type').val());
";
$cs->registerScript(__CLASS__ . '#dialog', $js);
}

The documentation for this class was generated from the following file: