FriendsOfCake/cakephp-csvview

Custom variables

shainanand opened this issue · 4 comments

Hi,
Really great plugin. I need some help. I have a field in database named 'status' which stores values for '1' for Active and '0' for Inactive . I have stored these in a variable. $boolean_values_status = array(1 => "Active", "0" => "Inactive");
So when i download the data, status comes as either 1 or 0. How can i make it print as 'Active' for 1 and 'Inactive' for 0.

translate it prior to passing it to the view:

$status = ($status == 1 ? 'active' : 'inactive');

I would do as @dereuromark says. Doing it within the view could become really weird in terms of the logic that would need to be written.

csvview

I have tried translating it prior to passing it to the view. But I could not achieve success. This is the snapshot of the code that I use currently excluding the translation part. Please suggest necessary changes.

public function admin_export() {
$results = $this->User->find('all', array('conditions' => array('User.group_id' => 2)));
$this->response->download('Export '.date('d-m-Y').'.csv');
$_serialize = 'results';
$_header = array('First name', 'Last name', 'Email', 'Phone', 'Address1', 'Address2', 'City', 'State', 'Country', 'Notes','Status');
$_extract = array('User.firstname', 'User.lastname', 'User.email', 'User.phone', 'User.address1', 'User.address2', 'User.city', 'User.state', 'Country.name', 'User.notes', 'User.status');
$this->viewClass = 'CsvView.Csv';
$_newline= ' ';
$this->set(compact('results', '_serialize', '_header', '_extract', '_newline'));
}}

@shainanand you need to iterate over $results and modify the records manually.