28 private static $_flatLists = array();
37 public static function model($className = __CLASS__)
49 return '{{personalisation_attributes}}';
62 array(
'name, title',
'required'),
63 array(
'name, title',
'common.components.NotContainsTagsValidator'),
64 array(
'name',
'unique'),
65 array(
'parent_id',
'numerical',
'integerOnly' =>
true),
66 array(
'name, title',
'length',
'max' => 255),
67 array(
'path',
'safe'),
70 array(
'id, parent_id, name',
'safe',
'on' =>
'search'),
83 $this->parent_id = $parent->id;
84 $this->path = empty($parent->path) ?
'.' . $parent->id .
'.' : $parent->path . $parent->id .
'.';
104 $data = Yii::app()->db->createCommand()
107 ->where(
"path LIKE '%.{$this->id}.%'")
129 array(self::HAS_MANY,
'UserPersonalisationAttribute',
'personalisation_attribute_id')
142 'parent_id' =>
'Parent',
157 $criteria =
new CDbCriteria;
159 $criteria->compare(
'id', $this->
id);
160 $criteria->compare(
'parent_id', $this->parent_id);
161 $criteria->compare(
'name', $this->name,
true);
163 return new CActiveDataProvider(
166 'criteria' => $criteria,
176 public function delete()
178 $transaction = Yii::app()->db->beginTransaction();
181 if (!empty($removeIds)) {
184 $removeIds[] = $this->id;
187 $transaction->commit();
189 }
catch (Exception $e) {
190 $transaction->rollback();
206 if (!empty($userId)) {
207 if (isset(self::$_flatLists[$userId])) {
208 $flatList = self::$_flatLists[$userId];
209 Yii::trace(
'Flatlist for userId='.$userId.
' taken from inclass cache');
212 ->cache($cache ? Yii::app()->getModule(
'personalisation')->cacheTime : 0)
213 ->with(
'personalisationAttribute')
214 ->findAllByAttributes(array(
'user_id' => $userId));
215 if ($userPersAttributes) {
216 foreach ($userPersAttributes as $attr) {
217 $flatList[] = $attr->personalisationAttribute->name;
220 Yii::trace(
'Flatlist for userId='.$userId.
' was put to inclass cache');
221 self::$_flatLists[$userId] = $flatList;
243 $tree = array(
'id' => 0,
'item' => array());
245 foreach ($personalisationAttributes as $attr) {
248 'text' => $attr->title,
250 array(
'name' =>
'name',
'content' => $attr->name),
251 array(
'name' =>
'title',
'content' => $attr->title)
255 if ($attr->parent_id === null) {
256 $tree[
'item'][] = $node;
258 $parent = &self::_findNode($tree, $attr->parent_id);
259 $parent[
'item'][] = $node;
277 foreach ($userPAttributes as $pAttr) {
278 $node = &self::_findNode($tree, $pAttr->personalisation_attribute_id);
279 $node[
'checked'] = 1;
292 private static function &_findNode(&$node, $id)
294 if ($node[
'id'] == $id) {
297 foreach ($node[
'item'] as &$item) {
298 $res = &self::_findNode($item, $id);