public static function getUserEvents(UserId $uid, $sort = true) { if ($sort) { $e = Event::find()->where(['event_owner' => $uid->getId()])->orderBy(['date' => SORT_DESC])->all(); } else { $e = Event::findAll(['event_owner' => $uid->getId()]); } $events = []; foreach ($e as $event) { $type = EEvent::search($event->event_type); $uconnected = $event->event_user_connected == null ? null : new UserId($event->event_user_connected); $ev = new UserEvent($event->event_id, EEvent::$type(), $uid, new \DateTime($event->date), $uconnected, $event->event_data_connected); $events[] = $ev; } return $events; }
/** * @param UserId $uid * @param ETokenType $type */ public static function getUserTokensByType(UserId $uid, ETokenType $type) { $tokens = []; $tkns = UserTokens::findAll(['user_id' => $uid->getId(), 'token_type' => $type->getValue()]); foreach ($tkns as $var) { $tokenType = ETokenType::search($var->token_type); $token = new Token($var->token, ETokenType::$tokenType(), new UserId($var->user_id), $var->token_expiration_date); $tokens[] = $token; } return $tokens; }
public static function createPost(UserId $receiverId, $text) { $author_id = Yii::$app->user->getId(); $receiver_id = $receiverId->getId(); try { if (!AccessService::hasAccess($receiver_id, ObjectCheckType::Post)) { Yii::$app->session->setFlash('error', 'Access Denied'); return false; } } catch (Exception $ex) { Yii::$app->session->setFlash('warning', 'Something went wrong, contact Administrator'); return false; } $post = new Post(); $post->owner_id = $author_id; $post->user_id = $receiver_id; $post->post_text = $text; $post->post_date = date('Y-m-d H:i:s'); $post->post_type = EPostType::text; $post->post_visibility = "visible"; if ($post->save()) { return $post->post_id; } else { return false; } }
public static function isRequestBetween(UserId $user1_id, UserId $user2_id, $req_type) { if (!RequestType::isValid($req_type)) { throw new InvalidEnumKeyException("Value: " . $req_type); } return Request::find()->where(['user1_id' => $user1_id->getId(), 'user2_id' => $user2_id->getId()])->orWhere(['user1_id' => $user2_id->getId(), 'user2_id' => $user1_id->getId()])->exists(); }
public static function isUserAccountActivated(UserId $uid) { $user = User::findOne(['id' => $uid->getId()]); return $user->status == EAccountStatus::STATUS_ACTIVE && $user->status != EAccountStatus::STATUS_NOTACTIVATED; }
/** * Do not use that function (Only for setRelation purposes) */ private static function saveRelation(UserId $user1_id, UserId $user2_id, $rel_type) { $relation = new Relationship(); $relation->user1_id = $user1_id->getId(); $relation->user2_id = $user2_id->getId(); $relation->relation_type = $rel_type; if ($relation->save()) { return true; } else { return false; } }