Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | List of all members
PersonalisationAttribute Class Reference

Public Member Functions

 tableName ()
 rules ()
 childOf (PersonalisationAttribute $parent)
 getChildren ()
 getChildrenIds ()
 relations ()
 attributeLabels ()
 search ()
 delete ()

Static Public Member Functions

static model ($className=__CLASS__)
static flatListForUser ($userId, $cache=true)
static getTree ()
static getTreeWithUserState ($userId)

Detailed Description

Definition at line 22 of file PersonalisationAttribute.php.

Member Function Documentation

PersonalisationAttribute::attributeLabels ( )

Returns customized attribute labels (name=>label)

Returns
array

Definition at line 138 of file PersonalisationAttribute.php.

{
return array(
'id' => 'ID',
'parent_id' => 'Parent',
'name' => 'Name',
);
}
PersonalisationAttribute::childOf ( PersonalisationAttribute  $parent)

sets id of parent

Parameters
\PersonalisationAttribute$parent
Returns
void

Definition at line 81 of file PersonalisationAttribute.php.

{
$this->parent_id = $parent->id;
$this->path = empty($parent->path) ? '.' . $parent->id . '.' : $parent->path . $parent->id . '.';
}
PersonalisationAttribute::delete ( )

Delete personalisation attribute with children and UserPersonalisationAttribute records

Returns
bool

Definition at line 176 of file PersonalisationAttribute.php.

References getChildrenIds(), and model().

{
$transaction = Yii::app()->db->beginTransaction();
try {
$removeIds = $this->getChildrenIds();
if (!empty($removeIds)) {
PersonalisationAttribute::model()->deleteAll('id IN (' . implode(',', $removeIds) . ')');
}
$removeIds[] = $this->id;
UserPersonalisationAttribute::model()->deleteAll('personalisation_attribute_id IN (' . implode(',', $removeIds) . ')');
$result = parent::delete();
$transaction->commit();
return $result;
} catch (Exception $e) {
$transaction->rollback();
return false;
}
}
static PersonalisationAttribute::flatListForUser (   $userId,
  $cache = true 
)
static

Get personalisation attributes for user in flat list form

Parameters
int$userIduser id
bool$cachedefines if rrsult should be cached
Returns
array

Definition at line 203 of file PersonalisationAttribute.php.

References model().

Referenced by UserIdentity\authenticate(), SUserIdentity\authenticate(), BasicPersonalisationRule\checkAccess(), and NavigationWidget\createCacheKey().

{
$flatList = array();
if (!empty($userId)) {
if (isset(self::$_flatLists[$userId])) {
$flatList = self::$_flatLists[$userId];
Yii::trace('Flatlist for userId='.$userId.' taken from inclass cache');
} else {
$userPersAttributes = UserPersonalisationAttribute::model()
->cache($cache ? Yii::app()->getModule('personalisation')->cacheTime : 0)
->with('personalisationAttribute')
->findAllByAttributes(array('user_id' => $userId));
if ($userPersAttributes) {
foreach ($userPersAttributes as $attr) {
$flatList[] = $attr->personalisationAttribute->name;
}
}
Yii::trace('Flatlist for userId='.$userId.' was put to inclass cache');
self::$_flatLists[$userId] = $flatList;
}
}
return $flatList;
}
PersonalisationAttribute::getChildren ( )

Find all children of current personalisation attribute

Returns
array

Definition at line 92 of file PersonalisationAttribute.php.

References model().

{
return PersonalisationAttribute::model()->findAll("path LIKE '%.{$this->id}.%'");
}
PersonalisationAttribute::getChildrenIds ( )

Get children ids

Returns
array

Definition at line 102 of file PersonalisationAttribute.php.

References tableName().

Referenced by delete().

{
$data = Yii::app()->db->createCommand()
->select('id')
->from($this->tableName())
->where("path LIKE '%.{$this->id}.%'")
->queryAll(false);
$ids = array_map(
function($item)
{
return $item[0];
}, $data
);
return $ids;
}
static PersonalisationAttribute::getTree ( )
static

Get associative array which represents all existed personalisation attributes in tree structure

Returns
array

Definition at line 235 of file PersonalisationAttribute.php.

References model().

Referenced by PersonalisationAttributeHelper\getTreeJs(), and getTreeWithUserState().

{
$personalisationAttributes = PersonalisationAttribute::model()->findAll(
array(
'order'=>'path ASC,
title ASC'
)
);
$tree = array('id' => 0, 'item' => array());
foreach ($personalisationAttributes as $attr) {
$node = array(
'id' => $attr->id,
'text' => $attr->title,
'userdata' => array(
array('name' => 'name', 'content' => $attr->name),
array('name' => 'title', 'content' => $attr->title)
),
'item' => array()
);
if ($attr->parent_id === null) {
$tree['item'][] = $node;
} else {
$parent = &self::_findNode($tree, $attr->parent_id);
$parent['item'][] = $node;
}
}
return $tree;
}
static PersonalisationAttribute::getTreeWithUserState (   $userId)
static

Get personalisation attributes tree with user state

Parameters
integer$userIdid uf user
Returns
array

Definition at line 273 of file PersonalisationAttribute.php.

References getTree(), and model().

Referenced by PersonalisationAttributeHelper\getTreeWithUserStateJs().

{
$tree = self::getTree();
$userPAttributes = UserPersonalisationAttribute::model()->findAllByAttributes(array('user_id' => $userId));
foreach ($userPAttributes as $pAttr) {
$node = &self::_findNode($tree, $pAttr->personalisation_attribute_id);
$node['checked'] = 1;
}
return $tree;
}
static PersonalisationAttribute::model (   $className = __CLASS__)
static

Returns the static model of the specified AR class.

Parameters
string$classNameactive record class name.
Returns
PersonalisationAttribute the static model class

Definition at line 37 of file PersonalisationAttribute.php.

Referenced by ManageController\actionDeleteAttribute(), ManageController\actionSaveAttribute(), ManageController\actionUpdateUserAttribute(), delete(), flatListForUser(), getChildren(), getTree(), and getTreeWithUserState().

{
return parent::model($className);
}
PersonalisationAttribute::relations ( )

returns relations rules

Returns
array relational rules.

Definition at line 124 of file PersonalisationAttribute.php.

{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
array(self::HAS_MANY, 'UserPersonalisationAttribute', 'personalisation_attribute_id')
);
}
array $_flatLists inclass cache for personalisation flat PersonalisationAttribute::rules ( )

returns validation rules

Returns
array validation rules for model attributes.

Definition at line 57 of file PersonalisationAttribute.php.

{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, title', 'required'),
array('name, title', 'common.components.NotContainsTagsValidator'),
array('name', 'unique'),
array('parent_id', 'numerical', 'integerOnly' => true),
array('name, title', 'length', 'max' => 255),
array('path', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, parent_id, name', 'safe', 'on' => 'search'),
);
}
PersonalisationAttribute::search ( )

Retrieves a list of models based on the current search/filter conditions.

Returns
the data provider that can return the models based on the search/filter conditions.

Definition at line 152 of file PersonalisationAttribute.php.

{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('parent_id', $this->parent_id);
$criteria->compare('name', $this->name, true);
return new CActiveDataProvider(
$this,
array(
'criteria' => $criteria,
)
);
}
PersonalisationAttribute::tableName ( )

returnes a table name

Returns
string the associated database table name

Definition at line 47 of file PersonalisationAttribute.php.

Referenced by getChildrenIds().

{
return '{{personalisation_attributes}}';
}

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