public function acceptWink($params) { $partnerId = OW::getUser()->getId(); if (!$partnerId) { throw new ApiResponseErrorException(); } if (empty($params['userId'])) { throw new ApiResponseErrorException(); } $service = WINKS_BOL_Service::getInstance(); $userId = $params['userId']; /** * @var WINKS_BOL_Winks $wink */ $wink = $service->findWinkByUserIdAndPartnerId($userId, $partnerId); if (empty($wink)) { throw new ApiResponseErrorException(); } $wink->setStatus(WINKS_BOL_WinksDao::STATUS_ACCEPT); WINKS_BOL_WinksDao::getInstance()->save($wink); if (($_wink = $service->findWinkByUserIdAndPartnerId($partnerId, $userId)) !== NULL) { $_wink->setStatus(WINKS_BOL_WinksDao::STATUS_IGNORE); WINKS_BOL_WinksDao::getInstance()->save($_wink); } $params = array('userId' => $userId, 'partnerId' => $partnerId, 'content' => array('entityType' => 'wink', 'eventName' => 'renderWink', 'params' => array('winkId' => $wink->id, 'winkBackEnabled' => 1))); $event = new OW_Event('winks.onAcceptWink', $params); OW::getEventManager()->trigger($event); $data = $event->getData(); if (!empty($data['conversationId'])) { $wink->setConversationId($data['conversationId']); WINKS_BOL_WinksDao::getInstance()->save($wink); } $this->assign('result', true); }
private function ignoreWink($userId, $partnerId) { if (($wink = $this->service->findWinkByUserIdAndPartnerId($userId, $partnerId)) === NULL) { return array('result' => FALSE, 'msg' => OW::getLanguage()->text('winks', 'wink_sent_error')); } $wink->setStatus(WINKS_BOL_WinksDao::STATUS_IGNORE); WINKS_BOL_WinksDao::getInstance()->save($wink); $event = new OW_Event('winks.onIgnoreWink', array('userId' => $userId, 'partnerId' => $partnerId)); OW::getEventManager()->trigger($event); return array('result' => TRUE); }
public function getIsWinkSent(OW_Event $event) { $params = $event->getParams(); if (empty($params['userId']) || empty($params['partnerId'])) { return; } $userId = (int) $params['userId']; $partnerId = (int) $params['partnerId']; $wink = WINKS_BOL_WinksDao::getInstance()->findByUserIdAndPartnerId($userId, $partnerId); if ($wink === NULL || $wink->getStatus() == WINKS_BOL_WinksDao::STATUS_ACCEPT) { return FALSE; } return TRUE; }
private function __construct() { $this->winksDao = WINKS_BOL_WinksDao::getInstance(); }