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

SVN:trunk[3156]
This commit is contained in:
Denis Flaven
2014-05-16 05:01:45 +00:00
parent 317344da2e
commit 196fba7d81
3 changed files with 71 additions and 40 deletions

View File

@@ -16,6 +16,39 @@
// You should have received a copy of the GNU Affero General Public License
// 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
*
@@ -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);
}
}