Bläddra i källkod

#783 Added the placeholder $this->xxx_list$ for emailing (names separated by a new line, truncated to 100 items)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2921 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 år sedan
förälder
incheckning
8a00a05b1a
2 ändrade filer med 41 tillägg och 7 borttagningar
  1. 8 0
      core/config.class.inc.php
  2. 33 7
      core/dbobject.class.php

+ 8 - 0
core/config.class.inc.php

@@ -651,6 +651,14 @@ class Config
 			'source_of_value' => '',
 			'show_in_conf_sample' => false,
 		),
+		'max_linkset_output' => array(
+			'type' => 'integer',
+			'description' => 'Maximum number of items shown when getting a list of related items in an email, using the form $this->some_list$. 0 means no limit.',
+			'default' => 100,
+			'value' => 100,
+			'source_of_value' => '',
+			'show_in_conf_sample' => true,
+		),
 	);
 
 	public function IsProperty($sPropCode)

+ 33 - 7
core/dbobject.class.php

@@ -1899,20 +1899,46 @@ abstract class DBObject
 			$sClass = get_class($this);
 			foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
 			{
-				$aScalarArgs[$sArgName.'->'.$sAttCode] = $this->Get($sAttCode);
-				if ($oAttDef->IsScalar())
+				if ($oAttDef instanceof AttributeCaseLog)
 				{
+					$oCaseLog = $this->Get($sAttCode);
+					$aScalarArgs[$sArgName.'->'.$sAttCode] = $oCaseLog->GetText();
+					$aScalarArgs[$sArgName.'->head('.$sAttCode.')'] = $oCaseLog->GetLatestEntry();
+				}
+				elseif ($oAttDef->IsScalar())
+				{
+					$aScalarArgs[$sArgName.'->'.$sAttCode] = $this->Get($sAttCode);
 					// #@# Note: This has been proven to be quite slow, this can slow down bulk load
 					$sAsHtml = $this->GetAsHtml($sAttCode);
 					$aScalarArgs[$sArgName.'->html('.$sAttCode.')'] = $sAsHtml;
 					$aScalarArgs[$sArgName.'->label('.$sAttCode.')'] = $this->GetEditValue($sAttCode); // "Nice" display value, but without HTML tags and entities
 				}
-				// Do something for case logs... quick N' dirty...
-				if ($aScalarArgs[$sArgName.'->'.$sAttCode] instanceof ormCaseLog)
+				elseif ($oAttDef->IsLinkSet())
 				{
-					$oCaseLog = $aScalarArgs[$sArgName.'->'.$sAttCode];
-					$aScalarArgs[$sArgName.'->'.$sAttCode] = $oCaseLog->GetText();
-					$aScalarArgs[$sArgName.'->head('.$sAttCode.')'] = $oCaseLog->GetLatestEntry();
+					$sRemoteName = $oAttDef->IsIndirect() ? $oAttDef->GetExtKeyToRemote().'_friendlyname' : 'friendlyname';
+
+					// Since we want to limit the number of item, it is not feasible to simply rely on Get() to build the link set
+					// $oLinkSet = $this->Get($sAttCode);
+					$sLinkedClass = $oAttDef->GetLinkedClass();
+					$sExtKeyToMe = $oAttDef->GetExtKeyToMe();
+					$oSearch = DBObjectSearch::FromOQL("SELECT $sLinkedClass WHERE $sExtKeyToMe = :this");
+					$oLinkSet = new DBObjectSet($oSearch, array(), array('this' => $this->GetKey()));
+					$iLimit = MetaModel::GetConfig()->Get('max_linkset_output');
+					if ($iLimit > 0)
+					{
+						$oLinkSet->SetLimit($iLimit);
+					}
+					$aNames = $oLinkSet->GetColumnAsArray($sRemoteName);
+					if ($iLimit > 0)
+					{
+						$iTotal = $oLinkSet->Count();
+						if ($iTotal > count($aNames))
+						{
+							$aNames[] = '... '.Dict::Format('UI:TruncatedResults', count($aNames), $iTotal);
+						}
+					}
+					$sNames = implode("\n", $aNames);
+					$aScalarArgs[$sArgName.'->'.$sAttCode] = $sNames;
 				}
 			}