Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/favorites/favorites_eh.php
Show All 36 Lines | |||||
/** | /** | ||||
* Adds/removes item from favorites | * Adds/removes item from favorites | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnFavoriteToggle($event) | function OnFavoriteToggle($event) | ||||
{ | { | ||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
/** @var kDBItem $parent_object */ | |||||
$parent_object = $this->Application->recallObject($parent_prefix); | $parent_object = $this->Application->recallObject($parent_prefix); | ||||
/* @var $parent_object kDBItem */ | |||||
if (!$parent_object->isLoaded() || !$this->Application->CheckPermission('FAVORITES', 0, $parent_object->GetDBField('ParentPath'))) { | if (!$parent_object->isLoaded() || !$this->Application->CheckPermission('FAVORITES', 0, $parent_object->GetDBField('ParentPath'))) { | ||||
$event->status = kEvent::erPERM_FAIL; | $event->status = kEvent::erPERM_FAIL; | ||||
return ; | return ; | ||||
} | } | ||||
$user_id = $this->Application->RecallVar('user_id'); | $user_id = $this->Application->RecallVar('user_id'); | ||||
$sql = 'SELECT FavoriteId | $sql = 'SELECT FavoriteId | ||||
FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' | FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' | ||||
WHERE (PortalUserId = '.$user_id.') AND (ResourceId = '.$parent_object->GetDBField('ResourceId').')'; | WHERE (PortalUserId = '.$user_id.') AND (ResourceId = '.$parent_object->GetDBField('ResourceId').')'; | ||||
$favorite_id = $this->Conn->GetOne($sql); | $favorite_id = $this->Conn->GetOne($sql); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(Array('skip_autoload' => true)); | $object = $event->getObject(Array('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
if ($favorite_id) { | if ($favorite_id) { | ||||
$object->Delete($favorite_id); | $object->Delete($favorite_id); | ||||
} | } | ||||
else { | else { | ||||
$object->Create(); | $object->Create(); | ||||
} | } | ||||
$event->SetRedirectParam('pass', 'm,'.$parent_prefix); | $event->SetRedirectParam('pass', 'm,'.$parent_prefix); | ||||
} | } | ||||
/** | /** | ||||
* Prepares Favorite record fields | * Prepares Favorite record fields | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemCreate(kEvent $event) | protected function OnBeforeItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemCreate($event); | parent::OnBeforeItemCreate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$user_id = $this->Application->RecallVar('user_id'); | $user_id = $this->Application->RecallVar('user_id'); | ||||
$object->SetDBField('PortalUserId', $user_id); | $object->SetDBField('PortalUserId', $user_id); | ||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
/** @var kDBItem $parent_object */ | |||||
$parent_object = $this->Application->recallObject($parent_prefix); | $parent_object = $this->Application->recallObject($parent_prefix); | ||||
/* @var $parent_object kDBItem */ | |||||
$object->SetDBField('ResourceId', $parent_object->GetDBField('ResourceId')); | $object->SetDBField('ResourceId', $parent_object->GetDBField('ResourceId')); | ||||
$object->SetDBField('ItemTypeId', $this->Application->getUnitOption($parent_prefix, 'ItemType')); | $object->SetDBField('ItemTypeId', $this->Application->getUnitOption($parent_prefix, 'ItemType')); | ||||
} | } | ||||
/** | /** | ||||
* [HOOK] Deletes favorite record to item, that is beeing deleted | * [HOOK] Deletes favorite record to item, that is beeing deleted | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnDeleteFavoriteItem($event) | function OnDeleteFavoriteItem($event) | ||||
{ | { | ||||
$main_object = $event->MasterEvent->getObject(); | $main_object = $event->MasterEvent->getObject(); | ||||
$sql = 'DELETE FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' | $sql = 'DELETE FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' | ||||
WHERE ResourceId = '.$main_object->GetDBField('ResourceId'); | WHERE ResourceId = '.$main_object->GetDBField('ResourceId'); | ||||
$this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |