瀏覽代碼

Implement the iDisplay interface on any class derived from DBObject, but also limit the possible actions on such objects (disable edition)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3156 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 11 年之前
父節點
當前提交
2e975aafb5
共有 3 個文件被更改,包括 71 次插入40 次删除
  1. 0 33
      application/cmdbabstract.class.inc.php
  2. 5 6
      application/displayblock.class.inc.php
  3. 66 1
      core/dbobject.class.php

+ 0 - 33
application/cmdbabstract.class.inc.php

@@ -43,39 +43,6 @@ require_once(APPROOT.'/application/ui.extkeywidget.class.inc.php');
 require_once(APPROOT.'/application/ui.htmleditorwidget.class.inc.php');
 require_once(APPROOT.'/application/datatable.class.inc.php');
 
-/**
- * All objects to be displayed in the application (either as a list or as details)
- * must implement this interface.
- */
-interface iDisplay
-{
-
-	/**
-	 * Maps the given context parameter name to the appropriate filter/search code for this class
-	 * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
-	 * @return string Filter code, i.e. 'customer_id'
-	 */
-	public static function MapContextParam($sContextParam);
-	/**
-	 * This function returns a 'hilight' CSS class, used to hilight a given row in a table
-	 * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
-	 * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
-	 * To Be overridden by derived classes
-	 * @param void
-	 * @return String The desired higlight class for the object/row
-	 */
-	public function GetHilightClass();
-	/**
-	 * Returns the relative path to the page that handles the display of the object
-	 * @return string
-	 */
-	public static function GetUIPage();
-	/**
-	 * Displays the details of the object
-	 */
-	public function DisplayDetails(WebPage $oPage, $bEditMode = false);
-}
-
 abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
 {
 	protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)

+ 5 - 6
application/displayblock.class.inc.php

@@ -1350,6 +1350,7 @@ class MenuBlock extends DisplayBlock
 			$sContext = '&'.$sContext;
 		}
 		$sClass = $this->m_oFilter->GetClass();
+		$oReflectionClass = new ReflectionClass($sClass);
 		$oSet = new CMDBObjectSet($this->m_oFilter);
 		$sFilter = $this->m_oFilter->serialize();
 		$sFilterDesc = $this->m_oFilter->ToOql(true);
@@ -1369,7 +1370,7 @@ class MenuBlock extends DisplayBlock
 				$sDefault.= "&default[$sKey]=$sValue";
 			}
 		}
-		$bIsCreationAllowed =  (UserRights::IsActionAllowed($sClass, UR_ACTION_CREATE) == UR_ALLOWED_YES);
+		$bIsCreationAllowed =  (UserRights::IsActionAllowed($sClass, UR_ACTION_CREATE) == UR_ALLOWED_YES) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject'));
 		switch($oSet->Count())
 		{
 			case 0:
@@ -1380,10 +1381,8 @@ class MenuBlock extends DisplayBlock
 			case 1:
 			$oObj = $oSet->Fetch();
 			$id = $oObj->GetKey();
-			$bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES);
+			$bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject'));
 			$bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet);
-			$bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet);
-			$bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet);
 			// Just one object in the set, possible actions are "new / clone / modify and delete"
 			if (!isset($aExtraParams['link_attr']))
 			{
@@ -1449,8 +1448,8 @@ class MenuBlock extends DisplayBlock
 			default:
 			// Check rights
 			// New / Modify
-			$bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet);
-			$bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet);
+			$bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject'));
+			$bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject'));
 			$bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet);
 			if (isset($aExtraParams['link_attr']))
 			{

+ 66 - 1
core/dbobject.class.php

@@ -17,6 +17,39 @@
 //   along with iTop. If not, see <http://www.gnu.org/licenses/>
 
 /**
+ * All objects to be displayed in the application (either as a list or as details)
+ * must implement this interface.
+ */
+interface iDisplay
+{
+
+	/**
+	 * Maps the given context parameter name to the appropriate filter/search code for this class
+	 * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
+	 * @return string Filter code, i.e. 'customer_id'
+	 */
+	public static function MapContextParam($sContextParam);
+	/**
+	 * This function returns a 'hilight' CSS class, used to hilight a given row in a table
+	 * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
+	 * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
+	 * To Be overridden by derived classes
+	 * @param void
+	 * @return String The desired higlight class for the object/row
+	 */
+	public function GetHilightClass();
+	/**
+	 * Returns the relative path to the page that handles the display of the object
+	 * @return string
+	 */
+	public static function GetUIPage();
+	/**
+	 * Displays the details of the object
+	 */
+	public function DisplayDetails(WebPage $oPage, $bEditMode = false);
+}
+
+/**
  * Class dbObject: the root of persistent classes
  *
  * @copyright   Copyright (C) 2010-2012 Combodo SARL
@@ -33,7 +66,7 @@ require_once('mutex.class.inc.php');
  *
  * @package     iTopORM
  */
-abstract class DBObject
+abstract class DBObject implements iDisplay
 {
 	private static $m_aMemoryObjectsByClass = array();
 
@@ -2493,5 +2526,37 @@ abstract class DBObject
 		}
 		return false;
 	}
+	/////////////////////////////////////////////////////////////////////////
+	//
+	// Experimental iDisplay implementation
+	//
+	/////////////////////////////////////////////////////////////////////////
+	
+	public static function MapContextParam($sContextParam)
+	{
+		return null;
+	}
+	
+	public function GetHilightClass()
+	{
+		return HILIGHT_CLASS_NONE;
+	}
+
+	public function DisplayDetails(WebPage $oPage, $bEditMode = false)
+	{
+		$oPage->add('<h1>'.MetaModel::GetName(get_class($this)).': '.$this->GetName().'</h1>');
+		$aValues = array();
+		$aList = MetaModel::FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
+		if (empty($aList))
+		{
+			$aList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
+		}
+		foreach($aList as $sAttCode)
+		{
+			$aValues[$sAttCode] = array('label' => MetaModel::GetLabel(get_class($this), $sAttCode), 'value' => $this->GetAsHTML($sAttCode));
+		}
+		$oPage->details($aValues);
+	}
+	
 }