Jump to:

23479 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » compare two csv files in modeladmin interface

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 414 Views
  • sajok
    Avatar
    Community Member
    82 Posts

    compare two csv files in modeladmin interface Link to this post

    Hello,

    I know SS has the ability to import csv files and show results. In my case I want to compare two csv files and show the records that match. I assume this would need two upload fields and converting the csv data to arrays which need to be compared. If this is the best way, can someone give an example how to do that on silverstripe?

    thanks in advance.

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: compare two csv files in modeladmin interface Link to this post

    SilverStripe also has a Diff library bundled (framework/core/Diff.php) which is used for showing diffs between page versions (DataDifferencer), haven't used it too much so I personally can't help much but take a look to see if those classes can help.

    http://api.silverstripe.org/3.0/framework/misc/DataDifferencer.html

    The usage of that is something like

    function getDifferences() {
    $obj1 = DataObject::get_one('Member');
    $obj2 = DataObject::get_one('Member');

    return new DataDifferencer($obj1, $obj2);
    }

    // then in the template
    <% with Differences %>
    <% loop ChangedFields %>
    <dt>$Title</dt>
    <dd>$Diff</dd>
    <% end_loop %>
    <% end_with %>

    How you get that displayed to the user depends on your use case. You could embed the template as a FormField within model admin or a separate controller would work.

    414 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.