* Xpressengine\Database 의 ProxyManager 에 DatabaseProxy 를 등록
* ProxyManager 의 인터페이스를 이용해서 DynamicField 데이터 처리
* DynamicFieldHandler 를 이용해 인스턴스 관리
## app binding
* xe.dynamicField 로 바인딩 되어 있음
* DynamicField facade 제공
## 사용법
Xpressengine\Database 패키지에서 처리하기 위해 ProxyInterface 를 사용함
### $group
* DynamicField 를 생성할 때 사용 한 별칭
* DynamicField 는 Table 단위로 관리되지 않음
* DynamicField 는 instance 별로 관리될 수 있음
### 관리자 Section
* App\Sections\DynamicFieldSection 을 이용해서 설정
### DynamicField 출력
* Document 에 추가된 Dynamic field 를 blade 에서 출력
```php
/** * make join query for revision * * @param array $configs config entity list * @param DynamicQuery $query Illuminate query builder * @return DynamicQuery */ public function join(array $configs, DynamicQuery $query) { $register = $this->handler->getRegisterHandler(); /** * @var ConfigEntity $config */ foreach ($configs as $config) { $type = $register->getType($this->handler, $config->get('typeId')); $type->setConfig($config); $query = $type->joinRevision($query); } return $query; }
/** * $query 에 join 된 쿼리를 리턴 * * @param Builder $query query builder * @return Builder */ public function joinRevision(Builder $query) { $config = $this->config; $tableName = $query->from; $table = $this->handler->getConfigHandler()->getRevisionTableName($config); $query->leftJoin($table, function (JoinClause $join) use($tableName, $table, $config) { $join->on(sprintf('%s.%s', $tableName, $config->get('joinColumnName')), '=', sprintf('%s.dynamicFieldTargetId', $table))->on(sprintf('%s.revisionId', $tableName), '=', sprintf('%s.revisionId', $table)); }); return $query; }
/** * set database connection and options * Dynamic field 는 'id', 'group' 옵션을 갖는다. * 'id' 는 instance id 와 같이 테이블 기준이 아니라 인스턴스 기준으로 * DynamicField 를 사용해야할 때 설정한다.(예: document, comment) * 'group' 은 별도의 명칭을 만들어 사용하고자 할 경우 설정 * * @param VirtualConnectionInterface $conn database connection * @param array $options options * @return void */ public function set(VirtualConnectionInterface $conn, array $options) { $this->handler->setConnection($conn); $this->options = $options; if (isset($this->options['table']) == false) { throw new Exceptions\InvalidOptionException(); } $this->group = $this->options['table']; if (isset($this->options['id'])) { $this->group = $this->options['table'] . '_' . $this->options['id']; } if (isset($this->options['group'])) { $this->group = $this->options['group']; } }
/** * 게시판 제거 * * @param string $boardId board id * @return void */ public function destroy($boardId) { $config = $this->configHandler->get($boardId); if ($config === null) { throw new Exceptions\InvalidConfigException(); } $this->conn->beginTransaction(); // get document config $this->document->destroyInstance($boardId); $this->comment->drop($boardId); // remove board config $this->configHandler->remove($config); // 연결된 df 제거 foreach ($this->configHandler->getDynamicFields($config) as $config) { $this->dynamicField->drop($config); } $this->conn->commit(); }
/** * test get type * * @return void */ public function testGetType() { $conn = $this->conn; $configHandler = $this->configHandler; $registerHandler = $this->registerHandler; $view = $this->view; $handler = new DynamicFieldHandler($conn, $configHandler, $registerHandler, $view); $group = 'group'; $id = 'id'; $configHandler->shouldReceive('get')->once()->andReturn(null); $result = $handler->getType($group, $id); $this->assertNull($result); $config = $this->getConfigEntity(); $config->shouldReceive('get')->with('typeId')->andReturn('type'); $configHandler->shouldReceive('get')->once()->andReturn($config); $type = m::mock('Type', 'Xpressengine\\DynamicField\\AbstractType'); $type->shouldReceive('setConfig'); $registerHandler->shouldReceive('getType')->andReturn($type); $result = $handler->getType($group, $id); $this->assertInstanceOf('Xpressengine\\DynamicField\\AbstractType', $result); }
/** * Dynamic Field 설정 페이지에서 skin 설정 등록 페이지 반환 * return html tag string * * @param ConfigEntity $config dynamic field config entity * @return string */ public function settings(ConfigEntity $config = null) { $viewFactory = $this->handler->getViewFactory(); return $viewFactory->make($this->getViewPath('settings'), ['config' => $config])->render(); }