protected function onModelCreated()
    {
        parent::onModelCreated();

        if ($this->incomingRestModel instanceof Model){
            $this->setRestModel($this->incomingRestModel);
        } elseif ($this->incomingRestModel instanceof Collection){
            $this->setRestCollection($this->incomingRestModel);
        }

        $this->model->createSubLeafFromNameEvent->attachHandler(function($leafName){

            if (!$this->hasRestModelOrCollection) {
                return null;
            }

            $restModel = $this->model->restModel;

            if ($restModel) {
                $class = $restModel->getModelName();
                $schema = $restModel->getSchema();
            } else {
                $restCollection = $this->model->restCollection;

                $class = $restCollection->getModelClassName();
                $schema = $restCollection->getModelSchema();
            }

            $leaf = $this->createLeafForLeafName($leafName);

            if ($leaf){
                return $leaf;
            }

            // See if the model has a relationship with this name.
            $relationships = SolutionSchema::getAllOneToOneRelationshipsForModelBySourceColumnName($class);

            $columnRelationships = false;

            if (isset($relationships[$leafName])) {
                $columnRelationships = $relationships[$leafName];
            } else {
                if ($leafName == $schema->uniqueIdentifierColumnName) {
                    if (isset($relationships[""])) {
                        $columnRelationships = $relationships[""];
                    }
                }
            }

            if ($columnRelationships) {
                $relationship = $relationships[$leafName];

                $collection = $relationship->getCollection();

                $dropDown = new DropDown($leafName);
                $dropDown->setSelectionItems(
                    [
                        ["", "Please Select"],
                        $collection
                    ]
                );

                $dropDown->setLabel(StringTools::wordifyStringByUpperCase($relationship->getNavigationPropertyName()));

                return $dropDown;
            }

            $columns = $schema->getColumns();

            if (!isset($columns[$leafName])) {
                return null;
            }

            $column = $columns[$leafName];

            return $this->createLeafFromColumn($column, $leafName);
        });
    }
protected function onModelCreated()
    {
        parent::onModelCreated();

        if ($this->incomingRestModel instanceof Model){
            $this->setRestModel($this->incomingRestModel);
        } elseif ($this->incomingRestModel instanceof Collection){
            $this->setRestCollection($this->incomingRestModel);
        }

        $this->model->createSubLeafFromNameEvent->attachHandler(function($leafName){

            if (!$this->hasRestModelOrCollection) {
                return null;
            }

            $restModel = $this->model->restModel;

            if ($restModel) {
                $class = $restModel->getModelName();
                $schema = $restModel->getSchema();
            } else {
                $restCollection = $this->model->restCollection;

                $class = $restCollection->getModelClassName();
                $schema = $restCollection->getModelSchema();
            }

            $leaf = $this->createLeafForLeafName($leafName);

            if ($leaf){
                return $leaf;
            }

            // See if the model has a relationship with this name.
            $relationships = SolutionSchema::getAllOneToOneRelationshipsForModelBySourceColumnName($class);

            $columnRelationships = false;

            if (isset($relationships[$leafName])) {
                $columnRelationships = $relationships[$leafName];
            } else {
                if ($leafName == $schema->uniqueIdentifierColumnName) {
                    if (isset($relationships[""])) {
                        $columnRelationships = $relationships[""];
                    }
                }
            }

            if ($columnRelationships) {
                $relationship = $relationships[$leafName];

                $collection = $relationship->getCollection();

                $dropDown = new DropDown($leafName);
                $dropDown->setSelectionItems(
                    [
                        ["", "Please Select"],
                        $collection
                    ]
                );

                $dropDown->setLabel(StringTools::wordifyStringByUpperCase($relationship->getNavigationPropertyName()));

                return $dropDown;
            }

            $columns = $schema->getColumns();

            if (!isset($columns[$leafName])) {
                return null;
            }

            $column = $columns[$leafName];

            return $this->createLeafFromColumn($column, $leafName);
        });
    }
protected function onModelCreated ( ) { parent :: onModelCreated ( ) ; if ( $ this -> incomingRestModel instanceof Model ) { $ this -> setRestModel ( $ this -> incomingRestModel ) ; } elseif ( $ this -> incomingRestModel instanceof Collection ) { $ this -> setRestCollection ( $ this -> incomingRestModel ) ; } $ this -> model -> createSubLeafFromNameEvent -> attachHandler ( function ( $ leafName ) { if ( ! $ this -> hasRestModelOrCollection ) { return null ; } $ restModel = $ this -> model -> restModel ; if ( $ restModel ) { $ class = $ restModel -> getModelName ( ) ; $ schema = $ restModel -> getSchema ( ) ; } else { $ restCollection = $ this -> model -> restCollection ; $ class = $ restCollection -> getModelClassName ( ) ; $ schema = $ restCollection -> getModelSchema ( ) ; } $ leaf = $ this -> createLeafForLeafName ( $ leafName ) ; if ( $ leaf ) { return $ leaf ; } // See if the model has a relationship with this name. $ relationships = SolutionSchema :: getAllOneToOneRelationshipsForModelBySourceColumnName ( $ class ) ; $ columnRelationships = false ; if ( isset ( $ relationships [ $ leafName ] ) ) { $ columnRelationships = $ relationships [ $ leafName ] ; } else { if ( $ leafName == $ schema -> uniqueIdentifierColumnName ) { if ( isset ( $ relationships [ "" ] ) ) { $ columnRelationships = $ relationships [ "" ] ; } } } if ( $ columnRelationships ) { $ relationship = $ relationships [ $ leafName ] ; $ collection = $ relationship -> getCollection ( ) ; $ dropDown = new DropDown ( $ leafName ) ; $ dropDown -> setSelectionItems ( [ [ "" , "Please Select" ] , $ collection ] ) ; $ dropDown -> setLabel ( StringTools :: wordifyStringByUpperCase ( $ relationship -> getNavigationPropertyName ( ) ) ) ; return $ dropDown ; } $ columns = $ schema -> getColumns ( ) ; if ( ! isset ( $ columns [ $ leafName ] ) ) { return null ; } $ column = $ columns [ $ leafName ] ; return $ this -> createLeafFromColumn ( $ column , $ leafName ) ; } ) ; }
Provides an opportunity for extending classes to modify the model in some way when they themselves are not
directly responsible for the model creation.
Provides an opportunity for extending classes to modify the model in some way when they themselves are not directly responsible for the model creation .