本文整理汇总了PHP中MetaModel::IsValidClass方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::IsValidClass方法的具体用法?PHP MetaModel::IsValidClass怎么用?PHP MetaModel::IsValidClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaModel
的用法示例。
在下文中一共展示了MetaModel::IsValidClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ComputeSLT
/**
* Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
* @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
* @return hash Array with 'SLT' => name of the SLT selected, 'value' => duration in seconds of the SLT metric, null if no SLT applies to this ticket
*/
protected static function ComputeSLT($oTicket, $sMetric = 'TTO')
{
$iDeadline = null;
if (MetaModel::IsValidClass('SLT')) {
$sType = get_class($oTicket);
if ($sType == 'Incident') {
$sRequestType = 'incident';
} else {
$sRequestType = $oTicket->Get('request_type');
}
$aArgs = $oTicket->ToArgs();
$aArgs['metric'] = $sMetric;
$aArgs['request_type'] = $sRequestType;
//echo "<p>Managing:".$sMetric."-".$this->Get('request_type')."-".$this->Get('importance')."</p>\n";
$oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL(RESPONSE_TICKET_SLT_QUERY), array(), $aArgs);
$iMinDuration = PHP_INT_MAX;
$sSLTName = '';
while ($oSLT = $oSLTSet->Fetch()) {
$iDuration = (int) $oSLT->Get('value');
$sUnit = $oSLT->Get('unit');
switch ($sUnit) {
case 'days':
$iDuration = $iDuration * 24;
// 24 hours in 1 days
// Fall though
// 24 hours in 1 days
// Fall though
case 'hours':
$iDuration = $iDuration * 60;
// 60 minutes in 1 hour
// Fall though
// 60 minutes in 1 hour
// Fall though
case 'minutes':
$iDuration = $iDuration * 60;
}
if ($iDuration < $iMinDuration) {
$iMinDuration = $iDuration;
$sSLTName = $oSLT->GetName();
}
}
if ($iMinDuration == PHP_INT_MAX) {
$iDeadline = null;
} else {
// Store $sSLTName to keep track of which SLT has been used
$iDeadline = $iMinDuration;
}
}
return $iDeadline;
}
示例2: AfterDatabaseCreation
public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
{
// Delete all Triggers corresponding to a no more valid class
$oSearch = new DBObjectSearch('TriggerOnObject');
$oSet = new DBObjectSet($oSearch);
$oChange = null;
while ($oTrigger = $oSet->Fetch()) {
if (!MetaModel::IsValidClass($oTrigger->Get('target_class'))) {
if ($oChange == null) {
// Create the change for its first use
$oChange = new CMDBChange();
$oChange->Set("date", time());
$oChange->Set("userinfo", "Uninstallation");
$oChange->DBInsert();
}
$oTrigger->DBDeleteTracked($oChange);
}
}
}
示例3: __construct
public function __construct($sClass, $sClassAlias = null)
{
parent::__construct();
if (is_null($sClassAlias)) {
$sClassAlias = $sClass;
}
if (!is_string($sClass)) {
throw new Exception('DBObjectSearch::__construct called with a non-string parameter: $sClass = ' . print_r($sClass, true));
}
if (!MetaModel::IsValidClass($sClass)) {
throw new Exception('DBObjectSearch::__construct called for an invalid class: "' . $sClass . '"');
}
$this->m_aSelectedClasses = array($sClassAlias => $sClass);
$this->m_aClasses = array($sClassAlias => $sClass);
$this->m_oSearchCondition = new TrueExpression();
$this->m_aParams = array();
$this->m_aFullText = array();
$this->m_aPointingTo = array();
$this->m_aReferencedBy = array();
}
示例4: GetObjectSetFromKey
/**
* Search objects from a polymorph search specification (Rest/Json)
*
* @param string $sClass Name of the class
* @param mixed $key Either search criteria (substructure), or an object or an OQL string.
* @return DBObjectSet The search result set
* @throws Exception If the input structure is not valid
*/
public static function GetObjectSetFromKey($sClass, $key)
{
if (is_object($key)) {
if (isset($key->finalclass)) {
$sClass = $key->finalclass;
if (!MetaModel::IsValidClass($sClass)) {
throw new Exception("finalclass: Unknown class '{$sClass}'");
}
}
$oSearch = new DBObjectSearch($sClass);
foreach ($key as $sAttCode => $value) {
$realValue = static::MakeValue($sClass, $sAttCode, $value);
$oSearch->AddCondition($sAttCode, $realValue, '=');
}
} elseif (is_numeric($key)) {
$oSearch = new DBObjectSearch($sClass);
$oSearch->AddCondition('id', $key);
} elseif (is_string($key)) {
// OQL
$oSearch = DBObjectSearch::FromOQL($key);
$oObjectSet = new DBObjectSet($oSearch);
} else {
throw new Exception("Wrong format for key");
}
$oObjectSet = new DBObjectSet($oSearch);
return $oObjectSet;
}
示例5: BuildQuery
/**
* Applies the defined parameters into the SQL query
* @return string the SQL query to execute
*/
public function BuildQuery()
{
$oAppContext = new ApplicationContext();
$sQuery = $this->m_sQuery;
$sQuery = str_replace('$DB_PREFIX$', MetaModel::GetConfig()->GetDBSubname(), $sQuery);
// put the tables DB prefix (if any)
foreach ($this->m_aParams as $sName => $aParam) {
if ($aParam['type'] == 'context') {
$sSearchPattern = '/\\$CONDITION\\(' . $sName . ',([^\\)]+)\\)\\$/';
$value = $oAppContext->GetCurrentValue($aParam['mapping']);
if (empty($value)) {
$sSQLExpr = '(1)';
} else {
// Special case for managing the hierarchy of organizations
if ($aParam['mapping'] == 'org_id' && MetaModel::IsValidClass('Organization')) {
$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass('Organization');
if ($sHierarchicalKeyCode != false) {
// organizations are in hierarchy... gather all the orgs below the given one...
$sOQL = "SELECT Organization AS node JOIN Organization AS root ON node.{$sHierarchicalKeyCode} BELOW root.id WHERE root.id = :value";
$oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('value' => $value));
$aOrgIds = array();
while ($oOrg = $oSet->Fetch()) {
$aOrgIds[] = $oOrg->GetKey();
}
$sSQLExpr = '($1 IN(' . implode(',', $aOrgIds) . '))';
} else {
$sSQLExpr = '($1 = ' . CMDBSource::Quote($value) . ')';
}
} else {
$sSQLExpr = '($1 = ' . CMDBSource::Quote($value) . ')';
}
}
$sQuery = preg_replace($sSearchPattern, $sSQLExpr, $sQuery);
}
}
return $sQuery;
}
示例6: RenderTag
protected function RenderTag($oPage, $sTag, $aAttributes, $sContent)
{
static $iTabContainerCount = 0;
switch ($sTag) {
case 'itoptabs':
$oPage->AddTabContainer('Tabs_' . $iTabContainerCount);
$oPage->SetCurrentTabContainer('Tabs_' . $iTabContainerCount);
$iTabContainerCount++;
//$oPage->p('Content:<pre>'.htmlentities($sContent, ENT_QUOTES, 'UTF-8').'</pre>');
$oTemplate = new DisplayTemplate($sContent);
$oTemplate->Render($oPage, array());
// no params to apply, they have already been applied
$oPage->SetCurrentTabContainer('');
break;
case 'itopcheck':
$sClassName = $aAttributes['class'];
if (MetaModel::IsValidClass($sClassName) && UserRights::IsActionAllowed($sClassName, UR_ACTION_READ)) {
$oTemplate = new DisplayTemplate($sContent);
$oTemplate->Render($oPage, array());
// no params to apply, they have already been applied
} else {
// Leave a trace for those who'd like to understand why nothing is displayed
$oPage->add("<!-- class {$sClassName} does not exist, skipping some part of the template -->\n");
}
break;
case 'itoptab':
$oPage->SetCurrentTab(Dict::S(str_replace('_', ' ', $aAttributes['name'])));
$oTemplate = new DisplayTemplate($sContent);
$oTemplate->Render($oPage, array());
// no params to apply, they have already been applied
//$oPage->p('iTop Tab Content:<pre>'.htmlentities($sContent, ENT_QUOTES, 'UTF-8').'</pre>');
$oPage->SetCurrentTab('');
break;
case 'itoptoggle':
$sName = isset($aAttributes['name']) ? $aAttributes['name'] : 'Tagada';
$bOpen = isset($aAttributes['open']) ? $aAttributes['open'] : true;
$oPage->StartCollapsibleSection(Dict::S($sName), $bOpen);
$oTemplate = new DisplayTemplate($sContent);
$oTemplate->Render($oPage, array());
// no params to apply, they have already been applied
//$oPage->p('iTop Tab Content:<pre>'.htmlentities($sContent, ENT_QUOTES, 'UTF-8').'</pre>');
$oPage->EndCollapsibleSection();
break;
case 'itopstring':
$oPage->add(Dict::S($sContent));
break;
case 'sqlblock':
$oBlock = SqlBlock::FromTemplate($sContent);
$oBlock->RenderContent($oPage);
break;
case 'itopblock':
// No longer used, handled by DisplayBlock::FromTemplate see above
$oPage->add("<!-- Application Error: should be handled by DisplayBlock::FromTemplate -->");
break;
default:
// Unknown tag, just ignore it or now -- output an HTML comment
$oPage->add("<!-- unsupported tag: {$sTag} -->");
}
}
示例7: UpdateChildRequestLog
public function UpdateChildRequestLog()
{
if (!MetaModel::IsValidClass('UserRequest')) {
return true;
}
// Do nothing
$oLog = $this->Get('public_log');
$sLogPublic = $oLog->GetModifiedEntry();
if ($sLogPublic != '') {
$sOQL = "SELECT UserRequest WHERE parent_incident_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('ticket' => $this->GetKey()));
while ($oRequest = $oChildRequestSet->Fetch()) {
$oRequest->set('public_log', $sLogPublic);
$oRequest->DBUpdate();
}
}
$oLog = $this->Get('private_log');
$sLogPrivate = $oLog->GetModifiedEntry();
if ($sLogPrivate != '') {
$sOQL = "SELECT UserRequest WHERE parent_incident_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('ticket' => $this->GetKey()));
while ($oRequest = $oChildRequestSet->Fetch()) {
$oRequest->set('private_log', $sLogPrivate);
$oRequest->DBUpdate();
}
}
return true;
}
示例8: Sanitize_Internal
protected static function Sanitize_Internal($value, $sSanitizationFilter)
{
switch ($sSanitizationFilter) {
case 'integer':
$retValue = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
break;
case 'class':
$retValue = $value;
if (!MetaModel::IsValidClass($value)) {
$retValue = false;
}
break;
case 'string':
$retValue = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
break;
case 'context_param':
case 'parameter':
case 'field_name':
if (is_array($value)) {
$retValue = array();
foreach ($value as $key => $val) {
$retValue[$key] = self::Sanitize_Internal($val, $sSanitizationFilter);
// recursively check arrays
if ($retValue[$key] === false) {
$retValue = false;
break;
}
}
} else {
switch ($sSanitizationFilter) {
case 'parameter':
$retValue = filter_var($value, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => '/^[ A-Za-z0-9_=-]*$/')));
// the '=' equal character is used in serialized filters
break;
case 'field_name':
$retValue = filter_var($value, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => '/^[A-Za-z0-9_]+(->[A-Za-z0-9_]+)*$/')));
// att_code or att_code->name or AttCode->Name or AttCode->Key2->Name
break;
case 'context_param':
$retValue = filter_var($value, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => '/^[ A-Za-z0-9_=%:+-]*$/')));
break;
}
}
break;
default:
case 'raw_data':
$retValue = $value;
// Do nothing
}
return $retValue;
}
示例9: IsValidClass
public function IsValidClass($sClass)
{
return MetaModel::IsValidClass($sClass);
}
示例10: LogMessage
protected function LogMessage($sMessage, $aData = array())
{
if (MetaModel::IsLogEnabledIssue()) {
if (MetaModel::IsValidClass('EventIssue')) {
$oLog = new EventIssue();
$oLog->Set('message', $sMessage);
$oLog->Set('userinfo', '');
$oLog->Set('issue', 'LDAP Authentication');
$oLog->Set('impact', 'User login rejected');
$oLog->Set('data', $aData);
$oLog->DBInsertNoReload();
}
IssueLog::Error($sMessage);
}
}
示例11: MakeRealValue
public function MakeRealValue($proposedValue, $oHostObj)
{
$sValue = $proposedValue;
if (preg_match_all(WIKI_OBJECT_REGEXP, $sValue, $aAllMatches, PREG_SET_ORDER)) {
foreach ($aAllMatches as $iPos => $aMatches) {
$sClassLabel = $aMatches[1];
$sName = $aMatches[2];
if (!MetaModel::IsValidClass($sClassLabel)) {
$sClass = MetaModel::GetClassFromLabel($sClassLabel);
if ($sClass) {
$sValue = str_replace($aMatches[0], "[[{$sClass}:{$sName}]]", $sValue);
}
}
}
}
return $sValue;
}
示例12: ReadContext
/**
* Read the context directly in the PHP parameters (either POST or GET)
* return nothing
*/
protected function ReadContext()
{
if (!isset(self::$aDefaultValues)) {
self::$aDefaultValues = array();
$aContext = utils::ReadParam('c', array(), false, 'context_param');
foreach ($this->aNames as $sName) {
$sValue = isset($aContext[$sName]) ? $aContext[$sName] : '';
// TO DO: check if some of the context parameters are mandatory (or have default values)
if (!empty($sValue)) {
self::$aDefaultValues[$sName] = $sValue;
}
// Hmm, there must be a better (more generic) way to handle the case below:
// When there is only one possible (allowed) organization, the context must be
// fixed to this org
if ($sName == 'org_id') {
if (MetaModel::IsValidClass('Organization')) {
$oSearchFilter = new DBObjectSearch('Organization');
$oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
$oSet = new CMDBObjectSet($oSearchFilter);
$iCount = $oSet->Count();
if ($iCount == 1) {
// Only one possible value for org_id, set it in the context
$oOrg = $oSet->Fetch();
self::$aDefaultValues[$sName] = $oOrg->GetKey();
}
}
}
}
}
$this->aValues = self::$aDefaultValues;
}
示例13: DisplayBareRelations
function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
parent::DisplayBareRelations($oPage, $bEditMode);
if (!$bEditMode) {
if (MetaModel::IsValidClass('KnownError')) {
//Search for known errors
$oPage->SetCurrentTab(Dict::S('Class:UserRequest:KnownErrorList'));
$iTicketID = $this->GetKey();
$oKnownErrorSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT KnownError AS ke JOIN lnkErrorToFunctionalCI AS l1 ON l1.error_id=ke.id JOIN FunctionalCI AS ci ON l1.functionalci_id=ci.id JOIN lnkFunctionalCIToTicket AS l2 ON l2.functionalci_id=ci.id WHERE l2.ticket_id={$iTicketID}"));
$iNumberKE = $oKnownErrorSet->count();
if ($iNumberKE > 0) {
$oPage->SetCurrentTab(Dict::S('Class:UserRequest:KnownErrorList') . " ({$iNumberKE})");
} else {
$oPage->SetCurrentTab(Dict::S('Class:UserRequest:KnownErrorList'));
}
self::DisplaySet($oPage, $oKnownErrorSet, array('menu' => false));
}
}
}
示例14: LoadFile
/**
* Helper function to load the objects from a standard XML file into the database
* @param $sFilePath string The full path to the XML file to load
* @param $bUpdateKeyCacheOnly bool Set to true to *just* update the keys cache but not reload the objects
*/
function LoadFile($sFilePath, $bUpdateKeyCacheOnly = false)
{
global $aKeys;
$oXml = simplexml_load_file($sFilePath);
$aReplicas = array();
foreach ($oXml as $sClass => $oXmlObj) {
if (!MetaModel::IsValidClass($sClass)) {
SetupPage::log_error("Unknown class - {$sClass}");
throw new Exception("Unknown class - {$sClass}");
}
$iSrcId = (int) $oXmlObj['id'];
// Mandatory to cast
// Import algorithm
// Here enumerate all the attributes of the object
// for all attribute that is neither an external field
// not an external key, assign it
// Store all external keys for further reference
// Create the object an store the correspondance between its newly created Id
// and its original Id
// Once all the objects have been created re-assign all the external keys to
// their actual Ids
$iExistingId = $this->GetObjectKey($sClass, $iSrcId);
if ($iExistingId != 0) {
$oTargetObj = MetaModel::GetObject($sClass, $iExistingId);
} else {
$oTargetObj = MetaModel::NewObject($sClass);
}
foreach ($oXmlObj as $sAttCode => $oSubNode) {
if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) {
$sMsg = "Unknown attribute code - {$sClass}/{$sAttCode}";
continue;
// ignore silently...
//SetupPage::log_error($sMsg);
//throw(new Exception($sMsg));
}
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if ($oAttDef->IsWritable() && $oAttDef->IsScalar()) {
if ($oAttDef->IsExternalKey()) {
if (substr(trim($oSubNode), 0, 6) == 'SELECT') {
$sQuery = trim($oSubNode);
$oSet = new DBObjectSet(DBObjectSearch::FromOQL($sQuery));
$iMatches = $oSet->Count();
if ($iMatches == 1) {
$oFoundObject = $oSet->Fetch();
$iExtKey = $oFoundObject->GetKey();
} else {
$sMsg = "Ext key not reconcilied - {$sClass}/{$iSrcId} - {$sAttCode}: '" . $sQuery . "' - found {$iMatches} matche(s)";
SetupPage::log_error($sMsg);
$this->m_aErrors[] = $sMsg;
$iExtKey = 0;
}
} else {
$iDstObj = (int) $oSubNode;
// Attempt to find the object in the list of loaded objects
$iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), $iDstObj);
if ($iExtKey == 0) {
$iExtKey = -$iDstObj;
// Convention: Unresolved keys are stored as negative !
$oTargetObj->RegisterAsDirty();
}
// here we allow external keys to be invalid because we will resolve them later on...
}
//$oTargetObj->CheckValue($sAttCode, $iExtKey);
$oTargetObj->Set($sAttCode, $iExtKey);
} elseif ($oAttDef instanceof AttributeBlob) {
$sMimeType = (string) $oSubNode->mimetype;
$sFileName = (string) $oSubNode->filename;
$data = base64_decode((string) $oSubNode->data);
$oDoc = new ormDocument($data, $sMimeType, $sFileName);
$oTargetObj->Set($sAttCode, $oDoc);
} else {
$value = (string) $oSubNode;
if ($value == '') {
$value = $oAttDef->GetNullValue();
}
$res = $oTargetObj->CheckValue($sAttCode, $value);
if ($res !== true) {
// $res contains the error description
$sMsg = "Value not allowed - {$sClass}/{$iSrcId} - {$sAttCode}: '" . $oSubNode . "' ; {$res}";
SetupPage::log_error($sMsg);
$this->m_aErrors[] = $sMsg;
}
$oTargetObj->Set($sAttCode, $value);
}
}
}
$this->StoreObject($sClass, $oTargetObj, $iSrcId, $bUpdateKeyCacheOnly, $bUpdateKeyCacheOnly);
}
return true;
}
示例15: LoadValues
protected function LoadValues($aArgs)
{
// Call the parent to parse the additional values...
parent::LoadValues($aArgs);
// Translate the labels of the additional values
foreach ($this->m_aValues as $sClass => $void) {
if (MetaModel::IsValidClass($sClass)) {
$this->m_aValues[$sClass] = MetaModel::GetName($sClass);
} else {
unset($this->m_aValues[$sClass]);
}
}
// Then, add the classes from the category definition
foreach (MetaModel::GetClasses($this->m_sCategories) as $sClass) {
if (MetaModel::IsValidClass($sClass)) {
$this->m_aValues[$sClass] = MetaModel::GetName($sClass);
} else {
unset($this->m_aValues[$sClass]);
}
}
return true;
}