Giter Club home page Giter Club logo

Comments (10)

kyleweishaupt avatar kyleweishaupt commented on June 3, 2024

I'm on the same page. Having trouble getting DATETIMES to export as well.

from cakephp-csvview.

josegonzalez avatar josegonzalez commented on June 3, 2024

Maybe its not being casted to a string properly?

from cakephp-csvview.

kyleweishaupt avatar kyleweishaupt commented on June 3, 2024

I got around this for now by creating a virtual field in my entity that returned as a string:

protected function _getCreatedString() {
return (string) $this->_properties['created']; }

Then I just used the created_string property with $_extract and it worked.

from cakephp-csvview.

josegonzalez avatar josegonzalez commented on June 3, 2024

What is the type of that field? Perhaps CsvView should cast everything to a string before exporting, though that might slow down performance.

from cakephp-csvview.

kyleweishaupt avatar kyleweishaupt commented on June 3, 2024

The created field is the typical nullable DATETIME that's compatible with the Timestamp behavior.

from cakephp-csvview.

carlo-arellano avatar carlo-arellano commented on June 3, 2024

Hi @kyleweishaupt how can I properly used the added virtual field at $_extract? Can you please post a sample code? I still getting a null value. Thanks!

from cakephp-csvview.

dereuromark avatar dereuromark commented on June 3, 2024

I found the issue and will provide a fix in a few minutes.

PS: Any idea why the default for NULL columns is actually 'NULL'? Shouldnt it rather be empty string?
Overwriting this every time is kind of a PITA.

from cakephp-csvview.

kyleweishaupt avatar kyleweishaupt commented on June 3, 2024

@aguirre1017 All I did was add the name of the virtual field in the $_extract array. Here's what mine looks like:

$_extract = [
'id', 
'user.full_name', 
'name',
'email',
'notes',
'follow_up_date_timestamp',
'created_timestamp',
'modified_timestamp'
];

So instead of using just the created field, I used created_timestamp that is being created in the entity class.

Here is the code in my entity:

protected $_virtual = [
    'follow_up_date_timestamp',
    'created_timestamp',
    'modified_timestamp'
];      

protected function _getFollowUpDateTimestamp()
{
    return (!empty($this->_properties['follow_up_date'])) ? (string) $this->_properties['follow_up_date'] : null;
}

protected function _getCreatedTimestamp()
{
    return (!empty($this->_properties['created'])) ? (string) $this->_properties['created'] : null;
} 

protected function _getModifiedTimestamp()
{
    return (!empty($this->_properties['modified'])) ? (string) $this->_properties['modified'] : null;
}

Hope this helps for you!

from cakephp-csvview.

dereuromark avatar dereuromark commented on June 3, 2024

This is a nice hack, but quite some overhead for an issue that maybe could be fixed in a more central place. Imagine you want to export multiple tables/entities.

from cakephp-csvview.

dereuromark avatar dereuromark commented on June 3, 2024

Resolved with my PR #55 .

from cakephp-csvview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.