⚠ 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

having trouble with set relation_n_n



richb201
  • profile picture
  • Member

Posted 02 April 2018 - 00:03 AM

I am trying to allow a user to from a pre-existing list of activities and am using set_relation_n_n. Here is the screen that is generated. Here is the code that does it:

public function activity_management()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('activity');//$crud->or_where_in('email',base64_decode( urldecode( $this->session->userdata('userid'))) ,$this->session->userdata('userid'),'N/A' );
$crud->set_subject('a new activity');
$crud->change_field_type('email','invisible');
$crud->change_field_type('campaign','invisible');
$crud->where('email', $this->session->userdata('userid') );
// $crud->or_where('email',$this->session->userdata('userid'));
$crud->or_where ('email','NA');
$crud->where('campaign', $this->session->userdata('campaign') ); //ANDed with email

// $email_encrypt=base64_decode( urldecode( $this->session->userdata('userid') ));
$email_unencrypt=$this->session->userdata('userid');
$email_na="NA";

$where_clause="email in ('$email_unencrypt','NA')";

$crud->set_relation_n_n('activities', 'relation', 'standard_activities', 'activity_id', 'standard_id', 'activity','priority',$where_clause);

$crud->unset_edit_fields('activity_id','email');
$crud->unset_columns('campaign','activity_id','email');
$crud->change_field_type('email','invisible');
$crud->change_field_type('activity_id','invisible');
// $crud->fields('activity_id');
$crud->callback_before_insert(array($this,'add_email'));
$output = $crud->render();

$this->_configure_output($output);

 

The problem is that I want to add the items selected to activity_text. I can't seem to post the data structure. 

 

 

Any idea why the activity_text field is not being populated with the "items selected"?

 

 

 

  

 

 

 


richb201
  • profile picture
  • Member

Posted 02 April 2018 - 06:29 AM

I looked at it a little more last night. When I select items, and they appear in the left box, which is correct, but I need to access them, one at a time(and also hide the activity_text field). The reason is that the activity_text field is the actual field that my app is using and it is in the activity table, not the relation table. So my question rephrased is "how can I add a new record to the activity table for each item selected but only if the activity and campaign are unique"? 

 

<a href="http://s1361.photobucket.com/user/richb201/media/shed%20site/Capture2_zps6lsjki8w.jpg.html" target="_blank"><img src="http://i1361.photobucket.com/albums/r676/richb201/shed%20site/Capture2_zps6lsjki8w.jpg" border="0" alt=" photo Capture2_zps6lsjki8w.jpg"/></a>

 

I am considering using callback_after_insert. If I could iterate through the "items selected" in Activities, I could just add  multiple records in a loop with 

 

 

while()

     $this->db->insert('activity',$activity_insert);

 

where activity_insert is populated from the items selected control. How can I access what has been selected?