Пример #1
0
function main()
{
    DatabaseProvider::connect("app/config/database.json");
    BaseViewContextProvider::setProvider(function () {
        return ['count' => ['event' => (new EventModel())->count()['nb'], 'user' => (new UserModel())->count()['nb'], 'online' => (new LittleModel())->checkConnect()['COUNT(*)']], 'newmessages' => Authentication::getInstance()->isAuthenticated() ? (new ConversationModel())->countUnreadMessages() : 0];
    });
    $router = new \SwagFramework\Routing\Router();
    $classRouting = new ClassRouting('\\app\\controllers\\');
    $classRouting->addClass('User');
    $classRouting->addClass('Event');
    $classRouting->addClass('Article');
    $classRouting->addClass('Parteners');
    $classRouting->addClass('Search');
    if (Authentication::getInstance()->isAuthenticated()) {
        $classRouting->addClass('Conversation');
        if (Authentication::getInstance()->getOptionOr('accessLevel', 0)) {
            $classRouting->addClass('AdminUsers');
            $classRouting->addClass('AdminEvent');
            $classRouting->addClass('AdminComment');
            $classRouting->addClass('Admin');
        }
    }
    $classRouting->generateRoute($router);
    $router->add('/errors/err404', new \app\controllers\ErrorsController(), 'err404');
    $router->add('/', new \app\controllers\HomeController(), 'index');
    $router->matchCurrentRequest();
}
Пример #2
0
 public function commentPOST()
 {
     if (!Authentication::getInstance()->isAuthenticated()) {
         throw new NotAuthenticatedException();
     }
     $id = (int) $this->getParams()[0];
     $this->articleCommentModel->insertCommentArticle(Authentication::getInstance()->getUserId(), $id, Input::post('message'));
     $this->getView()->redirect('/article/show/' . $id);
 }
 public function createPOST()
 {
     $message = Input::post('message');
     $userModel = $this->loadModel('User');
     $participationIds = [];
     foreach (explode(', ', Input::post('participations')) as $participation) {
         $userId = $userModel->getUserFullNameLike($participation)['id'];
         $participationIds[] = (int) $userId;
     }
     if ($existingConversationId = $this->conversationModel->conversationExistsBetween($participationIds)) {
         $this->conversationModel->newMessage($existingConversationId, $message);
         $this->getView()->redirect('/conversation/show/' . $existingConversationId);
         die;
     }
     $newConversationId = $this->conversationModel->createConversation(Input::post('title'));
     foreach ($participationIds as $participationId) {
         $this->conversationModel->addUserToConversation($newConversationId, $participationId);
     }
     $this->conversationModel->addUserToConversation($newConversationId, Authentication::getInstance()->getUserId());
     $this->conversationModel->newMessage($newConversationId, $message);
     $this->getView()->redirect('/conversation/show/' . $newConversationId);
 }
Пример #4
0
 /**
  * @param int $year
  * @return array
  * @throws \SwagFramework\Exceptions\DatabaseConfigurationNotLoadedException
  */
 public function getEventsByYear($year)
 {
     $sql = 'SELECT event.id, name, eventtime FROM event ' . 'LEFT JOIN event_user ' . 'ON event_user.id = event.id ' . 'WHERE event.user = ? ' . 'AND YEAR(eventtime) = ? ' . 'OR event_user.user = ? ' . 'AND YEAR(eventtime)= ? ';
     $user = Authentication::getInstance()->getUserId();
     return DatabaseProvider::connection()->query($sql, array($user, $year, $user, $year));
 }
Пример #5
0
 public function myevent()
 {
     $model = $this->loadModel('Event');
     $myevent = $model->getEventsForUser(Authentication::getInstance()->getUserId());
     $this->getView()->render('user/myevent', ['events' => $myevent]);
 }
Пример #6
0
 public function countUnreadMessages()
 {
     return DatabaseProvider::connection()->selectFirst(self::COUNT_NEW_MESSAGES, [Authentication::getInstance()->getUserId()])['nb'];
 }
Пример #7
0
 public function getAllFriends()
 {
     if (Authentication::getInstance()->isAuthenticated()) {
         return DatabaseProvider::connection()->query(self::GET_ALL_FRIENDS, ['user1' => Authentication::getInstance()->getUserId(), 'user2' => Authentication::getInstance()->getUserId()]);
     }
     return [];
 }