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


PHP ORM\DataObject类代码示例

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


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

示例1: scaffoldFormField

 public function scaffoldFormField($title = null, $params = null)
 {
     if (empty($this->object)) {
         return null;
     }
     $relationName = substr($this->name, 0, -2);
     $hasOneClass = $this->object->hasOneComponent($relationName);
     if (empty($hasOneClass)) {
         return null;
     }
     $hasOneSingleton = singleton($hasOneClass);
     if ($hasOneSingleton instanceof File) {
         $field = new UploadField($relationName, $title);
         if ($hasOneSingleton instanceof Image) {
             $field->setAllowedFileCategories('image/supported');
         }
         return $field;
     }
     // Build selector / numeric field
     $titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name";
     $list = DataList::create($hasOneClass);
     // Don't scaffold a dropdown for large tables, as making the list concrete
     // might exceed the available PHP memory in creating too many DataObject instances
     if ($list->count() < 100) {
         $field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
         $field->setEmptyString(' ');
     } else {
         $field = new NumericField($this->name, $title);
     }
     return $field;
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:31,代码来源:DBForeignKey.php

示例2: updateItemRequestClass

 /**
  * @param string $class
  * @param GridField $gridField
  * @param DataObject $record
  * @param RequestHandler $requestHandler
  */
 public function updateItemRequestClass(&$class, $gridField, $record, $requestHandler)
 {
     // Conditionally use a versioned item handler
     if ($record && $record->has_extension('SilverStripe\\ORM\\Versioning\\Versioned')) {
         $class = 'SilverStripe\\ORM\\Versioning\\VersionedGridFieldItemRequest';
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:13,代码来源:VersionedGridFieldDetailForm.php

示例3: add

 /**
  * Adds the item to this relation.
  *
  * It does so by setting the relationFilters.
  *
  * @param $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:jacobbuck,项目名称:silverstripe-framework,代码行数:32,代码来源:PolymorphicHasManyList.php

示例4: testMultipleRowInsert

 public function testMultipleRowInsert()
 {
     $query = SQLInsert::create('"SQLInsertTestBase"');
     $query->addRow(array('"Title"' => 'First Object', '"Age"' => 10, '"Description"' => 'First the worst'));
     $query->addRow(array('"Title"' => 'Second object', '"Age"' => 12));
     $sql = $query->sql($parameters);
     // Only test this case if using the default query builder
     if (get_class(DB::get_conn()->getQueryBuilder()) === 'SilverStripe\\ORM\\Connect\\DBQueryBuilder') {
         $this->assertSQLEquals('INSERT INTO "SQLInsertTestBase" ("Title", "Age", "Description") VALUES (?, ?, ?), (?, ?, ?)', $sql);
     }
     $this->assertEquals(array('First Object', 10, 'First the worst', 'Second object', 12, null), $parameters);
     $query->execute();
     $this->assertEquals(2, DB::affected_rows());
     // Check inserted objects are correct
     $firstObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'First Object'), false);
     $this->assertNotEmpty($firstObject);
     $this->assertEquals($firstObject->Title, 'First Object');
     $this->assertEquals($firstObject->Age, 10);
     $this->assertEquals($firstObject->Description, 'First the worst');
     $secondObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'Second object'), false);
     $this->assertNotEmpty($secondObject);
     $this->assertEquals($secondObject->Title, 'Second object');
     $this->assertEquals($secondObject->Age, 12);
     $this->assertEmpty($secondObject->Description);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:25,代码来源:SQLInsertTest.php

示例5: Form

 public function Form()
 {
     $player = DataObject::get('GridFieldTest_Player')->find('Email', 'player1@test.com');
     $config = GridFieldConfig::create()->addComponents($relationComponent = new GridFieldAddExistingAutocompleter('before'), new GridFieldDataColumns());
     $field = new GridField('testfield', 'testfield', $player->Teams(), $config);
     return new Form($this, 'Form', new FieldList($field), new FieldList());
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:7,代码来源:GridFieldAddExistingAutocompleterTest.php

示例6: testCreateWithTransaction

 public function testCreateWithTransaction()
 {
     if (DB::get_conn()->supportsTransactions() == true) {
         DB::get_conn()->transactionStart();
         $obj = new TransactionTest_Object();
         $obj->Title = 'First page';
         $obj->write();
         $obj = new TransactionTest_Object();
         $obj->Title = 'Second page';
         $obj->write();
         //Create a savepoint here:
         DB::get_conn()->transactionSavepoint('rollback');
         $obj = new TransactionTest_Object();
         $obj->Title = 'Third page';
         $obj->write();
         $obj = new TransactionTest_Object();
         $obj->Title = 'Fourth page';
         $obj->write();
         //Revert to a savepoint:
         DB::get_conn()->transactionRollback('rollback');
         DB::get_conn()->transactionEnd();
         $first = DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
         $second = DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
         $third = DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
         $fourth = DataObject::get('TransactionTest_Object', "\"Title\"='Fourth page'");
         //These pages should be in the system
         $this->assertTrue(is_object($first) && $first->exists());
         $this->assertTrue(is_object($second) && $second->exists());
         //These pages should NOT exist, we reverted to a savepoint:
         $this->assertFalse(is_object($third) && $third->exists());
         $this->assertFalse(is_object($fourth) && $fourth->exists());
     } else {
         $this->markTestSkipped('Current database does not support transactions');
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:35,代码来源:TransactionTest.php

示例7: 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

示例8: testApplyReplationDeepInheretence

 public function testApplyReplationDeepInheretence()
 {
     //test has_one relation
     $newDQ = new DataQuery('DataQueryTest_E');
     //apply a relation to a relation from an ancestor class
     $newDQ->applyRelation('TestA');
     $this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
     $this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql($params));
     //test many_many relation
     //test many_many with separate inheritance
     $newDQ = new DataQuery('DataQueryTest_C');
     $baseDBTable = DataObject::getSchema()->baseDataTable('DataQueryTest_C');
     $newDQ->applyRelation('ManyTestAs');
     //check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //check we are explicitly selecting "FROM" the DO's table
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql());
     //test many_many with shared inheritance
     $newDQ = new DataQuery('DataQueryTest_E');
     $baseDBTable = DataObject::getSchema()->baseDataTable('DataQueryTest_E');
     //check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //check we are explicitly selecting "FROM" the DO's table
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql(), 'The FROM clause is missing from the query');
     $newDQ->applyRelation('ManyTestGs');
     //confirm we are still joined to the base table
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //double check it is the "FROM" clause
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql(), 'The FROM clause has been removed from the query');
     //another (potentially less crude check) for checking "FROM" clause
     $fromTables = $newDQ->query()->getFrom();
     $this->assertEquals('"' . $baseDBTable . '"', $fromTables[$baseDBTable]);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:33,代码来源:DataQueryTest.php

示例9: 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

示例10: testDelete

 public function testDelete()
 {
     $role = $this->objFromFixture('SilverStripe\\Security\\PermissionRole', 'role');
     $role->delete();
     $this->assertEquals(0, DataObject::get('SilverStripe\\Security\\PermissionRole', "\"ID\"={$role->ID}")->count(), 'Role is removed');
     $this->assertEquals(0, DataObject::get('SilverStripe\\Security\\PermissionRoleCode', "\"RoleID\"={$role->ID}")->count(), 'Permissions removed along with the role');
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:7,代码来源:PermissionRoleTest.php

示例11: 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

示例12: testArrayValueWithSqlMapSource

 public function testArrayValueWithSqlMapSource()
 {
     $member1 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member1');
     $member2 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member2');
     $member3 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member3');
     $source = DataObject::get('SilverStripe\\Security\\Member');
     $f = new LookupField('test', 'test', $source->map('ID', 'FirstName'));
     $f->setValue(array($member1->ID, $member2->ID));
     $this->assertEquals(sprintf('<span class="readonly" id="test">member1, member2</span>' . '<input type="hidden" name="test" value="%s, %s" />', $member1->ID, $member2->ID), trim($f->Field()->getValue()));
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:10,代码来源:LookupFieldTest.php

示例13: testCompositeFieldMetaDataFunctions

 /**
  * Test DataObject::composite_fields() and DataObject::is_composite_field()
  */
 public function testCompositeFieldMetaDataFunctions()
 {
     $this->assertEquals('Money', DataObject::is_composite_field('DBCompositeTest_DataObject', 'MyMoney'));
     $this->assertFalse(DataObject::is_composite_field('DBCompositeTest_DataObject', 'Title'));
     $this->assertEquals(array('MyMoney' => 'Money', 'OverriddenMoney' => 'Money'), DataObject::composite_fields('DBCompositeTest_DataObject'));
     $this->assertEquals('Money', DataObject::is_composite_field('SubclassedDBFieldObject', 'MyMoney'));
     $this->assertEquals('Money', DataObject::is_composite_field('SubclassedDBFieldObject', 'OtherMoney'));
     $this->assertFalse(DataObject::is_composite_field('SubclassedDBFieldObject', 'Title'));
     $this->assertFalse(DataObject::is_composite_field('SubclassedDBFieldObject', 'OtherField'));
     $this->assertEquals(array('MyMoney' => 'Money', 'OtherMoney' => 'Money', 'OverriddenMoney' => 'Money'), DataObject::composite_fields('SubclassedDBFieldObject'));
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:14,代码来源:DBCompositeTest.php

示例14: testCompositeFieldMetaDataFunctions

 /**
  * Test DataObject::composite_fields() and DataObject::is_composite_field()
  */
 public function testCompositeFieldMetaDataFunctions()
 {
     $schema = DataObject::getSchema();
     $this->assertEquals('Money', $schema->compositeField(DBCompositeTest_DataObject::class, 'MyMoney'));
     $this->assertNull($schema->compositeField(DBCompositeTest_DataObject::class, 'Title'));
     $this->assertEquals(array('MyMoney' => 'Money', 'OverriddenMoney' => 'Money'), $schema->compositeFields(DBCompositeTest_DataObject::class));
     $this->assertEquals('Money', $schema->compositeField(SubclassedDBFieldObject::class, 'MyMoney'));
     $this->assertEquals('Money', $schema->compositeField(SubclassedDBFieldObject::class, 'OtherMoney'));
     $this->assertNull($schema->compositeField(SubclassedDBFieldObject::class, 'Title'));
     $this->assertNull($schema->compositeField(SubclassedDBFieldObject::class, 'OtherField'));
     $this->assertEquals(array('MyMoney' => 'Money', 'OtherMoney' => 'Money', 'OverriddenMoney' => 'Money'), $schema->compositeFields(SubclassedDBFieldObject::class));
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:15,代码来源:DBCompositeTest.php

示例15: 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


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