/**
* 게시판에 글 등록 시 핸들러를 통해서 처리
* 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;
}