本文整理汇总了PHP中MetaModel::GetObjectByName方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::GetObjectByName方法的具体用法?PHP MetaModel::GetObjectByName怎么用?PHP MetaModel::GetObjectByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaModel
的用法示例。
在下文中一共展示了MetaModel::GetObjectByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: switch
$oP->add_linked_script("../js/jquery.blockUI.js");
break;
}
switch ($operation) {
///////////////////////////////////////////////////////////////////////////////////////////
case 'details':
// Details of an object
$sClass = utils::ReadParam('class', '');
$id = utils::ReadParam('id', '');
if (empty($sClass) || empty($id)) {
throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
}
if (is_numeric($id)) {
$oObj = MetaModel::GetObject($sClass, $id, false);
} else {
$oObj = MetaModel::GetObjectByName($sClass, $id, false);
}
if (is_null($oObj)) {
$oP->set_title(Dict::S('UI:ErrorPageTitle'));
$oP->P(Dict::S('UI:ObjectDoesNotExist'));
} else {
try {
$oObj->Reload();
} catch (Exception $e) {
// Probably not allowed to see this instance of a derived class
$oObj = null;
$oP->set_title(Dict::S('UI:ErrorPageTitle'));
$oP->P(Dict::S('UI:ObjectDoesNotExist'));
}
if (!is_null($oObj)) {
DisplayDetails($oP, $sClass, $oObj, $id);
示例2: RenderWikiHtml
public static function RenderWikiHtml($sText)
{
$sPattern = '/' . str_replace('/', '\\/', utils::GetConfig()->Get('url_validation_pattern')) . '/i';
if (preg_match_all($sPattern, $sText, $aAllMatches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$aUrls = array();
$i = count($aAllMatches);
// Replace the URLs by an actual hyperlink <a href="...">...</a>
// Let's do it backwards so that the initial positions are not modified by the replacement
// This works if the matches are captured: in the order they occur in the string AND
// with their offset (i.e. position) inside the string
while ($i > 0) {
$i--;
$sUrl = $aAllMatches[$i][0][0];
// String corresponding to the main pattern
$iPos = $aAllMatches[$i][0][1];
// Position of the main pattern
$sText = substr_replace($sText, "<a href=\"{$sUrl}\">{$sUrl}</a>", $iPos, strlen($sUrl));
}
}
if (preg_match_all(WIKI_OBJECT_REGEXP, $sText, $aAllMatches, PREG_SET_ORDER)) {
foreach ($aAllMatches as $iPos => $aMatches) {
$sClass = $aMatches[1];
$sName = $aMatches[2];
if (MetaModel::IsValidClass($sClass)) {
$oObj = MetaModel::GetObjectByName($sClass, $sName, false);
if (is_object($oObj)) {
// Propose a std link to the object
$sText = str_replace($aMatches[0], $oObj->GetHyperlink(), $sText);
} else {
// Propose a std link to the object
$sClassLabel = MetaModel::GetName($sClass);
$sText = str_replace($aMatches[0], "<span class=\"wiki_broken_link\">{$sClassLabel}:{$sName}</span>", $sText);
// Later: propose a link to create a new object
// Anyhow... there is no easy way to suggest default values based on the given FRIENDLY name
//$sText = preg_replace('/\[\[(.+):(.+)\]\]/', '<a href="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&default[att1]=xxx&default[att2]=yyy">'.$sName.'</a>', $sText);
}
}
}
}
return $sText;
}
示例3: CreateCASUser
/**
* Helper method to create a CAS based user
* @param string $sEmail
* @param array $aGroups
* @return bool true on success, false otherwise
*/
protected static function CreateCASUser($sEmail, $aGroups)
{
if (!MetaModel::IsValidClass('URP_Profiles')) {
phpCAS::log("URP_Profiles is not a valid class. Automatic creation of Users is not supported in this context, sorry.");
return false;
}
$oUser = MetaModel::GetObjectByName('UserExternal', $sEmail, false);
if ($oUser == null) {
// Create the user, link it to a contact
phpCAS::log("Info: the user '{$sEmail}' does not exist. A new UserExternal will be created.");
$oSearch = new DBObjectSearch('Person');
$oSearch->AddCondition('email', $sEmail);
$oSet = new DBObjectSet($oSearch);
$iContactId = 0;
switch ($oSet->Count()) {
case 0:
phpCAS::log("Error: found no contact with the email: '{$sEmail}'. Cannot create the user in iTop.");
return false;
case 1:
$oContact = $oSet->Fetch();
$iContactId = $oContact->GetKey();
phpCAS::log("Info: Found 1 contact '" . $oContact->GetName() . "' (id={$iContactId}) corresponding to the email '{$sEmail}'.");
break;
default:
phpCAS::log("Error: " . $oSet->Count() . " contacts have the same email: '{$sEmail}'. Cannot create a user for this email.");
return false;
}
$oUser = new UserExternal();
$oUser->Set('login', $sEmail);
$oUser->Set('contactid', $iContactId);
$oUser->Set('language', MetaModel::GetConfig()->GetDefaultLanguage());
} else {
phpCAS::log("Info: the user '{$sEmail}' already exists (id=" . $oUser->GetKey() . ").");
}
// Now synchronize the profiles
if (!self::SetProfilesFromCAS($oUser, $aGroups)) {
return false;
} else {
if ($oUser->IsNew() || $oUser->IsModified()) {
$oMyChange = MetaModel::NewObject("CMDBChange");
$oMyChange->Set("date", time());
$oMyChange->Set("userinfo", 'CAS/LDAP Synchro');
$oMyChange->DBInsert();
if ($oUser->IsNew()) {
$oUser->DBInsertTracked($oMyChange);
} else {
$oUser->DBUpdateTracked($oMyChange);
}
}
return true;
}
}