src/Model/Group.php
public function store() {

        //2. Saniitize the data
        $groupTitle = $this->input->getString("group-title");
        $groupParent = $this->input->getInt("group-parent");
        $groupId = $this->input->getInt("group-id");
        $groupDescription = $this->input->getString("group-description");

        $groupName = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $groupTitle));

        $gData = array(
            "group_id" => $groupId,
            "group_name" => $groupName,
            "group_title" => $groupTitle,
            "group_parent_id" => empty($groupParent) ? 0 : (int) $groupParent,
            "group_description" => $groupDescription,
            "group_owner" => $this->get("user")->get("user_name_id"),
            "group_lft" => 1,
            "group_rgt" => 2
        );

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

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

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

            if (empty($groupName) || empty($groupTitle)) {
                $this->setError(_t('Every new Group must have a defined Title'));
                return false;
            }

            $rgt = $parent = $this->database->select("MAX(group_rgt) AS max")->from("?groups")->where("group_owner", $this->database->quote($table->getRowFieldValue('group_owner')))->prepare()->execute()->fetchObject();

            if (!empty($groupParent)):
                //Get the parent left and right value, to make space
                $parent = $this->database->select("group_lft, group_rgt")->from("?groups")->where("group_id", (int) $table->getRowFieldValue('group_parent_id'))->prepare()->execute()->fetchObject();
                //echo $parent->rgt;

                $this->database->update("?groups", array("group_lft" => "group_lft+2"), array("group_lft >" => ($parent->group_rgt - 1 ), "group_owner" => $this->database->quote($table->getRowFieldValue('group_owner'))));
                $this->database->update("?groups", array("group_rgt" => "group_rgt+2"), array("group_rgt >" => ($parent->group_rgt - 1), "group_owner" => $this->database->quote($table->getRowFieldValue('group_owner'))));

                $table->setRowFieldValue("group_lft", $parent->group_rgt);
                $table->setRowFieldValue("group_rgt", $parent->group_rgt + 1);
            else:
                $table->setRowFieldValue("group_lft", $rgt->max + 1);
                $table->setRowFieldValue("group_rgt", $rgt->max + 2);
            endif;
        }

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

        return true;
    }
public function store() {

        //2. Saniitize the data
        $groupTitle = $this->input->getString("group-title");
        $groupParent = $this->input->getInt("group-parent");
        $groupId = $this->input->getInt("group-id");
        $groupDescription = $this->input->getString("group-description");

        $groupName = strtoupper(str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), "", $groupTitle));

        $gData = array(
            "group_id" => $groupId,
            "group_name" => $groupName,
            "group_title" => $groupTitle,
            "group_parent_id" => empty($groupParent) ? 0 : (int) $groupParent,
            "group_description" => $groupDescription,
            "group_owner" => $this->get("user")->get("user_name_id"),
            "group_lft" => 1,
            "group_rgt" => 2
        );

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

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

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

            if (empty($groupName) || empty($groupTitle)) {
                $this->setError(_t('Every new Group must have a defined Title'));
                return false;
            }

            $rgt = $parent = $this->database->select("MAX(group_rgt) AS max")->from("?groups")->where("group_owner", $this->database->quote($table->getRowFieldValue('group_owner')))->prepare()->execute()->fetchObject();

            if (!empty($groupParent)):
                //Get the parent left and right value, to make space
                $parent = $this->database->select("group_lft, group_rgt")->from("?groups")->where("group_id", (int) $table->getRowFieldValue('group_parent_id'))->prepare()->execute()->fetchObject();
                //echo $parent->rgt;

                $this->database->update("?groups", array("group_lft" => "group_lft+2"), array("group_lft >" => ($parent->group_rgt - 1 ), "group_owner" => $this->database->quote($table->getRowFieldValue('group_owner'))));
                $this->database->update("?groups", array("group_rgt" => "group_rgt+2"), array("group_rgt >" => ($parent->group_rgt - 1), "group_owner" => $this->database->quote($table->getRowFieldValue('group_owner'))));

                $table->setRowFieldValue("group_lft", $parent->group_rgt);
                $table->setRowFieldValue("group_rgt", $parent->group_rgt + 1);
            else:
                $table->setRowFieldValue("group_lft", $rgt->max + 1);
                $table->setRowFieldValue("group_rgt", $rgt->max + 2);
            endif;
        }

        //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