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


PHP DataObject::get_by_id方法代码示例

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


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

示例1: processRecord

 public function processRecord($record, $columnMap, &$results, $preview = false)
 {
     $objID = parent::processRecord($record, $columnMap, $results, $preview);
     $_cache_groupByCode = array();
     // Add to predefined groups
     /** @var Member $member */
     $member = DataObject::get_by_id($this->objectClass, $objID);
     foreach ($this->groups as $group) {
         // TODO This isnt the most memory effective way to add members to a group
         $member->Groups()->add($group);
     }
     // Add to groups defined in CSV
     if (isset($record['Groups']) && $record['Groups']) {
         $groupCodes = explode(',', $record['Groups']);
         foreach ($groupCodes as $groupCode) {
             $groupCode = Convert::raw2url($groupCode);
             if (!isset($_cache_groupByCode[$groupCode])) {
                 $group = Group::get()->filter('Code', $groupCode)->first();
                 if (!$group) {
                     $group = new Group();
                     $group->Code = $groupCode;
                     $group->Title = $groupCode;
                     $group->write();
                 }
                 $member->Groups()->add($group);
                 $_cache_groupByCode[$groupCode] = $group;
             }
         }
     }
     $member->destroy();
     unset($member);
     return $objID;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:33,代码来源:MemberCsvBulkLoader.php

示例2: processRecord

 public function processRecord($record, $columnMap, &$results, $preview = false)
 {
     // We match by 'Code', the ID property is confusing the importer
     if (isset($record['ID'])) {
         unset($record['ID']);
     }
     $objID = parent::processRecord($record, $columnMap, $results, $preview);
     $group = DataObject::get_by_id($this->objectClass, $objID);
     // set group hierarchies - we need to do this after all records
     // are imported to avoid missing "early" references to parents
     // which are imported later on in the CSV file.
     if (isset($record['ParentCode']) && $record['ParentCode']) {
         $parentGroup = DataObject::get_one('SilverStripe\\Security\\Group', array('"Group"."Code"' => $record['ParentCode']));
         if ($parentGroup) {
             $group->ParentID = $parentGroup->ID;
             $group->write();
         }
     }
     // set permission codes - these are all additive, meaning
     // existing permissions arent cleared.
     if (isset($record['PermissionCodes']) && $record['PermissionCodes']) {
         foreach (explode(',', $record['PermissionCodes']) as $code) {
             $p = DataObject::get_one('SilverStripe\\Security\\Permission', array('"Permission"."Code"' => $code, '"Permission"."GroupID"' => $group->ID));
             if (!$p) {
                 $p = new Permission(array('Code' => $code));
                 $p->write();
             }
             $group->Permissions()->add($p);
         }
     }
     return $objID;
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:32,代码来源:GroupCsvBulkLoader.php

示例3: add

 /**
  * Adds the item to this relation.
  *
  * It does so by setting the relationFilters.
  *
  * @param DataObject|int $item The DataObject to be added, or its ID
  */
 public function add($item)
 {
     if (is_numeric($item)) {
         $item = DataObject::get_by_id($this->dataClass, $item);
     } else {
         if (!$item instanceof $this->dataClass) {
             user_error("PolymorphicHasManyList::add() expecting a {$this->dataClass} object, or ID value", E_USER_ERROR);
         }
     }
     $foreignID = $this->getForeignID();
     // Validate foreignID
     if (!$foreignID) {
         user_error("PolymorphicHasManyList::add() can't be called until a foreign ID is set", E_USER_WARNING);
         return;
     }
     if (is_array($foreignID)) {
         user_error("PolymorphicHasManyList::add() can't be called on a list linked to mulitple foreign IDs", E_USER_WARNING);
         return;
     }
     $foreignKey = $this->foreignKey;
     $classForeignKey = $this->classForeignKey;
     $item->{$foreignKey} = $foreignID;
     $item->{$classForeignKey} = $this->getForeignClass();
     $item->write();
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:32,代码来源:PolymorphicHasManyList.php

示例4: getValue

 public function getValue()
 {
     $id = $this->getIDValue();
     $class = $this->getClassValue();
     if ($id && $class && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject')) {
         return DataObject::get_by_id($class, $id);
     }
     return null;
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:9,代码来源:DBPolymorphicForeignKey.php

示例5: testSQLInsert

 public function testSQLInsert()
 {
     $factory = new FixtureFactory();
     $relPath = ltrim(FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml', '/');
     $fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $relPath);
     $fixture->writeInto($factory);
     $this->assertGreaterThan(0, $factory->getId("YamlFixtureTest_DataObject", "testobject1"));
     $object1 = DataObject::get_by_id("YamlFixtureTest_DataObject", $factory->getId("YamlFixtureTest_DataObject", "testobject1"));
     $this->assertTrue($object1->ManyManyRelation()->Count() == 2, "Should be two items in this relationship");
     $this->assertGreaterThan(0, $factory->getId("YamlFixtureTest_DataObject", "testobject2"));
     $object2 = DataObject::get_by_id("YamlFixtureTest_DataObject", $factory->getId("YamlFixtureTest_DataObject", "testobject2"));
     $this->assertTrue($object2->ManyManyRelation()->Count() == 1, "Should be one item in this relationship");
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:13,代码来源:YamlFixtureTest.php

示例6: testCleartextPasswordsAreHashedWithDefaultAlgo

 public function testCleartextPasswordsAreHashedWithDefaultAlgo()
 {
     $loader = new MemberCsvBulkLoader();
     $results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_cleartextpws.csv');
     $member = $results->Created()->First();
     $memberID = $member->ID;
     DataObject::flush_and_destroy_cache();
     $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $memberID);
     // TODO Direct getter doesn't work, wtf!
     $this->assertEquals(Security::config()->password_encryption_algorithm, $member->getField('PasswordEncryption'));
     $result = $member->checkPassword('mypassword');
     $this->assertTrue($result->valid());
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:13,代码来源:MemberCsvBulkLoaderTest.php

示例7: testRun

 public function testRun()
 {
     $m = new Member();
     $m->Password = 'plain';
     $m->PasswordEncryption = 'none';
     $m->write();
     $t = new EncryptAllPasswordsTask();
     $t->run(null);
     $m = DataObject::get_by_id('SilverStripe\\Security\\Member', $m->ID);
     $this->assertEquals($m->PasswordEncryption, 'blowfish');
     $this->assertNotEquals($m->Password, 'plain');
     $result = $m->checkPassword('plain');
     $this->assertTrue($result->valid());
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:14,代码来源:EncryptAllPasswordsTaskTest.php

示例8: testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm

 public function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm()
 {
     Config::inst()->update('SilverStripe\\Security\\PasswordEncryptor', 'encryptors', array('crc32' => array('SilverStripe\\Security\\PasswordEncryptor_PHPHash' => 'crc32')));
     $field = Member::config()->unique_identifier_field;
     $member = new Member();
     $member->{$field} = 'test2@test.com';
     $member->PasswordEncryption = "crc32";
     $member->Password = "mypassword";
     $member->write();
     $data = array('Email' => $member->{$field}, 'Password' => 'mypassword');
     MemberAuthenticator::authenticate($data);
     $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member->ID);
     $this->assertEquals($member->PasswordEncryption, "crc32");
     $result = $member->checkPassword('mypassword');
     $this->assertTrue($result->valid());
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:16,代码来源:MemberAuthenticatorTest.php

示例9: testDuplicateManyManyClasses

 public function testDuplicateManyManyClasses()
 {
     //create new test classes below
     $one = new DataObjectDuplicateTestClass1();
     $two = new DataObjectDuplicateTestClass2();
     $three = new DataObjectDuplicateTestClass3();
     //set some simple fields
     $text1 = "Test Text 1";
     $text2 = "Test Text 2";
     $text3 = "Test Text 3";
     $one->text = $text1;
     $two->text = $text2;
     $three->text = $text3;
     //write the to DB
     $one->write();
     $two->write();
     $three->write();
     //create relations
     $one->twos()->add($two);
     $one->threes()->add($three);
     $one = DataObject::get_by_id("DataObjectDuplicateTestClass1", $one->ID);
     $two = DataObject::get_by_id("DataObjectDuplicateTestClass2", $two->ID);
     $three = DataObject::get_by_id("DataObjectDuplicateTestClass3", $three->ID);
     //test duplication
     $oneCopy = $one->duplicate();
     $twoCopy = $two->duplicate();
     $threeCopy = $three->duplicate();
     $oneCopy = DataObject::get_by_id("DataObjectDuplicateTestClass1", $oneCopy->ID);
     $twoCopy = DataObject::get_by_id("DataObjectDuplicateTestClass2", $twoCopy->ID);
     $threeCopy = DataObject::get_by_id("DataObjectDuplicateTestClass3", $threeCopy->ID);
     $this->assertNotNull($oneCopy, "Copy of 1 exists");
     $this->assertNotNull($twoCopy, "Copy of 2 exists");
     $this->assertNotNull($threeCopy, "Copy of 3 exists");
     $this->assertEquals($text1, $oneCopy->text);
     $this->assertEquals($text2, $twoCopy->text);
     $this->assertEquals($text3, $threeCopy->text);
     $this->assertNotEquals($one->twos()->Count(), $oneCopy->twos()->Count(), "Many-to-one relation not copied (has_many)");
     $this->assertEquals($one->threes()->Count(), $oneCopy->threes()->Count(), "Object has the correct number of relations");
     $this->assertEquals($three->ones()->Count(), $threeCopy->ones()->Count(), "Object has the correct number of relations");
     $this->assertEquals($one->ID, $twoCopy->one()->ID, "Match between relation of copy and the original");
     $this->assertEquals(0, $oneCopy->twos()->Count(), "Many-to-one relation not copied (has_many)");
     $this->assertEquals($three->ID, $oneCopy->threes()->First()->ID, "Match between relation of copy and the original");
     $this->assertEquals($one->ID, $threeCopy->ones()->First()->ID, "Match between relation of copy and the original");
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:44,代码来源:DataObjectDuplicationTest.php

示例10: getItems

 /**
  * Return this field's linked items
  */
 public function getItems()
 {
     // If the value has been set, use that
     if ($this->value != 'unchanged' && is_array($this->sourceObject)) {
         $items = array();
         $values = is_array($this->value) ? $this->value : preg_split('/ *, */', trim($this->value));
         foreach ($values as $value) {
             $item = new stdClass();
             $item->ID = $value;
             $item->Title = $this->sourceObject[$value];
             $items[] = $item;
         }
         return $items;
         // Otherwise, look data up from the linked relation
     }
     if ($this->value != 'unchanged' && is_string($this->value)) {
         $items = new ArrayList();
         $ids = explode(',', $this->value);
         foreach ($ids as $id) {
             if (!is_numeric($id)) {
                 continue;
             }
             $item = DataObject::get_by_id($this->sourceObject, $id);
             if ($item) {
                 $items->push($item);
             }
         }
         return $items;
     } else {
         if ($this->form) {
             $fieldName = $this->name;
             $record = $this->form->getRecord();
             if (is_object($record) && $record->hasMethod($fieldName)) {
                 return $record->{$fieldName}();
             }
         }
     }
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:41,代码来源:TreeMultiselectField.php

示例11: getHTMLFragments

 public function getHTMLFragments($gridField)
 {
     $modelClass = $gridField->getModelClass();
     $parentID = 0;
     if ($this->currentID) {
         $modelObj = DataObject::get_by_id($modelClass, $this->currentID);
         if ($modelObj->hasMethod('getParent')) {
             $parent = $modelObj->getParent();
         } elseif ($modelObj->ParentID) {
             $parent = $modelObj->Parent();
         }
         if ($parent) {
             $parentID = $parent->ID;
         }
         // Attributes
         $attrs = array_merge($this->attributes, array('href' => sprintf($this->linkSpec, $parentID), 'class' => 'cms-panel-link ss-ui-button font-icon-level-up no-text grid-levelup'));
         $attrsStr = '';
         foreach ($attrs as $k => $v) {
             $attrsStr .= " {$k}=\"" . Convert::raw2att($v) . "\"";
         }
         $forTemplate = new ArrayData(array('UpLink' => DBField::create_field('HTMLFragment', sprintf('<a%s></a>', $attrsStr))));
         return array('before' => $forTemplate->renderWith('Includes/GridFieldLevelup'));
     }
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:24,代码来源:GridFieldLevelup.php

示例12: getHTMLFragments

 public function getHTMLFragments($gridField)
 {
     $modelClass = $gridField->getModelClass();
     $parentID = 0;
     if (!$this->currentID) {
         return null;
     }
     $modelObj = DataObject::get_by_id($modelClass, $this->currentID);
     $parent = null;
     if ($modelObj->hasMethod('getParent')) {
         $parent = $modelObj->getParent();
     } elseif ($modelObj->ParentID) {
         $parent = $modelObj->Parent();
     }
     if ($parent) {
         $parentID = $parent->ID;
     }
     // Attributes
     $attrs = array_merge($this->attributes, array('href' => sprintf($this->linkSpec, $parentID), 'class' => 'cms-panel-link ss-ui-button font-icon-level-up no-text grid-levelup'));
     $linkTag = FormField::create_tag('a', $attrs);
     $forTemplate = new ArrayData(array('UpLink' => DBField::create_field('HTMLFragment', $linkTag)));
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array('before' => $forTemplate->renderWith($template));
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:24,代码来源:GridFieldLevelup.php

示例13: delete_by_id

 /**
  * Delete the record with the given ID.
  *
  * @param string $className The class name of the record to be deleted
  * @param int $id ID of record to be deleted
  */
 public static function delete_by_id($className, $id)
 {
     $obj = DataObject::get_by_id($className, $id);
     if ($obj) {
         $obj->delete();
     } else {
         user_error("{$className} object #{$id} wasn't found when calling DataObject::delete_by_id", E_USER_WARNING);
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:15,代码来源:DataObject.php

示例14: inGroup

 /**
  * Check if the member is in the given group or any parent groups.
  *
  * @param int|Group|string $group Group instance, Group Code or ID
  * @param boolean $strict Only determine direct group membership if set to TRUE (Default: FALSE)
  * @return bool Returns TRUE if the member is in the given group, otherwise FALSE.
  */
 public function inGroup($group, $strict = false)
 {
     if (is_numeric($group)) {
         $groupCheckObj = DataObject::get_by_id('SilverStripe\\Security\\Group', $group);
     } elseif (is_string($group)) {
         $groupCheckObj = DataObject::get_one('SilverStripe\\Security\\Group', array('"Group"."Code"' => $group));
     } elseif ($group instanceof Group) {
         $groupCheckObj = $group;
     } else {
         user_error('Member::inGroup(): Wrong format for $group parameter', E_USER_ERROR);
     }
     if (!$groupCheckObj) {
         return false;
     }
     $groupCandidateObjs = $strict ? $this->getManyManyComponents("Groups") : $this->Groups();
     if ($groupCandidateObjs) {
         foreach ($groupCandidateObjs as $groupCandidateObj) {
             if ($groupCandidateObj->ID == $groupCheckObj->ID) {
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:31,代码来源:Member.php

示例15: testFormatFromSettings

 public function testFormatFromSettings()
 {
     $memberID = $this->logInWithPermission();
     $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $memberID);
     $member->DateFormat = 'dd/MM/YYYY';
     $member->write();
     $fixtures = array('2000-12-31' => '31/12/2000', '31-12-2000' => '31/12/2000', '31/12/2000' => '31/12/2000', '2014-04-01' => '01/04/2014');
     foreach ($fixtures as $from => $to) {
         $date = DBField::create_field('Date', $from);
         // With member
         $this->assertEquals($to, $date->FormatFromSettings($member));
         // Without member
         $this->assertEquals($to, $date->FormatFromSettings());
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:15,代码来源:DBDateTest.php


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