⚠ 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

How to deal with callback_update



John Ophof

John Ophof
  • profile picture
  • Member

Posted 26 January 2015 - 10:41 AM

This is related to my other post as well see /topic/2894-indirect-join/

 

The code underneath works but when filling in a person the field scrum_team.scrum_masterID is not filled in.
Also the table scrum_master is not toucehed. I've heard that I must use callback_before_update. I try that one but it throws < unexpected on my javascript onsole

 

The table setup can be found in the following pastebin

http://pastebin.com/jXURCDQM

function scrum_team() {
    $subject = "Scrum team";
    $crud = new grocery_CRUD();
    $crud->set_theme('datatables');
    $crud->set_subject($subject);

    $crud->edit_fields('team_name', 'date_started', 'scrum_masterID', 'product_ownerID');
    $crud->columns('team_name', 'date_started', 'scrum_masterID', 'product_ownerID');
    $crud->add_fields('team_name', 'date_started', 'scrum_masterID', 'product_ownerID');

    //$crud->display_as('scrum_masterID', 'Scrum master');
    //$crud->display_as('product_ownerID', 'Product_owner');
    $crud->display_as('date_started', 'Team start date');
    $crud->display_as('team_name', 'Team name');

    //$crud->set_relation("scrum_masterID", "person", "christian_name");
    //$crud->set_relation("product_ownerID", "product_ownerID", "team_name");
    //$crud->add_action('SHow scrum team', '', '', 'ui-icon-image', array($this, 'navigate_team'));

    $cur_state = $crud->getState();
    /* Use the mySQL view to display the data with related tables */
    if (($cur_state == "list") || ($cur_state == "ajax_list") || ($cur_state == "read") || ($cur_state == "success")) {
      $crud->set_table('vw_scrum_team');
      $crud->columns('team_name', 'date_started', 'Scrum master first name', 'Scrum master christian name', 'Product owner first name', 'Product owner christian name');
      $crud->set_primary_key('scrum_teamID', 'vw_scrum_team');

      if ($cur_state == "read") {
        $crud->unset_fields('Scrum master first name', 'Scrum master christian name', 'Product owner first name', 'Product owner christian name');
      }
    } else {
      /* Use the patient_note table itself for add/edit operation */
      $crud->set_table('scrum_team');
      $crud->columns('team_name', 'date_started');
    }

    //$sm = $row->scrum_masterID; // or however you get the state you want to filter by
    //$crud->set_relation('scrum_masterID', 'scrum_master', 'christian_name', 'scrum_masterID IN (SELECT chistian_name FROM person WHERE personIDstate=' . $sm . ')');
    $crud->set_relation_n_n('Name scrum master', 'scrum_master', 'person', 'scrum_masterID', 'personID', 'first_name');
    $crud->edit_fields('team_name', 'date_started', 'product_ownerID', 'Name scrum master');
    $crud->add_fields('team_name', 'date_started', 'product_ownerID', 'Name scrum master');

    $crud->callback_before_update(array($this, '_fill_scrummaster'));

    $output = $crud->render();
    $this->_scrumba_output($output);
  }

  function _fill_scrummaster($post_array, $primary_key) {
    echo "personID " . $post_array ["personID"];
    echo "primary_key " . $primary_key;
    exit;
  }
 

I studies a lot on grocerycrud on first eye pretty simple but later on it got more complex.

My graphical datamodel is this http://picpaste.com/Screen_Shot_2015-01-26_at_11.39.59-3fOyu7L4.png

 

I am also looking for a nice example how to make your own db query on a column field. How are parameters past? How is output returned.

Like in this example how is $select set? http://stackoverflow.com/questions/15220603/crud-codeigniter-default-value

 

Many thanks in advance,

John