Система управления «Сайт PRO»
Версия 20240107

Класс Modules

Объект $Modules: Cms\Root\Main\Modules наследует Cms\Site\Base

Объект для работы с модулями системы управления

Объект $Modules

Исходный код
class Modules extends \Cms\Site\Base { … }

Свойства

$modules

$Modules->modules = array();

Список типов страниц

Исходный код
    var $modules = array();

$select

$Modules->select = array(
        '' => '',
    );

Данные для выпадающего списка «Тип страницы»

Смотрите описание $Main->getTypes()

Исходный код
    var $select = array( … );

$_enabledModuleList

$Modules->_enabledModuleList
Исходный код
    var $_enabledModuleList;

Методы

init()

$Modules->init();

Инициализация

Возвращает: true – инициализация выполнена; null – инициализация уже выполнена ранее

Исходный код
    function init() {
        $this->loadData();
        $modules = $this->Conf()->get('modules', array());
        if (is_string($modules)) {
            $types = explode('|', $modules);
            $modules = array();
            foreach ($types as $type) if (strlen($type)) $modules[$type] = 'Y';
        }
        foreach ($modules as $type => $Y) {
            $Type = $this->initModule($type);
            $Type->set('enable', 'Y');
            $Type->set('site', 'Y');
        }
        $step = 0;
        $done = false;
        while (!$done) {
            $step ++;
            $done = true;
            foreach ($this->modules as $type => $Type) if (!$Type->register) {
                $done = false;
                $Type = $this->registerModule($type);
                if ($step > 1) $Type->set('enable', 'Y');
            }
        }
        foreach ($this->modules as $type => $Type) if (!$Type->getPropertyList()) {
            $Type->addPropertyFieldList();
        }
    }

loadData()

$Modules->loadData();
Исходный код
    function loadData() {
        $App = $this->App();
        $this->initModule('page');
        $typeClass = $App->getClass('data_type');
        if ($path = $App->resolvePath('cms/site/main/modules.data.php')) {
            foreach (include($path) as $typeData) {
                if (!$Type = $this->getModule($typeData['name'])) $Type = new $typeClass($typeData['name']);
                $typeData['site'] = 'Y';
                if (is_array($typeData['fields'])) foreach ($typeData['fields'] as $fieldName => $fieldData) if (is_array($fieldData)) $typeData['fields'][$fieldName]['site'] = 'Y';
                $Type->addTypeData($typeData, true);
                $this->addModule($Type);
            }
        }
        if ($path = __DIR__ . DIRECTORY_SEPARATOR . 'modules.data.php') {
            foreach (include($path) as $typeData) {
                if (!$Type = $this->getModule($typeData['name'])) $Type = new $typeClass($typeData['name']);
                $typeData['root'] = 'Y';
                if (is_array($typeData['fields'])) foreach ($typeData['fields'] as $fieldName => $fieldData) if (is_array($fieldData)) $typeData['fields'][$fieldName]['root'] = 'Y';
                $Type->addTypeData($typeData, false);
                $this->addModule($Type);
            }
        }
    }

saveData()

$Modules->saveData();
Исходный код
    function saveData() {
        $data = array();
        foreach ($this->getModuleList() as $Type) if ($Type->isSite()) {
            $data[$Type->getName()] = $Type->getTypeData();
        }
        return $this->App()->get('file')->saveFileData($this->root() . '/cms/site/main/modules.data.php', $data);
    }

registerModule()

$Modules->registerModule($type);
Исходный код
    function registerModule($type) {
        $Type = $this->initModule($type);
        if ($Type->register) return $Type;
        $object = $Type->object;
        if (is_callable(array($object, 'register'))) {
            $var = ucfirst(strtolower($type));
            global $$var;
            $$var = $object;
            $Main = $this->Main();
            $data = $$var->register($Main);
            if (is_array($data)) foreach ($data as $k => $v) $Type->set($k, $v);
        }
        $Type->register = true;
        return $Type;
    }

initModule()

$Modules->initModule($type);
Исходный код
    function initModule($type) {
        if ($this->isModule($type)) return $this->getModule($type);
        $typeClass = $this->App()->getClass('data_type');
        $Type = $this->modules[$type] = new $typeClass($type);
        return $this->addModule($Type);
    }

addModule()

$Modules->addModule(\Cms\Root\Data\Type $Type);
Исходный код
    function addModule(\Cms\Root\Data\Type $Type) {
        $type = $Type->name;
        $this->modules[$type] = $Type;
        if (!isset($Type->table)) $Type->table = 'item';
        if (!isset($Type->class) || !isset($Type->object)) {
            $object = $this->App()->getPageObject($type);
            if (!isset($Type->class)) $Type->class = get_class($object);
            if (!isset($Type->object)) $Type->object = $object;
        }
        if ($Type->isSelect()) $this->addType($Type->getName(), $Type->getTitle());
        return $Type;
    }

isType()

$Modules->isType($type);
Исходный код
    function isType($type) {
        return isset($this->modules[$type]);
    }

isModule()

$Modules->isModule($type);
Исходный код
    function isModule($type) {
        return isset($this->modules[$type]);
    }

getModule()

$Modules->getModule($type);
Исходный код
    function getModule($type) {
        return $this->modules[$type];
    }

getModuleList()

$Modules->getModuleList();
Исходный код
    function getModuleList() {
        return $this->modules;
    }

getEnabledModuleList()

$Modules->getEnabledModuleList();
Исходный код
    function getEnabledModuleList() {
        if (isset($this->_enabledModuleList)) return $this->_enabledModuleList;
        $r = array();
        foreach ($this->getModuleList() as $type => $Type) {
            if ($Type->isEnabled()) $r[$type] = $Type;
        }
        return $this->_enabledModuleList = $r;
    }

resetEnabledModuleList()

$Modules->resetEnabledModuleList();
Исходный код
    function resetEnabledModuleList() {
        unset($this->_enabledModuleList);
    }

getClass()

$Modules->getClass($type);
Исходный код
    function getClass($type) {
        $class = $this->modules[$type]['class'];
        if (!strlen($class)) $class = $this->App()->getClass($type);
        return $class;
    }

getTypes()

$Modules->getTypes();
Исходный код
    function getTypes() {
        return $this->select;
    }

addType()

$Modules->addType($type, $title);
Исходный код
    function addType($type, $title) {
        $this->select[$type === 'page' ? '' : $type] = $title;
    }