/** * create * * @param UserInterface $user user * @param array $data data * * @return EmailInterface */ public function create(UserInterface $user, array $data) { if (empty($data['confirmationCode'])) { $data['confirmationCode'] = str_random(); } $email = $this->createModel()->create($data); $user->pendingEmail()->save($email); return $email; }
/** * update * * @param UserInterface $user user * @param array $data data * * @return UserInterface */ public function update(UserInterface $user, array $data = []) { if ($user->isDirty('password') || !empty($data['password']) && $user->password !== $data['password']) { $model = $this->createModel(); $data['passwordUpdatedAt'] = $model->freshTimestamp(); } $user->update($data); return $user; }
/** * 회원의 프로필 이미지를 등록한다. * * @param UserInterface $user 프로필 이미지를 등록할 회원 * @param UploadedFile $profileFile 프로필 이미지 파일 * * @return string 등록한 프로필이미지 ID */ public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile) { $disk = array_get($this->profileImgConfig, 'storage.disk'); $path = array_get($this->profileImgConfig, 'storage.path'); $size = array_get($this->profileImgConfig, 'size'); // make fitted image /** @var ImageManager $imageManager */ $imageManager = call_user_func($this->imageManagerResolver); $image = $imageManager->make($profileFile->getRealPath()); $image = $image->fit($size['width'], $size['height']); // remove old profile image if (!empty($user->profileImageId)) { $file = File::find($user->profileImageId); if ($file !== null) { try { $this->storage->remove($file); } catch (\Exception $e) { } } } // save image to storage $id = $user->getId(); $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk); return $file->id; }
/** * get log by name * 옵션을 사용하는 Counter 에서 로그를 확인 할 때 * 등록된 옵션은 제외하고 확인하려고 할 수 있음 * * @param string $targetId target id * @param UserInterface|null $user user instance * @return CounterLog|null */ public function getByName($targetId, UserInterface $user = null) { if ($this->guest == true && ($user == null || $user instanceof Guest)) { return $this->newModel()->where('targetId', $targetId)->where('ipaddress', $this->request->ip())->where('counterName', $this->name)->first(); } else { return $this->newModel()->where('targetId', $targetId)->where('userId', $user->getId())->where('counterName', $this->name)->first(); } }
/** * except User * * @param UserInterface $user user * * @return static */ public function exceptUser(UserInterface $user) { $this->users()->detach($user->getId()); $this->decrement('count'); return $this; }
/** * User 가 속한 그룹이 권한이 있는지 판별. * * @param UserInterface $user user instance * @param array $criterion criterion group ids * @return bool */ protected function groupInspect(UserInterface $user, $criterion) { $groups = $user->getGroups(); foreach ($groups as $group) { if (in_array($group->id, $criterion)) { return true; } } return false; }
/** * create * * @param UserInterface $user user * @param array $data data * * @return AccountInterface */ public function create(UserInterface $user, array $data) { $account = $this->createModel()->create($data); $user->accounts()->save($account); return $account; }
/** * 게시판에 글 등록 시 핸들러를 통해서 처리 * Interception 을 통해 다양한 서드파티 기능이 추가될 수 있다. * * @param array $args arguments * @param UserInterface $user * @return Board */ public function add(array $args, UserInterface $user, ConfigEntity $config) { $model = $this->getModel($config); $model->getConnection()->beginTransaction(); $args['type'] = BoardModule::getId(); $args['userId'] = $user->getId(); if ($args['userId'] === null) { $args['userId'] = ''; } if (empty($args['writer'])) { $args['writer'] = $user->getDisplayName(); } if ($user instanceof Guest) { $args['userType'] = Board::USER_TYPE_GUEST; } if ($config->get('anonymity') === true) { $args['writer'] = $config->get('anonymityName'); $args['userType'] = Board::USER_TYPE_ANONYMITY; } // save Document $doc = $this->documentHandler->add($args); $model = $this->getModel($config); $board = $model->find($doc->id); $this->setModelConfig($board, $config); $this->saveSlug($board, $args); $this->saveCategory($board, $args); $this->setFiles($board, $args); $this->setTags($board, $args); $this->saveData($board, $args); $model->getConnection()->commit(); return $board; }
/** * 신고 여부 * * @param string $targetId targetId * @param UserInterface $author user instance * @return bool */ public function has($targetId, UserInterface $author) { return ClaimLog::where('userId', $author->getId())->where('targetId', $targetId)->where('claimType', $this->claimType)->first() !== null; }
/** * create * * @param UserInterface $user user * @param array $data data * * @return EmailInterface */ public function create(UserInterface $user, array $data) { $email = $this->createModel()->create($data); $user->emails()->save($email); return $email; }