src/Model/Authority.php
public function store($data = "", $params = array()) {

        //1. Load Helpers
        $encrypt = \Library\Encrypt::getInstance();


        //2. Saniitize the data
        $authorityTitle = $this->input->getString("authority-title");
        $authorityParent = $this->input->getInt("authority-parent");
        $authorityId = $this->input->getInt("authority-id");

        $authorityDescription = $this->input->getString("authority-description");

        $authorityName = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $authorityTitle));

//        $authorityAreaTitle         = $this->input->getArray("area-title", array() );
//        $authorityAreaURI           = $this->input->getArray("area-uri", array() );
//        $authorityAreaAction        = $this->input->getArray("area-action", array() );
//        $authorityAreaPermission    = $this->input->getArray("area-permission", array() );
//        
//        $authorityAreaName          = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $authorityAreaTitle));
//        

        $aData = array(
            "authority_id" => $authorityId,
            "authority_name" => $authorityName,
            "authority_title" => $authorityTitle,
            "authority_parent_id" => empty($authorityParent) ? 1 : (int) $authorityParent,
            "authority_description" => $authorityDescription
        );

        //3. Load and prepare the Authority Table
        $table = $this->load->table("?authority");

        if (!$table->bindData($aData)) {
            //print_R($table->getErrors());
            throw new \Platform\Exception($table->getError());
            return false;
        }

        //4. Are we adding a new row
        if ($table->isNewRow()) {

            if (empty($authorityName) || empty($authorityParent) || empty($authorityTitle)) {
                $this->setError(_t('Every new authority must have a defined Title, and must be a subset of the public authority'));
                return false;
            }

            //Get the parent left and right value, to make space
            $parent = $this->database->select("lft, rgt")->from("?authority")->where("authority_id", (int) $table->getRowFieldValue('authority_parent_id'))->prepare()->execute()->fetchObject();

            $update = array(
                "lft" => "lft+2",
                "rgt" => "rgt+2"
            );

            //echo $parent->rgt;

            $this->database->update("?authority", array("lft" => "lft+2"), array("lft >" => ($parent->rgt - 1)));
            $this->database->update("?authority", array("rgt" => "rgt+2"), array("rgt >" => ($parent->rgt - 1)));

            $table->setRowFieldValue("lft", $parent->rgt);
            $table->setRowFieldValue("rgt", $parent->rgt + 1);
        }

        //5. Save the table modifications
        if (!$table->save()) {
            return false;
        }

        return true;
    }
public function store($data = "", $params = array()) {

        //1. Load Helpers
        $encrypt = \Library\Encrypt::getInstance();


        //2. Saniitize the data
        $authorityTitle = $this->input->getString("authority-title");
        $authorityParent = $this->input->getInt("authority-parent");
        $authorityId = $this->input->getInt("authority-id");

        $authorityDescription = $this->input->getString("authority-description");

        $authorityName = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $authorityTitle));

//        $authorityAreaTitle         = $this->input->getArray("area-title", array() );
//        $authorityAreaURI           = $this->input->getArray("area-uri", array() );
//        $authorityAreaAction        = $this->input->getArray("area-action", array() );
//        $authorityAreaPermission    = $this->input->getArray("area-permission", array() );
//        
//        $authorityAreaName          = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $authorityAreaTitle));
//        

        $aData = array(
            "authority_id" => $authorityId,
            "authority_name" => $authorityName,
            "authority_title" => $authorityTitle,
            "authority_parent_id" => empty($authorityParent) ? 1 : (int) $authorityParent,
            "authority_description" => $authorityDescription
        );

        //3. Load and prepare the Authority Table
        $table = $this->load->table("?authority");

        if (!$table->bindData($aData)) {
            //print_R($table->getErrors());
            throw new \Platform\Exception($table->getError());
            return false;
        }

        //4. Are we adding a new row
        if ($table->isNewRow()) {

            if (empty($authorityName) || empty($authorityParent) || empty($authorityTitle)) {
                $this->setError(_t('Every new authority must have a defined Title, and must be a subset of the public authority'));
                return false;
            }

            //Get the parent left and right value, to make space
            $parent = $this->database->select("lft, rgt")->from("?authority")->where("authority_id", (int) $table->getRowFieldValue('authority_parent_id'))->prepare()->execute()->fetchObject();

            $update = array(
                "lft" => "lft+2",
                "rgt" => "rgt+2"
            );

            //echo $parent->rgt;

            $this->database->update("?authority", array("lft" => "lft+2"), array("lft >" => ($parent->rgt - 1)));
            $this->database->update("?authority", array("rgt" => "rgt+2"), array("rgt >" => ($parent->rgt - 1)));

            $table->setRowFieldValue("lft", $parent->rgt);
            $table->setRowFieldValue("rgt", $parent->rgt + 1);
        }

        //5. Save the table modifications
        if (!$table->save()) {
            return false;
        }

        return true;
    }
Stores Authority Data to the database
@param array $data
@return boolean true on success