BlogCategory::getControlSource PHP Method

getControlSource() public method

コントロールソースを取得する
public getControlSource ( string $field, $options = [] ) : array
$field string フィールド名
return array コントロールソース
    public function getControlSource($field, $options = [])
    {
        switch ($field) {
            case 'parent_id':
                if (!isset($options['blogContentId'])) {
                    return false;
                }
                $conditions = [];
                if (isset($options['conditions'])) {
                    $conditions = $options['conditions'];
                }
                $conditions['BlogCategory.blog_content_id'] = $options['blogContentId'];
                if (!empty($options['excludeParentId'])) {
                    $children = $this->children($options['excludeParentId']);
                    $excludeIds = [$options['excludeParentId']];
                    foreach ($children as $child) {
                        $excludeIds[] = $child['BlogCategory']['id'];
                    }
                    $conditions['NOT']['BlogCategory.id'] = $excludeIds;
                }
                if (isset($options['ownerId'])) {
                    $ownerIdConditions = [['BlogCategory.owner_id' => null], ['BlogCategory.owner_id' => $options['ownerId']]];
                    if (isset($conditions['OR'])) {
                        $conditions['OR'] = am($conditions['OR'], $ownerIdConditions);
                    } else {
                        $conditions['OR'] = $ownerIdConditions;
                    }
                }
                $parents = $this->generateTreeList($conditions);
                $controlSources['parent_id'] = [];
                foreach ($parents as $key => $parent) {
                    if (preg_match("/^([_]+)/i", $parent, $matches)) {
                        $parent = preg_replace("/^[_]+/i", '', $parent);
                        $prefix = str_replace('_', '&nbsp&nbsp&nbsp', $matches[1]);
                        $parent = $prefix . '└' . $parent;
                    }
                    $controlSources['parent_id'][$key] = $parent;
                }
                break;
            case 'owner_id':
                $UserGroup = ClassRegistry::init('UserGroup');
                $controlSources['owner_id'] = $UserGroup->find('list', ['fields' => ['id', 'title'], 'recursive' => -1]);
                break;
        }
        if (isset($controlSources[$field])) {
            return $controlSources[$field];
        } else {
            return false;
        }
    }