Exemple #1
0
 public function replace($content = '')
 {
     if (empty($this->name)) {
         throw new Exception('Blog post needs name before it can be saved');
     }
     $bean = $this->_bean;
     if ($bean === null) {
         $this->_bean = $bean = R::dispense('blog');
     }
     $bean->name = $this->name;
     $this->content = $bean->content = $content;
     $bean->edited = R::isoDateTime();
     $bean->created = $this->created ?: R::isoDateTime();
     $otherUserBean = App::user()->bean();
     $bean->user = $this->_user !== null ? $this->_user->bean() : $otherUserBean;
     $this->contributorIds[] = $otherUserBean->getID();
     $this->contributorIds = array_unique($this->contributorIds);
     $bean->contributorIds = implode(',', $this->contributorIds);
     if (!empty($this->publishedOn)) {
         $bean->publishedOn = R::isoDateTime($this->publishedOn);
     } else {
         $bean->publishedOn = null;
     }
     R::store($bean);
 }
Exemple #2
0
 public function addSharedUser(User $user)
 {
     $bean = $this->bean();
     if ($bean === null) {
         return $this;
     }
     $bean->sharedUserList[] = $user->bean();
     return $this;
 }
Exemple #3
0
 public static function getByEmailAndPassword($email, $password)
 {
     $user = new User($email);
     $bean = $user->bean();
     if ($bean !== null) {
         if (password_verify($password, $bean->password)) {
             return $user;
         }
     }
     return null;
 }
Exemple #4
0
    /**
     * @param User $user
     * @param bool|false $showAll
     * @return Post|null
     */
    public static function userMostRecentPost(User $user, $showAll = false)
    {
        $bean = R::findOne('blog', '
			where
				user_id = :user_id
				and (
					true = :show_all
					or date(published_on) >= now()
				)
			order by created limit 0, 1', ['user_id' => $user->bean()->getID(), 'show_all' => $showAll]);
        if ($bean !== null) {
            return new Post($bean->name, $bean);
        }
        return null;
    }
Exemple #5
0
<?php

use Enpowi\Users\User;
$tf->test('Adding a user', function (\Testify\Testify $tf) {
    $email = '*****@*****.**';
    User::create($email, '123123123');
    $user = new User($email);
    $tf->assertTrue($user->bean() !== null);
});
$tf->test('Removing a user', function (\Testify\Testify $tf) {
    $email = '*****@*****.**';
    User::create($email, '123123123');
    (new User($email))->remove();
    $user = new User($email);
    $tf->assertTrue($user->bean() === null);
});
Exemple #6
0
 public function removeUser(User $user)
 {
     $userBean = $user->bean();
     $groupBean = $this->_bean;
     if ($groupBean !== null && $user !== null) {
         if (!$groupBean->isDefaultRegistered && !$groupBean->isDefaultAnonymous && !$groupBean->isEveryone) {
             unset($userBean->sharedGroupList[$groupBean->getID()]);
             R::store($userBean);
             $user->updateGroups();
         }
         return false;
     }
     return true;
 }