-
Notifications
You must be signed in to change notification settings - Fork 39
/
Component.php
69 lines (65 loc) · 2.82 KB
/
Component.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class Kwc_Favourites_Component extends Kwc_Abstract
{
const LINK_TYPE_GRAPHICAL = 'graphical';
const LINK_TYPE_TEXTUAL = 'textual';
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['assets']['dep'][] = 'KwfSwitchHoverFade';
$ret['placeholder']['saveFavourite'] = trlKwfStatic('save as favourite');
$ret['placeholder']['deleteFavourite'] = trlKwfStatic('delete favourite');
$ret['favouritesModel'] = 'Kwc_Favourites_Model';
$ret['linkType'] = self::LINK_TYPE_GRAPHICAL;
return $ret;
}
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$ret['favouriteText'] = $this->_getPlaceholder('saveFavourite');
$ret['config'] = array(
'componentId' => $this->getData()->componentId,
'controllerUrl' => Kwc_Admin::getInstance($this->getData()->componentClass)->getControllerUrl(),
'deleteFavourite' => $this->_getPlaceholder('deleteFavourite'),
'saveFavourite' => $this->_getPlaceholder('saveFavourite')
);
$ret['linkType'] = $this->_getSetting('linkType');
if ($ret['linkType'] == self::LINK_TYPE_GRAPHICAL) {
$ret['rootElementClass'] .= ' kwfSwitchHoverFade';
}
return $ret;
}
/**
* returns a list of all visible favourite componentIds
*/
public static function getFavouriteComponentIds($favouritesModel)
{
$ret = array();
$userId = Kwf_Registry::get('userModel')->getAuthedUserId();
if ($userId) {
$cacheIdUser = 'favCIds'.$userId;
$ret = Kwf_Cache_Simple::fetch($cacheIdUser, $success);
if (!$success) {
// get all favourites related to user
$select = new Kwf_Model_Select();
$select->whereEquals('user_id', $userId);
$favouritesModel = Kwf_Model_Abstract::getInstance($favouritesModel);
$favourites = $favouritesModel->getRows($select);
$componentIds = array();
foreach ($favourites as $favourite) {
$component = Kwf_Component_Data_Root::getInstance()
->getComponentById($favourite->component_id);
// check if component is visible and existent
if ($component) {
// if component is visible create list of users related to component
$componentIds[] = $component->componentId;
}
}
// cache relation of visible components to user
Kwf_Cache_Simple::add($cacheIdUser, $componentIds);
$ret = $componentIds;
}
}
return $ret;
}
}