当前位置: 首页>>代码示例>>PHP>>正文


PHP Organization::Set方法代码示例

本文整理汇总了PHP中Organization::Set方法的典型用法代码示例。如果您正苦于以下问题:PHP Organization::Set方法的具体用法?PHP Organization::Set怎么用?PHP Organization::Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Organization的用法示例。


在下文中一共展示了Organization::Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CreateAdministrator

 public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
 {
     CMDBObject::SetTrackInfo('Initialization');
     $oChange = CMDBObject::GetCurrentChange();
     $iContactId = 0;
     // Support drastic data model changes: no organization class (or not writable)!
     if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) {
         $oOrg = new Organization();
         $oOrg->Set('name', 'My Company/Department');
         $oOrg->Set('code', 'SOMECODE');
         $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true);
         // Support drastic data model changes: no Person class  (or not writable)!
         if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) {
             $oContact = new Person();
             $oContact->Set('name', 'My last name');
             $oContact->Set('first_name', 'My first name');
             if (MetaModel::IsValidAttCode('Person', 'org_id')) {
                 $oContact->Set('org_id', $iOrgId);
             }
             if (MetaModel::IsValidAttCode('Person', 'phone')) {
                 $oContact->Set('phone', '+00 000 000 000');
             }
             $oContact->Set('email', 'my.email@foo.org');
             $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true);
         }
     }
     $oUser = new UserLocal();
     $oUser->Set('login', $sAdminUser);
     $oUser->Set('password', $sAdminPwd);
     if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && $iContactId != 0) {
         $oUser->Set('contactid', $iContactId);
     }
     $oUser->Set('language', $sLanguage);
     // Language was chosen during the installation
     // Add this user to the very specific 'admin' profile
     $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true);
     if (is_object($oAdminProfile)) {
         $oUserProfile = new URP_UserProfile();
         //$oUserProfile->Set('userid', $iUserId);
         $oUserProfile->Set('profileid', $oAdminProfile->GetKey());
         $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
         //$oUserProfile->DBInsertTrackedNoReload($oChange, true /* skip security */);
         $oSet = DBObjectSet::FromObject($oUserProfile);
         $oUser->Set('profile_list', $oSet);
     }
     $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true);
     return true;
 }
开发者ID:kira8565,项目名称:ITOP203-ZHCN,代码行数:48,代码来源:userrightsprofile.class.inc.php

示例2: CreateAdministrator

 public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
 {
     // Create a change to record the history of the User object
     $oChange = MetaModel::NewObject("CMDBChange");
     $oChange->Set("date", time());
     $oChange->Set("userinfo", "Initialization");
     $iChangeId = $oChange->DBInsert();
     $oOrg = new Organization();
     $oOrg->Set('name', 'My Company/Department');
     $oOrg->Set('code', 'SOMECODE');
     //		$oOrg->Set('status', 'implementation');
     //$oOrg->Set('parent_id', xxx);
     $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true);
     // Location : optional
     //$oLocation = new bizLocation();
     //$oLocation->Set('name', 'MyOffice');
     //$oLocation->Set('status', 'implementation');
     //$oLocation->Set('org_id', $iOrgId);
     //$oLocation->Set('severity', 'high');
     //$oLocation->Set('address', 'my building in my city');
     //$oLocation->Set('country', 'my country');
     //$oLocation->Set('parent_location_id', xxx);
     //$iLocationId = $oLocation->DBInsertNoReload();
     $oContact = new Person();
     $oContact->Set('name', 'My last name');
     $oContact->Set('first_name', 'My first name');
     //$oContact->Set('status', 'available');
     $oContact->Set('org_id', $iOrgId);
     $oContact->Set('email', 'my.email@foo.org');
     //$oContact->Set('phone', '');
     //$oContact->Set('location_id', $iLocationId);
     //$oContact->Set('employee_number', '');
     $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true);
     $oUser = new UserLocal();
     $oUser->Set('login', $sAdminUser);
     $oUser->Set('password', $sAdminPwd);
     $oUser->Set('contactid', $iContactId);
     $oUser->Set('language', $sLanguage);
     // Language was chosen during the installation
     $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true);
     // Add this user to the very specific 'admin' profile
     $oUserProfile = new URP_UserProfile();
     $oUserProfile->Set('userid', $iUserId);
     $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
     $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
     $oUserProfile->DBInsertTrackedNoReload($oChange, true);
     return true;
 }
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:48,代码来源:userrightsprojection.class.inc.php

示例3: DoExecute

 protected function DoExecute()
 {
     CMDBSource::Query('START TRANSACTION');
     //CMDBSource::Query('ROLLBACK'); automatique !
     ////////////////////////////////////////////////////////////////////////////////
     // Set the stage
     //
     $oProvider = new Organization();
     $oProvider->Set('name', 'Test-Provider1');
     $oProvider->DBInsert();
     $iProvider = $oProvider->GetKey();
     $oDM1 = new DeliveryModel();
     $oDM1->Set('name', 'Test-DM-1');
     $oDM1->Set('org_id', $iProvider);
     $oDM1->DBInsert();
     $iDM1 = $oDM1->GetKey();
     $oDM2 = new DeliveryModel();
     $oDM2->Set('name', 'Test-DM-2');
     $oDM2->Set('org_id', $iProvider);
     $oDM2->DBInsert();
     $iDM2 = $oDM2->GetKey();
     ////////////////////////////////////////////////////////////////////////////////
     // Scenarii
     //
     $aScenarii = array(array('description' => 'Add the first customer', 'organizations' => array(array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Remove the customer by loading an empty set', 'organizations' => array(), 'expected-res' => array(), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Create two customers at once', 'organizations' => array(array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1'), array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1", "Test-Customer-2, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Move Customer-1 to the second Delivery Model', 'organizations' => array(array('id' => "SELECT Organization WHERE name='Test-Customer-1'", 'deliverymodel_id' => $iDM2, 'name' => 'Test-Customer-1'), array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-2, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Move Customer-1 back to the first Delivery Model and reset Customer-2 (no Delivery Model)', 'organizations' => array(array('id' => "SELECT Organization WHERE name='Test-Customer-1'", 'deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1'), array('id' => "SELECT Organization WHERE name='Test-Customer-2'", 'deliverymodel_id' => 0, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0));
     foreach ($aScenarii as $aScenario) {
         echo "<h4>" . $aScenario['description'] . "</h4>\n";
         $oChange = MetaModel::NewObject("CMDBChange");
         $oChange->Set("date", time());
         $oChange->Set("userinfo", CMDBChange::GetCurrentUserName());
         $oChange->Set("origin", 'custom-extension');
         $oChange->DBInsert();
         CMDBObject::SetCurrentChange($oChange);
         $iChange = $oChange->GetKey();
         // Prepare set
         $oLinkset = DBObjectSet::FromScratch('Organization');
         foreach ($aScenario['organizations'] as $aOrgData) {
             if (array_key_exists('id', $aOrgData)) {
                 $sOQL = $aOrgData['id'];
                 $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
                 $oOrg = $oSet->Fetch();
                 if (!is_object($oOrg)) {
                     throw new Exception('Failed to find the Organization: ' . $sOQL);
                 }
             } else {
                 $oOrg = MetaModel::NewObject('Organization');
             }
             foreach ($aOrgData as $sAttCode => $value) {
                 if ($sAttCode == 'id') {
                     continue;
                 }
                 $oOrg->Set($sAttCode, $value);
             }
             $oLinkset->AddObject($oOrg);
         }
         // Write
         $oDM = MetaModel::GetObject('DeliveryModel', $iDM1);
         $oDM->Set('customers_list', $oLinkset);
         $oDM->DBWrite();
         // Check Results
         $bFoundIssue = false;
         $oDM = MetaModel::GetObject('DeliveryModel', $iDM1);
         $oLinkset = $oDM->Get('customers_list');
         $aRes = $this->StandardizedDump($oLinkset, 'zzz');
         $sRes = var_export($aRes, true);
         echo "Found: <pre>" . $sRes . "</pre>\n";
         $sExpectedRes = var_export($aScenario['expected-res'], true);
         if ($sRes != $sExpectedRes) {
             $bFoundIssue = true;
             echo "NOT COMPLIANT!!! Expecting: <pre>" . $sExpectedRes . "</pre>\n";
         }
         // Check History
         $aQueryParams = array('change' => $iChange, 'objclass' => get_class($oDM), 'objkey' => $oDM->GetKey());
         $oAdded = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksAddRemove WHERE objclass = :objclass AND objkey = :objkey AND change = :change AND type = 'added'"), array(), $aQueryParams);
         echo "added: " . $oAdded->Count() . "<br/>\n";
         if ($aScenario['history_added'] != $oAdded->Count()) {
             $bFoundIssue = true;
             echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_added'] . "<br/>\n";
         }
         $oRemoved = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksAddRemove WHERE objclass = :objclass AND objkey = :objkey AND change = :change AND type = 'removed'"), array(), $aQueryParams);
         echo "removed: " . $oRemoved->Count() . "<br/>\n";
         if ($aScenario['history_removed'] != $oRemoved->Count()) {
             $bFoundIssue = true;
             echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_removed'] . "<br/>\n";
         }
         $oModified = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksTune WHERE objclass = :objclass AND objkey = :objkey AND change = :change"), array(), $aQueryParams);
         echo "modified: " . $oModified->Count() . "<br/>\n";
         if ($aScenario['history_modified'] != $oModified->Count()) {
             $bFoundIssue = true;
             echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_modified'] . "<br/>\n";
         }
         if ($bFoundIssue) {
             throw new Exception('Stopping on failed scenario');
         }
     }
 }
开发者ID:besmirzanaj,项目名称:itop-code,代码行数:96,代码来源:testlist.inc.php


注:本文中的Organization::Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。