Modules\Sections\Module::installModule PHP Method

installModule() public method

public installModule ( )
    public function installModule()
    {
        parent::installModule();
        $this->container->get('db')->schema()->create('sections', function ($table) {
            $table->increments('id');
            $table->string('name');
            $table->string('code');
            $table->integer('sort')->default(100)->nullable();
            $table->integer('parent_id')->default(0)->nullable();
            $table->text('detail_text')->nullable();
            $table->string('detail_picture')->nullable();
            $table->string('show_in_menu')->nullable();
            $table->string('name_for_menu')->nullable();
            $table->string('path')->nullable();
            $table->char('active', 1)->default(1);
            $table->timestamps();
            $table->index(['code', 'parent_id', 'path']);
            //$table->foreign('parent_id')->references('id')->on('sections');
        });
        $this->container->get('db')->schema()->table('pages', function ($table) {
            $table->integer('category_id')->default(0)->nullable();
            //$table->foreign('category_id')->references('id')->on('sections');
        });
        $path = RESOURCE_PATH . 'models_field_info/pages.json';
        $pagesField = FileWorker::getJsonDataFile($path);
        if (!$pagesField) {
            $pagesField = [];
        }
        $trigUrlPrefix = false;
        foreach ($pagesField as $field) {
            if ($field->name == 'url_prefix') {
                $field->type = "hidden";
                $trigUrlPrefix = true;
                break;
            }
        }
        if (!$trigUrlPrefix) {
            $cId = new \stdClass();
            $cId->name = "url_prefix";
            $cId->type = "hidden";
            $pagesField[] = $cId;
        }
        $cId = new \stdClass();
        $cId->name = "category_id";
        $cId->type = "select";
        $pagesField[] = $cId;
        FileWorker::saveJsonFile($path, $pagesField);
        FileWorker::addItemInModelsFillable('Pages', 'category_id');
        $this->saveConfigForModule(self::class, ["params" => ["installed" => true, "active" => true]]);
    }