SilverStripe 3.0 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
Version: master
  • master
  • 3.1
  • 3.0
  • 2.4
  • tagfield

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • content
    • control
    • controller
    • controllers
    • core
    • export
    • filesystem
    • forms
    • model
    • publishers
    • reports
    • search
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • framework
    • admin
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • fields-relational
    • filesystem
    • formatters
    • forms
    • gridfield
    • i18n
    • injector
    • integration
    • manifest
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • validation
    • view
  • None
  • PHP

Classes

  • ArrayLib
  • BBCodeParser
  • Convert
  • Cookie
  • DataDifferencer
  • HTMLCleaner
  • HTTP
  • i18n
  • Profiler
  • PurifierHTMLCleaner
  • ShortcodeParser
  • SSHTMLBBCodeParser
  • SSHTMLBBCodeParser_Filter
  • SSHTMLBBCodeParser_Filter_Basic
  • SSHTMLBBCodeParser_Filter_EmailLinks
  • SSHTMLBBCodeParser_Filter_Extended
  • SSHTMLBBCodeParser_Filter_Images
  • SSHTMLBBCodeParser_Filter_Links
  • SSHTMLBBCodeParser_Filter_Lists
  • TextParser
  • TidyHTMLCleaner

Class DataDifferencer

Utility class to render views of the differences between two data objects (or two versions of the same data object).

Construcing a diff object is done as follows:

$fromRecord = Versioned::get_version('SiteTree', $pageID, $fromVersion);
$toRecord = Versioned::get_version('SiteTree, $pageID, $toVersion);
$diff = new DataDifferencer($fromRecord, $toRecord);

And then it can be used in a number of ways. You can use the ChangedFields() method in a template:

<dl class="diff">
<% with Diff %>
<% loop ChangedFields %>
   <dt>$Title</dt>
   <dd>$Diff</dd>
<% end_loop %>
<% end_with %>
</dl>

Or you can get the diff'ed content as another DataObject, that you can insert into a form.

$form->loadDataFrom($diff->diffedData());

If there are fields whose changes you aren't interested in, you can ignore them like so:

$diff->ignoreFields('AuthorID', 'Status');
Object
Extended by ViewableData implements IteratorAggregate
Extended by DataDifferencer
Package: framework\misc
Located at sapphire/model/DataDifferencer.php

Methods summary

public
# __construct( DataObject $fromRecord, DataObject $toRecord )

Construct a DataDifferencer to show the changes between $fromRecord and $toRecord. If $fromRecord is null, this will represent a "creation".

Construct a DataDifferencer to show the changes between $fromRecord and $toRecord. If $fromRecord is null, this will represent a "creation".

Parameters

$fromRecord
DataObject
(Optional)
$toRecord
DataObject

Overrides

Object::__construct
public
# ignoreFields( mixed $ignoredFields )

Specify some fields to ignore changes from. Repeated calls are cumulative.

Specify some fields to ignore changes from. Repeated calls are cumulative.

Parameters

$ignoredFields
mixed
$ignoredFields An array of field names to ignore. Alternatively, pass the field names as separate args.
public
# diffedData( )

Get a DataObject with altered values replaced with HTML diff strings, incorporating <ins> and <del> tags.

Get a DataObject with altered values replaced with HTML diff strings, incorporating <ins> and <del> tags.

public
# ChangedFields( )

Get a SS_List of the changed fields. Each element is an array data containing
- Name: The field name
- Title: The human-readable field title
- Diff: An HTML diff showing the changes
- From: The older version of the field
- To: The newer version of the field

Get a SS_List of the changed fields. Each element is an array data containing - Name: The field name - Title: The human-readable field title - Diff: An HTML diff showing the changes - From: The older version of the field - To: The newer version of the field

public
# changedFieldNames( )

Get an array of the names of every fields that has changed. This is simpler than DataDifferencer::ChangedFields()

Get an array of the names of every fields that has changed. This is simpler than DataDifferencer::ChangedFields()

Methods inherited from ViewableData

ATT_val(), CSSClasses(), Debug(), JS_val(), Me(), RAW_val(), SQL_val(), ThemeDir(), XML_val(), __get(), __isset(), __set(), buildCastingCache(), cachedCall(), castingClass(), castingHelper(), castingHelperPair(), castingObjectCreator(), castingObjectCreatorPair(), customise(), defineMethods(), escapeTypeForField(), getField(), getIterator(), getXMLValues(), hasField(), hasValue(), obj(), renderWith(), setCustomisedObj(), setField()

Methods inherited from Object

__call(), __toString(), addMethodsFrom(), addStaticVars(), addWrapperMethod(), add_extension(), add_static_var(), allMethodNames(), cacheToFile(), clearCache(), combined_static(), config(), create(), createMethod(), create_from_string(), exists(), extend(), getCustomClass(), getExtensionInstance(), getExtensionInstances(), get_extensions(), get_extra_config_sources(), get_static(), hasExtension(), hasMethod(), has_extension(), invokeWithExtensions(), is_a(), loadCache(), parentClass(), parse_class_spec(), remove_extension(), sanitiseCachename(), saveCache(), set_stat(), set_static(), set_uninherited(), stat(), static_lookup(), strong_create(), uninherited(), uninherited_static(), useCustomClass()

Magic methods summary

Properties summary

protected mixed $fromRecord
#
protected mixed $toRecord
#
protected array $ignoredFields
#

Properties inherited from ViewableData

$casting, $customisedObject, $default_cast, $failover

Properties inherited from Object

$class, $extension_instances, $extensions

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.
blog comments powered by Disqus
SilverStripe 3.0 API Docs API documentation generated by ApiGen 2.8.0