⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Grocery CRUD with MPTT



Alex Price
  • profile picture
  • Member

Posted 15 January 2013 - 08:55 AM

Hey,
Did you figure this out? I am trying to figure out a way to get rid of "Update and go back to list" button.

nigeltufnel
  • profile picture
  • Member

Posted 15 January 2013 - 14:22 PM

I never figured out a comprehensive CI solution. I did create a non-CI PHP page to serve in the place of the Edit and made a custom callback function to override the default edit option.

Having dealt with CI for several months now, I could probably take another stab at integrating that MPTT library into our project. However, not a high priority since our app does what it needs to do.

To your question, I haven't removed any of the "Update and go back to list" buttons on the edit dialog, but I would assume that could be done in the same manner as removing actions on the main table.

nigeltufnel
  • profile picture
  • Member

Posted 26 April 2013 - 15:35 PM

I am posting a follow-up now that I have had a few months to get familiar with CI and now have a solution.

 

First, many thanks to [member='victor'].  His recommendation to use the Nested_set library ultimately worked.  I abandoned the stored procedure solution that I used initially.

 

Brief overview:

(1) Download Nested_set.php from http://pastebin.com/gAN1DZMb.  (Note that there are a few other variations of this library posted on pastebin and github, but this was the one I used).

(2) I installed Nested_set.php into the system library directory, but I assume the application library directory would work just the same.

(3) Create a model that 'extends grocery_CRUD_Model'

(4) In the model, specify the mptt subject table and identify its columns used by the nested set library.

 

 

    public function __construct()
    {
      parent::__construct();
      $this->load->library('Nested_set');
      $this->nested_set->setControlParams(
            'mysubjecttable',
            'lft',
            'rgt',
            'id',
            'parent_id',
            '1');
    }

 

Override the default insert, update, and delete methods:

    public function db_insert($post_array)
    {
        return $this->nested_set->appendNewChild(
            $this->nested_set->getNodeFromId($post_array['parent_id']),
            $post_array
        );
    }

 

    public function db_update($post_array, $primary_key_value)
    {
        return $this->nested_set->setNodeAsLastChild(
            $this->nested_set->getNodeFromId($primary_key_value),
            $this->nested_set->getNodeFromId($post_array['parent_id'])
        );
    }
    public function db_delete($primary_key_value)
    {
        return $this->nested_set->deleteNode(
            $this->nested_set->getNodeFromId($primary_key_value)
        );
    }

 

 

(5) In the controller, load the custom model: $crud->set_model('nameofmycustommodel');

 

 

Thanks again for all of the help.