GetText() == ''); } /** * @inheritDoc * * @param ormCaseLog $proposedValue */ public function HasAValue($proposedValue): bool { // Protection against wrong value type if (false === ($proposedValue instanceof ormCaseLog)) { return parent::HasAValue($proposedValue); } // We test if there is at least 1 entry in the log, not if the user is adding one return $proposedValue->GetEntryCount() > 0; } public function ScalarToSQL($value) { if (!is_string($value) && !is_null($value)) { throw new CoreWarning('Expected the attribute value to be a string', array( 'found_type' => gettype($value), 'value' => $value, 'class' => $this->GetCode(), 'attribute' => $this->GetHostClass(), )); } return $value; } public function GetEditClass() { return "CaseLog"; } public function GetEditValue($sValue, $oHostObj = null) { if (!($sValue instanceof ormCaseLog)) { return ''; } return $sValue->GetModifiedEntry(); } /** * For fields containing a potential markup, return the value without this markup * * @param mixed $value * @param \DBObject $oHostObj * * @return string */ public function GetAsPlainText($value, $oHostObj = null) { if ($value instanceof ormCaseLog) { /** ormCaseLog $value */ return $value->GetAsPlainText(); } else { return (string)$value; } } public function GetDefaultValue(DBObject $oHostObject = null) { return new ormCaseLog(); } public function Equals($val1, $val2) { return ($val1->GetText() == $val2->GetText()); } /** * Facilitate things: allow the user to Set the value from a string * * @param $proposedValue * @param DBObject $oHostObj * * @return mixed|null|ormCaseLog|string * @throws Exception */ public function MakeRealValue($proposedValue, $oHostObj) { if ($proposedValue instanceof ormCaseLog) { // Passthrough $ret = clone $proposedValue; } else { // Append the new value if an instance of the object is supplied // $oPreviousLog = null; if ($oHostObj != null) { $oPreviousLog = $oHostObj->Get($this->GetCode()); if (!is_object($oPreviousLog)) { $oPreviousLog = $oHostObj->GetOriginal($this->GetCode());; } } if (is_object($oPreviousLog)) { $oCaseLog = clone($oPreviousLog); } else { $oCaseLog = new ormCaseLog(); } if ($proposedValue instanceof stdClass) { $oCaseLog->AddLogEntryFromJSON($proposedValue); } else { if (utils::StrLen($proposedValue) > 0) { //N°5135 - add impersonation information in caselog if (UserRights::IsImpersonated()) { $sOnBehalfOf = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUserFriendlyName(), UserRights::GetUserFriendlyName()); $oCaseLog->AddLogEntry($proposedValue, $sOnBehalfOf, UserRights::GetConnectedUserId()); } else { $oCaseLog->AddLogEntry($proposedValue); } } } $ret = $oCaseLog; } return $ret; } public function GetSQLExpressions($sPrefix = '') { if ($sPrefix == '') { $sPrefix = $this->Get('sql'); } $aColumns = array(); // Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix $aColumns[''] = $sPrefix; $aColumns['_index'] = $sPrefix.'_index'; return $aColumns; } /** * @param array $aCols * @param string $sPrefix * * @return ormCaseLog * @throws MissingColumnException */ public function FromSQLToValue($aCols, $sPrefix = '') { if (!array_key_exists($sPrefix, $aCols)) { $sAvailable = implode(', ', array_keys($aCols)); throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}"); } $sLog = $aCols[$sPrefix]; if (isset($aCols[$sPrefix.'_index'])) { $sIndex = $aCols[$sPrefix.'_index']; } else { // For backward compatibility, allow the current state to be: 1 log, no index $sIndex = ''; } if (strlen($sIndex) > 0) { $aIndex = unserialize($sIndex); $value = new ormCaseLog($sLog, $aIndex); } else { $value = new ormCaseLog($sLog); } return $value; } public function GetSQLValues($value) { if (!($value instanceof ormCaseLog)) { $value = new ormCaseLog(''); } $aValues = array(); $aValues[$this->GetCode()] = $value->GetText(); $aValues[$this->GetCode().'_index'] = serialize($value->GetIndex()); return $aValues; } public function GetSQLColumns($bFullSpec = false) { $aColumns = array(); $aColumns[$this->GetCode()] = 'LONGTEXT' // 2^32 (4 Gb) .CMDBSource::GetSqlStringColumnDefinition(); $aColumns[$this->GetCode().'_index'] = 'BLOB'; return $aColumns; } public function GetAsHTML($value, $oHostObject = null, $bLocalize = true) { if ($value instanceof ormCaseLog) { $sContent = $value->GetAsHTML(null, false, array(__class__, 'RenderWikiHtml')); } else { $sContent = ''; } $aStyles = array(); if ($this->GetWidth() != '') { $aStyles[] = 'width:'.$this->GetWidth(); } if ($this->GetHeight() != '') { $aStyles[] = 'height:'.$this->GetHeight(); } $sStyle = ''; if (count($aStyles) > 0) { $sStyle = 'style="'.implode(';', $aStyles).'"'; } return "