コード例 #1
0
ファイル: UserPresenter.php プロジェクト: subbly/framework
 /**
  * Get formated datas for a single entry.
  *
  * @param \Subbly\Model\User $user
  *
  * @return array
  */
 public function single($user)
 {
     $entry = new Entry($user);
     $entry->conditionalField('id', function () {
         return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth');
     })->field('uid')->field('email')->field('firstname')->field('lastname')->compositeField('displayName', 'firstname', 'lastname')->relationshipField('addresses', 'Subbly\\Presenter\\V1\\UserAddressPresenter')->integer('orders_total', $user->countOrders())->relationshipField('orders', 'Subbly\\Presenter\\V1\\OrderPresenter')->relationshipField('groups', 'Subbly\\Presenter\\V1\\GroupPresenter')->dateField('last_login')->dateField('created_at')->dateField('updated_at');
     return $entry->toArray();
 }
コード例 #2
0
 public function testIndex()
 {
     $response = $this->callJSON('GET', '/api/v1/users');
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONCollectionResponse('users');
     $this->assertJSONTypes('users[0]', $this->userJSONFormat);
     $this->assertEquals(0, $json->response->offset);
     $this->assertEquals(User::count(), $json->response->total);
 }
コード例 #3
0
ファイル: UserTableSeeder.php プロジェクト: subbly/framework
 public function run()
 {
     $faker = TestCase::faker();
     $user = User::create(array('email' => '*****@*****.**', 'password' => 'hodor123', 'firstname' => 'Jon', 'lastname' => 'Snow', 'activated' => true));
     TestCase::addFixture('users.jon_snow', $user);
     // generate some others users
     for ($i = 1; $i <= 10; $i++) {
         $user = User::create(array('email' => $faker->email, 'password' => $faker->password(), 'firstname' => $faker->firstName, 'lastname' => $faker->lastName, 'activated' => $i === 0 ? true : rand(0, 1)));
         TestCase::addFixture('users.user_' . $i, $user);
     }
 }
コード例 #4
0
ファイル: UserService.php プロジェクト: subbly/framework
 /**
  * Count user's orders.
  *
  * @param User|string $user The user_uid or the user model
  *
  * @return User
  *
  * @pi
  */
 public function countOrders($user)
 {
     if ($user instanceof User) {
         return $user->countOrders();
     }
 }
コード例 #5
0
ファイル: UserService.php プロジェクト: subbly/cms
 /**
  * Create a new User
  *
  * @example
  *     $user = Subbly\Model\User;
  *     Subbly::api('subbly.user')->create($user);
  *
  *     Subbly::api('subbly.user')->create(array(
  *         'firstname' => 'Jon',
  *         'lastname'  => 'Snow',
  *     ));
  *
  * @param User|array $user
  *
  * @return User
  *
  * @throws \Subbly\Api\Service\Exception
  *
  * @api
  */
 public function create($user)
 {
     if (is_array($user)) {
         $user = new User($user);
     }
     if ($user instanceof User) {
         if ($this->fireEvent('creating', array($user)) === false) {
             return false;
         }
         $user->setCaller($this);
         $user->save();
         $this->fireEvent('created', array($user));
         $user = $this->find($user->uid);
         return $user;
     }
     throw new Exception(sprintf(Exception::CANT_CREATE_MODEL, $this->modelClass, $this->name()));
 }