m_sLog = $sLog;
$this->m_aIndex = $aIndex;
}
public function GetText()
{
return $this->m_sLog;
}
public function GetIndex()
{
return $this->m_aIndex;
}
public function __toString()
{
return $this->m_sLog;
}
public function GetAsHTML(WebPage $oP = null, $bEditMode = false, $aTransfoHandler = null)
{
$sHtml = '';
$iPos = 0;
for($index=count($this->m_aIndex)-1 ; $index >= 0 ; $index--)
{
if ($index < count($this->m_aIndex) - CASELOG_VISIBLE_ITEMS)
{
$sOpen = '';
$sDisplay = 'style="display:none;"';
}
else
{
$sOpen = ' open';
$sDisplay = '';
}
$iPos += $this->m_aIndex[$index]['separator_length'];
$sTextEntry = substr($this->m_sLog, $iPos, $this->m_aIndex[$index]['text_length']);
$sTextEntry = str_replace("\n", "
", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
if (!is_null($aTransfoHandler))
{
$sTextEntry = call_user_func($aTransfoHandler, $sTextEntry);
}
$iPos += $this->m_aIndex[$index]['text_length'];
$sEntry = '
';
$sEntry .= '';
$sEntry .= $sTextEntry;
$sEntry .= '
';
$sHtml = $sHtml.$sEntry;
}
// Process the case of an eventual remainder (quick migration of AttributeText fields)
if ($iPos < (strlen($this->m_sLog) - 1))
{
$sTextEntry = substr($this->m_sLog, $iPos);
$sTextEntry = str_replace("\n", "
", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
if (!is_null($aTransfoHandler))
{
$sTextEntry = call_user_func($aTransfoHandler, $sTextEntry);
}
if (count($this->m_aIndex) == 0)
{
$sHtml .= "$sTextEntry
\n";
}
else
{
if (count($this->m_aIndex) - CASELOG_VISIBLE_ITEMS > 0)
{
$sOpen = '';
$sDisplay = 'style="display:none;"';
}
else
{
$sOpen = ' open';
$sDisplay = '';
}
$sHtml .= '';
$sHtml .= '';
$sHtml .= $sTextEntry;
$sHtml .= '
';
}
}
return $sHtml;
}
/**
* Add a new entry to the log and updates the internal index
* @param $sText string The text of the new entry
*/
public function AddLogEntry($sText)
{
$sDate = date(Dict::S('UI:CaseLog:DateFormat'));
$sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, UserRights::GetUserFriendlyName(), UserRights::GetUserId());
$iSepLength = strlen($sSeparator);
$iTextlength = strlen($sText);
$this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
$this->m_aIndex[] = array(
'user_name' => UserRights::GetUserFriendlyName(),
'user_id' => UserRights::GetUserId(),
'date' => new DateTime(),
'text_length' => $iTextlength,
'separator_length' => $iSepLength,
);
}
/**
* Get the latest entry from the log
* @return string
*/
public function GetLatestEntry()
{
$iLast = count($this->m_aIndex) - 1;
$aLastEntry = $this->m_aIndex[$iLast];
$sRes = substr($this->m_sLog, $aLastEntry['separator_length'], $aLastEntry['text_length']);
return $sRes;
}
/**
* Get the index of the latest entry from the log
* @return integer
*/
public function GetLatestEntryIndex()
{
$iLast = count($this->m_aIndex) - 1;
return $iLast;
}
}
?>