/** * Returns the changes for a given record in a particular language, since * a given version number. * @param Dataface_Record &$record The record we are interested in. * @param string $language 2-digit language code * @param float $version <major_version>.<minor_version> * @param string $fieldname Optional field name to get changes for. * @returns mixed Either a Dataface_Record object with the changes, or * a string with the changes for $fieldname. * */ function getChanges(&$record, $version, $lang = null, $fieldname = null) { $app = Dataface_Application::getInstance(); if (!isset($lang)) { $lang = $app->_conf['lang']; } list($major_version, $minor_version) = explode('.', $version); $trecord = $this->getTranslationRecord($record, $lang); import('Dataface/HistoryTool.php'); $ht = new Dataface_HistoryTool(); $hrecord = $ht->searchArchives($trecord, array('major_version' => $major_version, 'minor_version' => $minor_version), $lang); $modified = $hrecord->strval('history__modified'); return $ht->getDiffsByDate($record, $modified, null, $lang, $fieldname); }
function test_diffs_by_date() { $this->test_diff(); $app =& Dataface_Application::getInstance(); $profile =& df_get_record('Profiles', array('id' => 10)); $profile->setValue('description', 'Head of your household'); $profile->save(); $ht = new Dataface_HistoryTool(); $ht->logRecord($profile); $sql[] = "update `Profiles__history` set `history__modified`='2005-12-10 12:23:00' where `history__id`=1"; $sql[] = "update `Profiles__history` set `history__modified`='2006-05-04 12:22:00' where `history__id`=2"; $sql[] = "update `Profiles__history` set `history__modified`='2006-05-05 12:21:00' where `history__id`=3"; foreach ($sql as $query) { $res = xf_db_query($query, $app->db()); if (!$res) { trigger_error(xf_db_error($app->db()), E_USER_ERROR); } } $diff = $ht->getDiffsByDate($profile, '2006-01-01'); $this->assertEquals('Head of <del>the</del><ins>your</ins> household ', $diff->val('description')); $diff = $ht->getDiffsByDate($profile, '2006-05-04 12:22:00'); //print_r($diff->strvals()); $this->assertEquals('Head of <del>this</del><ins>your</ins> household<del> And more He is also a great fisherman</del> ', $diff->val('description')); $diff = $ht->getDiffsByDate($profile, '2006-05-04', '2006-05-06'); $this->assertEquals('Head of <del>the</del><ins>my</ins> household<ins> And more He is also a greater fisherman</ins> ', $diff->val('description')); //print_r($diff->strvals()); }