public function getSummary()
 {
     $txt = '';
     if ($this->tagHistoryModel->getIsNew()) {
         $txt .= 'New! ' . "\n";
     }
     if ($this->tagHistoryModel->isAnyChangeFlagsUnknown()) {
         $txt .= $this->tagHistoryModel->getDescription();
     } else {
         if ($this->tagHistoryModel->getTitleChanged()) {
             $txt .= 'Title Changed. ' . "\n";
         }
         if ($this->tagHistoryModel->getDescriptionChanged()) {
             $txt .= 'Description Changed. ' . "\n";
         }
         if ($this->tagHistoryModel->getIsDeletedChanged()) {
             $txt .= 'Deleted Changed: ' . ($this->tagHistoryModel->getIsDeleted() ? "Deleted" : "Restored") . "\n\n";
         }
     }
     return $txt;
 }
 public function ensureChangedFlagsAreSet(TagHistoryModel $tagHistory)
 {
     global $DB;
     // do we already have them?
     if (!$tagHistory->isAnyChangeFlagsUnknown()) {
         return;
     }
     // load last.
     $stat = $DB->prepare("SELECT * FROM tag_history WHERE tag_id = :id AND created_at < :at " . "ORDER BY created_at DESC");
     $stat->execute(array('id' => $tagHistory->getId(), 'at' => $tagHistory->getCreatedAt()->format("Y-m-d H:i:s")));
     // Apply what we know
     if ($stat->rowCount() == 0) {
         $tagHistory->setChangedFlagsFromNothing();
     } else {
         while ($tagHistory->isAnyChangeFlagsUnknown() && ($lastHistoryData = $stat->fetch())) {
             $lastHistory = new TagHistoryModel();
             $lastHistory->setFromDataBaseRow($lastHistoryData);
             $tagHistory->setChangedFlagsFromLast($lastHistory);
         }
     }
     // Save back to DB
     $sqlFields = array();
     $sqlParams = array('id' => $tagHistory->getId(), 'created_at' => $tagHistory->getCreatedAt()->format("Y-m-d H:i:s"), 'is_new' => $tagHistory->getIsNew() ? 1 : 0);
     if ($tagHistory->getTitleChangedKnown()) {
         $sqlFields[] = " title_changed = :title_changed ";
         $sqlParams['title_changed'] = $tagHistory->getTitleChanged() ? 1 : -1;
     }
     if ($tagHistory->getDescriptionChangedKnown()) {
         $sqlFields[] = " description_changed = :description_changed ";
         $sqlParams['description_changed'] = $tagHistory->getDescriptionChanged() ? 1 : -1;
     }
     if ($tagHistory->getIsDeletedChangedKnown()) {
         $sqlFields[] = " is_deleted_changed = :is_deleted_changed ";
         $sqlParams['is_deleted_changed'] = $tagHistory->getIsDeletedChanged() ? 1 : -1;
     }
     $statUpdate = $DB->prepare("UPDATE tag_history SET " . " is_new = :is_new, " . implode(" , ", $sqlFields) . " WHERE tag_id = :id AND created_at = :created_at");
     $statUpdate->execute($sqlParams);
 }