⚠ 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 forum is read-only and soon will be archived. ⚠


ded

Member Since 09 Apr 2014
Offline Last Active Apr 20 2014 10:07 PM
-----

Posts I've Made

In Topic: Replicated attribute in a Custom Table

14 April 2014 - 04:36 AM

Well, what I managed to do is creating 10 columns in my original table (pessoa) and call it fake_conhece_pessoa_01, fake_conhece_pessoa_02,...
 
I'm not displaying these fields in the table, they just receive the values and with the callback_after_insert I send these values to another table.
 
I am also using a callback_before_insert to validate the fields fake_conhece_pessoa_XX ('cause I noticed that if these fields are left blank and the user submit the add form, the form actually doesn't send the values to the table and the page stays stuck at the form). so the callback_before_insert checks if the field is empty and if it is it just puts the value 0 (zero) to it.
 
The problem is that I don't know if the problem is that this "check" function is not working 'cause of some bad coding or if it has something to do with the set_relation that I have on every fake_conhece_pessoa_XX. Does the set_relation kind of make the user obligated to put value in it? Or if the field is with set_relation I can't add value to it if it is left blank?
 
function pessoa_management()
{
$crud = new grocery_CRUD();


$crud->set_table('pessoa');
$crud->set_subject('Pessoa');
$crud->columns('pessoa_link','nome_completo','cidade_natal');
$crud->fields('pessoa_link','nome_completo','cidade_natal');
$crud->required_fields('pessoa_link','nome_completo','cidade_natal');
$crud->display_as('pessoa_id','Pessoa ID')
->display_as('pessoa_link','Pessoa URL')
->display_as('nome_completo','Nome Completo')
->display_as('cidade_natal','Cidade Natal');
->display_as('fake_conhece_pessoa_01','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_02','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_03','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_04','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_05','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_06','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_07','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_08','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_09','Pessoa Conhecida')
->display_as('fake_conhece_pessoa_10','Pessoa Conhecida');


$crud->set_relation('fake_conhece_pessoa_01','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_02','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_03','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_04','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_05','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_06','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_07','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_08','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_09','pessoa','nome_completo');
$crud->set_relation('fake_conhece_pessoa_10','pessoa','nome_completo');


$crud->callback_after_insert(array($this, 'fconhece'));
$crud->callback_before_insert(array($this,'check'));
$crud->callback_before_update(array($this,'check'));


$output = $crud->render();


$this->_redesocial_output($output);
}

 

function check($post_array)
{
if(empty($post_array['fake_conhece_pessoa_01'])) {
$post_array['fake_conhece_pessoa_01'] = 0;
}


if(empty($post_array['fake_conhece_pessoa_02'])) {
$post_array['fake_conhece_pessoa_02'] = 0;
}


if(empty($post_array['fake_conhece_pessoa_03'])) {
$post_array['fake_conhece_pessoa_03'] = 0;
}


...
 
 
return $post_array;
}
function fconhece($post_array, $primary_key)
{
$user_logs_insert01 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_01']);
$user_logs_insert02 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_02']);
$user_logs_insert03 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_03']);
$user_logs_insert04 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_04']);
$user_logs_insert05 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_05']);
$user_logs_insert06 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_06']);
$user_logs_insert07 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_07']);
$user_logs_insert08 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_08']);
$user_logs_insert09 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_09']);
$user_logs_insert10 = array("pessoa_id" => $primary_key, "pessoa_conhecida_id" => $post_array['fake_conhece_pessoa_10']);
 
$this->db->insert('conhece',$user_logs_insert01);
$this->db->insert('conhece',$user_logs_insert02);
$this->db->insert('conhece',$user_logs_insert03);
$this->db->insert('conhece',$user_logs_insert04);
$this->db->insert('conhece',$user_logs_insert05);
$this->db->insert('conhece',$user_logs_insert06);
$this->db->insert('conhece',$user_logs_insert07);
$this->db->insert('conhece',$user_logs_insert08);
$this->db->insert('conhece',$user_logs_insert09);
$this->db->insert('conhece',$user_logs_insert10);


return true;
}

In Topic: Replicated attribute in a Custom Table

12 April 2014 - 08:44 PM

I did some progress using Callback_after_insert but still I can't make it to work. In the function "fconhece", when I assign the values $primary_key to both variables "pessoa_id" and "pessoa_conhecida_id" it works, but when I try to assign another value to the variable "pessoa_conhecida_id" it doesn't work (like in the code below).
 
I'm putting a field in the add form that I don't have in my original table (the field is "pessoa_conhecida" and its value is going to the table "conhece").
 
public function test()
{
$crud = new grocery_CRUD();


$crud->set_table('pessoa');
$crud->set_subject('Pessoa');
$crud->add_fields('pessoa_link','nome_completo','cidade_natal','pessoa_conhecida');


$crud->callback_after_insert(array($this, 'fconhece'));


$output = $crud->render();


$this->_example_output($output);
}

 

function fconhece($post_array, $primary_key)
{
$user_logs_insert = array(
"pessoa_id" => $primary_key,
"pessoa_conhecida_id" => $post_array["pessoa_conhecida"]
     );


$this->db->insert('conhece',$user_logs_insert);


return true;
}

 


In Topic: Replicated attribute in a Custom Table

12 April 2014 - 05:57 PM

Thank you for your response Amit, using set_relation works like a charm.

 

Do you know if it is also possible to create other fields in the "add/insert" form in the person's table to feed another table?

 

For example:

 

So far I have in the person's insert fields:

Person URL:

Person Full Name:

Person Hometown:

 

and I would have:

Person URL:

Person Full Name:

Person Hometown:

Person Know:

Person Like:

 

The last two (Person Know and Person Like) would feed another table: Person Know would feed a column in my Knows Table and Person Like would feed a column in my Likes table.


In Topic: Replicated attribute in a Custom Table

10 April 2014 - 01:26 PM

I'd be grateful for any help.