/** * answering on request, accept or dismiss * * @param type $req_id * @param type $answer answer on request true or false. */ public static function answerRequest($req_id, $answer) { $user1_id = RequestService::getUser1Id($req_id); $user2_id = RequestService::getUser2Id($req_id); $uid1 = new UserId($user1_id); $uid2 = new UserId($user2_id); ///AccessService try { if (!AccessService::hasAccess($user2_id, ObjectCheckType::Request)) { \Yii::$app->session->setFlash('error', 'Access Denied'); return false; } } catch (Exception $ex) { Yii::$app->session->setFlash('warning', 'Something went wrong, contact Administrator'); return false; } ///end AccessService if ($answer) { RelationService::setRelation($uid1, $uid2, RelationType::Friend); RelationService::setRelation($uid1, $uid2, RelationType::Follower); // for default friend is followed RelationService::setRelation($uid2, $uid1, RelationType::Follower); EventService::createEvent(EEvent::FRIEND_REQUEST_ACCEPTED(), $uid2, true, $uid1); EventService::createEvent(EEvent::FRIEND_REQUEST_ACCEPTED(), $uid1, false, $uid2); } else { EventService::createEvent(EEvent::FRIEND_REQUEST_DENIED(), $uid2, true, $uid1); EventService::createEvent(EEvent::FRIEND_REQUEST_DENIED(), $uid1, false, $uid2); } self::dropRequest($req_id); //TODO Przemek popraw to! $check = Request::find()->select('req_id')->where(['user1_id' => $user2_id, 'user2_id' => $user1_id, 'req_type' => 'friend'])->one(); if (!is_null($check)) { self::dropRequest($check['req_id']); } }
/** * @param \common\components\Post $post * @param IntouchUser $author * @param $content * * @return \common\components\Comment */ public static function createComment(\common\components\Post $post, $content) { try { if (!AccessService::hasAccess($post->getAuthor()->getId(), ObjectCheckType::PostComment)) { Yii::$app->session->setFlash('error', 'Access Denied'); return false; } } catch (Exception $ex) { Yii::$app->session->setFlash('warning', 'Something went wrong, contact Administrator'); return false; } $comment = new Comment(); $author_id = Yii::$app->user->getId(); $comment->author_id = $author_id; $comment->comment_text = $content; $comment->comment_date = date('Y-m-d H:i:s'); $comment->post_id = $post->getId(); return $comment->save(); }