public function getSummary() { $txt = ''; if ($this->groupHistoryModel->getIsNew()) { $txt .= 'New! ' . "\n"; } if ($this->groupHistoryModel->isAnyChangeFlagsUnknown()) { $txt .= $this->groupHistoryModel->getDescription(); } else { if ($this->groupHistoryModel->getTitleChanged()) { $txt .= 'Title Changed. ' . "\n"; } if ($this->groupHistoryModel->getDescriptionChanged()) { $txt .= 'Description Changed. ' . "\n"; } if ($this->groupHistoryModel->getUrlChanged()) { $txt .= 'URL Changed. ' . "\n"; } if ($this->groupHistoryModel->getTwitterUsernameChanged()) { $txt .= 'Twitter Changed. ' . "\n"; } if ($this->groupHistoryModel->getIsDeletedChanged()) { $txt .= 'Deleted Changed: ' . ($this->groupHistoryModel->getIsDeleted() ? "Deleted" : "Restored") . "\n\n"; } } return $txt; }
function testSetChangedFlagsFromLast3() { $lastHistory = new GroupHistoryModel(); $lastHistory->setFromDataBaseRow(array('group_id' => 1, 'title' => 'Cat', 'description' => 'no dogs allowed', 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'url' => 'http://www.groupwithnoname.com', 'twitter_username' => 'noname', 'is_deleted' => 0, 'title_changed' => 0, 'description_changed' => 0, 'url_changed' => 0, 'twitter_username_changed' => 0, 'is_deleted_changed' => 0)); $groupHistory = new GroupHistoryModel(); $groupHistory->setFromDataBaseRow(array('group_id' => 1, 'title' => 'Cat', 'description' => 'no dogs allowed', 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'url' => 'http://www.groupwithnoname.com', 'twitter_username' => 'noname', 'is_deleted' => 1, 'title_changed' => 0, 'description_changed' => 0, 'url_changed' => 0, 'twitter_username_changed' => 0, 'is_deleted_changed' => 0)); $groupHistory->setChangedFlagsFromLast($lastHistory); $this->assertEquals(false, $groupHistory->getTitleChanged()); $this->assertEquals(false, $groupHistory->getDescriptionChanged()); $this->assertEquals(false, $groupHistory->getUrlChanged()); $this->assertEquals(false, $groupHistory->getTwitterUsernameChanged()); $this->assertEquals(true, $groupHistory->getIsDeletedChanged()); $this->assertEquals(false, $groupHistory->getIsNew()); }
public function ensureChangedFlagsAreSet(GroupHistoryModel $groupHistory) { global $DB; // do we already have them? if (!$groupHistory->isAnyChangeFlagsUnknown()) { return; } // load last. $stat = $DB->prepare("SELECT * FROM group_history WHERE group_id = :id AND created_at < :at " . "ORDER BY created_at DESC"); $stat->execute(array('id' => $groupHistory->getId(), 'at' => $groupHistory->getCreatedAt()->format("Y-m-d H:i:s"))); if ($stat->rowCount() == 0) { $groupHistory->setChangedFlagsFromNothing(); } else { while ($groupHistory->isAnyChangeFlagsUnknown() && ($lastHistoryData = $stat->fetch())) { $lastHistory = new GroupHistoryModel(); $lastHistory->setFromDataBaseRow($lastHistoryData); $groupHistory->setChangedFlagsFromLast($lastHistory); } } // Save back to DB $sqlFields = array(); $sqlParams = array('id' => $groupHistory->getId(), 'created_at' => $groupHistory->getCreatedAt()->format("Y-m-d H:i:s"), 'is_new' => $groupHistory->getIsNew() ? 1 : 0); if ($groupHistory->getTitleChangedKnown()) { $sqlFields[] = " title_changed = :title_changed "; $sqlParams['title_changed'] = $groupHistory->getTitleChanged() ? 1 : -1; } if ($groupHistory->getDescriptionChangedKnown()) { $sqlFields[] = " description_changed = :description_changed "; $sqlParams['description_changed'] = $groupHistory->getDescriptionChanged() ? 1 : -1; } if ($groupHistory->getUrlChangedKnown()) { $sqlFields[] = " url_changed = :url_changed "; $sqlParams['url_changed'] = $groupHistory->getUrlChanged() ? 1 : -1; } if ($groupHistory->getTwitterUsernameChangedKnown()) { $sqlFields[] = " twitter_username_changed = :twitter_username_changed "; $sqlParams['twitter_username_changed'] = $groupHistory->getTwitterUsernameChanged() ? 1 : -1; } if ($groupHistory->getIsDuplicateOfIdChangedKnown()) { $sqlFields[] = " is_duplicate_of_id_changed = :is_duplicate_of_id_changed "; $sqlParams['is_duplicate_of_id_changed'] = $groupHistory->getIsDuplicateOfIdChangedKnown() ? 1 : -1; } if ($groupHistory->getIsDeletedChangedKnown()) { $sqlFields[] = " is_deleted_changed = :is_deleted_changed "; $sqlParams['is_deleted_changed'] = $groupHistory->getIsDeletedChanged() ? 1 : -1; } $statUpdate = $DB->prepare("UPDATE group_history SET " . " is_new = :is_new, " . implode(" , ", $sqlFields) . " WHERE group_id = :id AND created_at = :created_at"); $statUpdate->execute($sqlParams); }