⚠ 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

callback_before_update with regard to timestamp



Thomas Ferreira
  • profile picture
  • Member

Posted 07 August 2012 - 08:43 AM

Hey Guys I have been trying to wrap my head around this for 2 days and can't get this to work. I am new to Grocery Crud and am still figuring out all the functionality.

This is what I am trying to achieve:

I have a project where I need to create moderate and display articles on a site. These three methods have 3 different states: New, Approved, All. I am able to get a timestamp when I create(new) an article, however I am unable to get a timestamp for when the article has been moderated and the approved state has been selected.

I.e: New article created 07 july 2012. Now when this article has been approved it should log the new date and time of when the article was approved, i.e 08 july 2012.

I do have 2 seperate fields in my database 1 for date created and 1 for date approved. When I change the status from new to approved in the crud the date field is left blank. I hope this clears things up.

Here is the code:


public function _datetime_moderated($post_array, $primary_key) {
$post_array['datetime_moderated'] = date('Y-m-d H:i:s');
return $post_array;
}

function tutorial_moderate() {

$crud = new grocery_CRUD();
$crud->set_table('tutorial');
$crud->where('tutorial_status', 'New');
$crud->fields('tutorial_title','tutorial_body','datetime_added','tutorial_status', 'decline_reason');
$crud->columns('tutorial_title','datetime_added','tutorial_status');

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

$output=$crud->render();
$html=$this->load->view('admin/layout_list', $output, True);
$data=array('BASE_URL'=>base_url('admin'),);
$this->parser->parse_string($html, $data);

}