static function create($definition, $lexemIds) { $diffSize = 0; $sr = new SimilarRecord(); $sr->source = SimilarSource::getSimilarSource($definition->sourceId); $sr->definition = $definition->loadSimilar($lexemIds, $diffSize); if ($sr->definition) { $sr->htmlDiff = LDiff::htmlDiff($sr->definition->internalRep, $definition->internalRep, true); } else { $sr->htmlDiff = null; } $sr->identical = $sr->definition && $diffSize == 0; return $sr; }
function loadSimilar($lexemIds, &$diffSize = null) { $result = null; // First see if there is a similar source $similarSource = SimilarSource::getSimilarSource($this->sourceId); if ($similarSource && count($lexemIds)) { // Load all definitions from $similarSource mapped to any of $lexemIds $candidates = Model::factory('Definition')->table_alias('d')->select('d.*')->distinct()->join('LexemDefinitionMap', 'ldm.definitionId = d.id', 'ldm')->where_not_equal('d.status', self::ST_DELETED)->where('d.sourceId', $similarSource->id)->where_in('ldm.lexemId', $lexemIds)->find_many(); // Find the definition with the minimum diff from the original $diffSize = 0; foreach ($candidates as $d) { $size = LDiff::diffMeasure($this->internalRep, $d->internalRep); if (!$result || $size < $diffSize) { $result = $d; $diffSize = $size; } } } return $result; }
foreach ($recordSet as $row) { $changeSet = $row; $changeSet['changesCount'] = 0; if ($row['OldUserId'] !== $row['NewUserId']) { $changeSet['changesCount']++; } if ($row['OldSourceId'] !== $row['NewSourceId']) { $changeSet['changesCount']++; } if ($row['OldStatus'] !== $row['NewStatus']) { $changeSet['OldStatusName'] = $statuses[$row['OldStatus']]; $changeSet['NewStatusName'] = $statuses[$row['NewStatus']]; $changeSet['changesCount']++; } if ($row['OldLexicon'] !== $row['NewLexicon']) { $changeSet['changesCount']++; } if ($row['OldModUserId'] !== $row['NewModUserId']) { $changeSet['changesCount']++; } if ($row['OldInternalRep'] !== $row['NewInternalRep']) { $changeSet['diff'] = LDiff::htmlDiff($row['OldInternalRep'], $row['NewInternalRep']); $changeSet['changesCount']++; } if ($changeSet['changesCount'] > 0) { $changeSets[] = $changeSet; } } SmartyWrap::assign('def', $def); SmartyWrap::assign('changeSets', $changeSets); SmartyWrap::display('istoria-definitiei.tpl');