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


PHP DataObject::get方法代码示例

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


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

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

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

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

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

示例5: testLoadDataFromObject

 public function testLoadDataFromObject()
 {
     $article = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithouttags');
     $articleWithTags = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithtags');
     $tag1 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag1');
     $tag2 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag2');
     $field = new CheckboxSetField("Tags", "Test field", DataObject::get("CheckboxSetFieldTest_Tag")->map());
     $form = new Form(new Controller(), 'Form', new FieldList($field), new FieldList());
     $form->loadDataFrom($articleWithTags);
     $value = $field->Value();
     sort($value);
     $this->assertEquals(array($tag1->ID, $tag2->ID), $value, 'CheckboxSetField loads data from a manymany relationship in an object through Form->loadDataFrom()');
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:13,代码来源:CheckboxSetFieldTest.php

示例6: testDeleteExistingRecords

 /**
  * Test plain import with clear_table_before_import
  */
 public function testDeleteExistingRecords()
 {
     $loader = new CsvBulkLoader('CsvBulkLoaderTest_Player');
     $filepath = $this->getCurrentAbsolutePath() . '/CsvBulkLoaderTest_PlayersWithHeader.csv';
     $loader->deleteExistingRecords = true;
     $results1 = $loader->load($filepath);
     $this->assertEquals(4, $results1->Count(), 'Test correct count of imported data on first load');
     //delete existing data before doing second CSV import
     $results2 = $loader->load($filepath, '512MB', true);
     //get all instances of the loaded DataObject from the database and count them
     $resultDataObject = DataObject::get('CsvBulkLoaderTest_Player');
     $this->assertEquals(4, $resultDataObject->Count(), 'Test if existing data is deleted before new data is added');
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:16,代码来源:CsvBulkLoaderTest.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     Versioned::set_stage(Versioned::DRAFT);
     // Automatically publish any object named *_published
     foreach ($this->getFixtureFactory()->getFixtures() as $class => $fixtures) {
         foreach ($fixtures as $name => $id) {
             if (stripos($name, '_published') !== false) {
                 /** @var Versioned|DataObject $object */
                 $object = DataObject::get($class)->byID($id);
                 $object->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
             }
         }
     }
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:15,代码来源:VersionedOwnershipTest.php

示例8: onBeforeWrite

 /**
  * Ensure that changes to records flush overwritten files, and update the visibility
  * of other assets.
  */
 public function onBeforeWrite()
 {
     // Prepare blank manipulation
     $manipulations = new AssetManipulationList();
     // Mark overwritten object as deleted
     if ($this->owner->isInDB()) {
         $priorRecord = DataObject::get(get_class($this->owner))->byID($this->owner->ID);
         if ($priorRecord) {
             $this->addAssetsFromRecord($manipulations, $priorRecord, AssetManipulationList::STATE_DELETED);
         }
     }
     // Add assets from new record with the correct visibility rules
     $state = $this->getRecordState($this->owner);
     $this->addAssetsFromRecord($manipulations, $this->owner, $state);
     // Whitelist assets that exist in other stages
     $this->addAssetsFromOtherStages($manipulations);
     // Apply visibility rules based on the final manipulation
     $this->processManipulation($manipulations);
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:23,代码来源:AssetControlExtension.php

示例9: testItemMarkingIsntRestrictedToSpecificInstance

 /**
  * Test that you can call Hierarchy::markExpanded/Unexpanded/Open() on a obj, and that
  * calling Hierarchy::isMarked() on a different instance of that object will return true.
  */
 public function testItemMarkingIsntRestrictedToSpecificInstance()
 {
     // Mark a few objs
     $this->objFromFixture('HierarchyTest_Object', 'obj2')->markExpanded();
     $this->objFromFixture('HierarchyTest_Object', 'obj2a')->markExpanded();
     $this->objFromFixture('HierarchyTest_Object', 'obj2b')->markExpanded();
     $this->objFromFixture('HierarchyTest_Object', 'obj3')->markUnexpanded();
     // Query some objs in a different context and check their m
     $objs = DataObject::get("HierarchyTest_Object", '', '"ID" ASC');
     $marked = $expanded = array();
     foreach ($objs as $obj) {
         if ($obj->isMarked()) {
             $marked[] = $obj->Title;
         }
         if ($obj->isExpanded()) {
             $expanded[] = $obj->Title;
         }
     }
     $this->assertEquals(array('Obj 2', 'Obj 3', 'Obj 2a', 'Obj 2b'), $marked);
     $this->assertEquals(array('Obj 2', 'Obj 2a', 'Obj 2b'), $expanded);
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:25,代码来源:HierarchyTest.php

示例10: testSaveInto

 public function testSaveInto()
 {
     $group = $this->objFromFixture('SilverStripe\\Security\\Group', 'group');
     // tested group
     $untouchable = $this->objFromFixture('SilverStripe\\Security\\Group', 'untouchable');
     // group that should not change
     $field = new PermissionCheckboxSetField('Permissions', 'Permissions', 'SilverStripe\\Security\\Permission', 'GroupID', $group);
     // get the number of permissions before we start
     $baseCount = DataObject::get('SilverStripe\\Security\\Permission')->Count();
     // there are currently no permissions, save empty checkbox
     $field->saveInto($group);
     $group->flushCache();
     $untouchable->flushCache();
     $this->assertEquals($group->Permissions()->Count(), 0, 'The tested group has no permissions');
     $this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
     $this->assertEquals($untouchable->Permissions()->where("\"Code\"='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
     $this->assertEquals(DataObject::get('SilverStripe\\Security\\Permission')->Count(), $baseCount, 'There are no orphaned permissions');
     // add some permissions
     $field->setValue(array('ADMIN' => true, 'NON-ADMIN' => true));
     $field->saveInto($group);
     $group->flushCache();
     $untouchable->flushCache();
     $this->assertEquals($group->Permissions()->Count(), 2, 'The tested group has two permissions permission');
     $this->assertEquals($group->Permissions()->where("\"Code\"='ADMIN'")->Count(), 1, 'The tested group has ADMIN permission');
     $this->assertEquals($group->Permissions()->where("\"Code\"='NON-ADMIN'")->Count(), 1, 'The tested group has CMS_ACCESS_AssetAdmin permission');
     $this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
     $this->assertEquals($untouchable->Permissions()->where("\"Code\"='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
     $this->assertEquals(DataObject::get('SilverStripe\\Security\\Permission')->Count(), $baseCount + 2, 'There are no orphaned permissions');
     // remove permission
     $field->setValue(array('ADMIN' => true));
     $field->saveInto($group);
     $group->flushCache();
     $untouchable->flushCache();
     $this->assertEquals($group->Permissions()->Count(), 1, 'The tested group has 1 permission');
     $this->assertEquals($group->Permissions()->where("\"Code\"='ADMIN'")->Count(), 1, 'The tested group has ADMIN permission');
     $this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
     $this->assertEquals($untouchable->Permissions()->where("\"Code\"='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
     $this->assertEquals(DataObject::get('SilverStripe\\Security\\Permission')->Count(), $baseCount + 1, 'There are no orphaned permissions');
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:39,代码来源:PermissionCheckboxSetFieldTest.php

示例11: foreignIDFilter

 /**
  * Link this group set to a specific member.
  *
  * Recursively selects all groups applied to this member, as well as any
  * parent groups of any applied groups
  *
  * @param array|integer $id (optional) An ID or an array of IDs - if not provided, will use the current
  * ids as per getForeignID
  * @return array Condition In array(SQL => parameters format)
  */
 public function foreignIDFilter($id = null)
 {
     if ($id === null) {
         $id = $this->getForeignID();
     }
     // Find directly applied groups
     $manyManyFilter = parent::foreignIDFilter($id);
     $query = new SQLSelect('"Group_Members"."GroupID"', '"Group_Members"', $manyManyFilter);
     $groupIDs = $query->execute()->column();
     // Get all ancestors, iteratively merging these into the master set
     $allGroupIDs = array();
     while ($groupIDs) {
         $allGroupIDs = array_merge($allGroupIDs, $groupIDs);
         $groupIDs = DataObject::get("SilverStripe\\Security\\Group")->byIDs($groupIDs)->column("ParentID");
         $groupIDs = array_filter($groupIDs);
     }
     // Add a filter to this DataList
     if (!empty($allGroupIDs)) {
         $allGroupIDsPlaceholders = DB::placeholders($allGroupIDs);
         return array("\"Group\".\"ID\" IN ({$allGroupIDsPlaceholders})" => $allGroupIDs);
     } else {
         return array('"Group"."ID"' => 0);
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:34,代码来源:Member_GroupSet.php

示例12: siteTreeSearchCallback

 /**
  * Searches the SiteTree for display in the dropdown
  *
  * @return callback
  */
 public function siteTreeSearchCallback($sourceObject, $labelField, $search)
 {
     return DataObject::get($sourceObject)->filterAny(array('MenuTitle:PartialMatch' => $search, 'Title:PartialMatch' => $search));
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:9,代码来源:HTMLEditorField.php

示例13: findExistingObject

 /**
  * Find an existing objects based on one or more uniqueness columns
  * specified via {@link self::$duplicateChecks}.
  *
  * @todo support $columnMap
  *
  * @param array $record CSV data column
  * @param array $columnMap
  * @return DataObject
  */
 public function findExistingObject($record, $columnMap = [])
 {
     $SNG_objectClass = singleton($this->objectClass);
     // checking for existing records (only if not already found)
     foreach ($this->duplicateChecks as $fieldName => $duplicateCheck) {
         $existingRecord = null;
         if (is_string($duplicateCheck)) {
             // Skip current duplicate check if field value is empty
             if (empty($record[$duplicateCheck])) {
                 continue;
             }
             // Check existing record with this value
             $dbFieldValue = $record[$duplicateCheck];
             $existingRecord = DataObject::get($this->objectClass)->filter($duplicateCheck, $dbFieldValue)->first();
             if ($existingRecord) {
                 return $existingRecord;
             }
         } elseif (is_array($duplicateCheck) && isset($duplicateCheck['callback'])) {
             if ($this->hasMethod($duplicateCheck['callback'])) {
                 $existingRecord = $this->{$duplicateCheck['callback']}($record[$fieldName], $record);
             } elseif ($SNG_objectClass->hasMethod($duplicateCheck['callback'])) {
                 $existingRecord = $SNG_objectClass->{$duplicateCheck['callback']}($record[$fieldName], $record);
             } else {
                 user_error("CsvBulkLoader::processRecord():" . " {$duplicateCheck['callback']} not found on importer or object class.", E_USER_ERROR);
             }
             if ($existingRecord) {
                 return $existingRecord;
             }
         } else {
             user_error('CsvBulkLoader::processRecord(): Wrong format for $duplicateChecks', E_USER_ERROR);
         }
     }
     return false;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:44,代码来源:CsvBulkLoader.php

示例14: updatetreenodes

 /**
  * Allows requesting a view update on specific tree nodes.
  * Similar to {@link getsubtree()}, but doesn't enforce loading
  * all children with the node. Useful to refresh views after
  * state modifications, e.g. saving a form.
  *
  * @param HTTPRequest $request
  * @return string JSON
  */
 public function updatetreenodes($request)
 {
     $data = array();
     $ids = explode(',', $request->getVar('ids'));
     foreach ($ids as $id) {
         if ($id === "") {
             continue;
         }
         // $id may be a blank string, which is invalid and should be skipped over
         $record = $this->getRecord($id);
         if (!$record) {
             continue;
         }
         // In case a page is no longer available
         $recordController = $this->stat('tree_class') == 'SilverStripe\\CMS\\Model\\SiteTree' ? CMSPageEditController::singleton() : $this;
         // Find the next & previous nodes, for proper positioning (Sort isn't good enough - it's not a raw offset)
         // TODO: These methods should really be in hierarchy - for a start it assumes Sort exists
         $next = $prev = null;
         $className = $this->stat('tree_class');
         $next = DataObject::get($className)->filter('ParentID', $record->ParentID)->filter('Sort:GreaterThan', $record->Sort)->first();
         if (!$next) {
             $prev = DataObject::get($className)->filter('ParentID', $record->ParentID)->filter('Sort:LessThan', $record->Sort)->reverse()->first();
         }
         $link = Controller::join_links($recordController->Link("show"), $record->ID);
         $html = LeftAndMain_TreeNode::create($record, $link, $this->isCurrentPage($record))->forTemplate() . '</li>';
         $data[$id] = array('html' => $html, 'ParentID' => $record->ParentID, 'NextID' => $next ? $next->ID : null, 'PrevID' => $prev ? $prev->ID : null);
     }
     $this->getResponse()->addHeader('Content-Type', 'text/json');
     return Convert::raw2json($data);
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:39,代码来源:LeftAndMain.php

示例15: doBuild

 /**
  * Updates the database schema, creating tables & fields as necessary.
  *
  * @param boolean $quiet Don't show messages
  * @param boolean $populate Populate the database, as well as setting up its schema
  * @param bool $testMode
  */
 public function doBuild($quiet = false, $populate = true, $testMode = false)
 {
     if ($quiet) {
         DB::quiet();
     } else {
         $conn = DB::get_conn();
         // Assumes database class is like "MySQLDatabase" or "MSSQLDatabase" (suffixed with "Database")
         $dbType = substr(get_class($conn), 0, -8);
         $dbVersion = $conn->getVersion();
         $databaseName = method_exists($conn, 'currentDatabase') ? $conn->getSelectedDatabase() : "";
         if (Director::is_cli()) {
             echo sprintf("\n\nBuilding database %s using %s %s\n\n", $databaseName, $dbType, $dbVersion);
         } else {
             echo sprintf("<h2>Building database %s using %s %s</h2>", $databaseName, $dbType, $dbVersion);
         }
     }
     // Set up the initial database
     if (!DB::is_active()) {
         if (!$quiet) {
             echo '<p><b>Creating database</b></p>';
         }
         // Load parameters from existing configuration
         global $databaseConfig;
         if (empty($databaseConfig) && empty($_REQUEST['db'])) {
             user_error("No database configuration available", E_USER_ERROR);
         }
         $parameters = !empty($databaseConfig) ? $databaseConfig : $_REQUEST['db'];
         // Check database name is given
         if (empty($parameters['database'])) {
             user_error("No database name given; please give a value for \$databaseConfig['database']", E_USER_ERROR);
         }
         $database = $parameters['database'];
         // Establish connection and create database in two steps
         unset($parameters['database']);
         DB::connect($parameters);
         DB::create_database($database);
     }
     // Build the database.  Most of the hard work is handled by DataObject
     $dataClasses = ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject');
     array_shift($dataClasses);
     if (!$quiet) {
         if (Director::is_cli()) {
             echo "\nCREATING DATABASE TABLES\n\n";
         } else {
             echo "\n<p><b>Creating database tables</b></p>\n\n";
         }
     }
     // Initiate schema update
     $dbSchema = DB::get_schema();
     $dbSchema->schemaUpdate(function () use($dataClasses, $testMode, $quiet) {
         foreach ($dataClasses as $dataClass) {
             // Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
             if (!class_exists($dataClass)) {
                 continue;
             }
             // Check if this class should be excluded as per testing conventions
             $SNG = singleton($dataClass);
             if (!$testMode && $SNG instanceof TestOnly) {
                 continue;
             }
             // Log data
             if (!$quiet) {
                 if (Director::is_cli()) {
                     echo " * {$dataClass}\n";
                 } else {
                     echo "<li>{$dataClass}</li>\n";
                 }
             }
             // Instruct the class to apply its schema to the database
             $SNG->requireTable();
         }
     });
     ClassInfo::reset_db_cache();
     if ($populate) {
         if (!$quiet) {
             if (Director::is_cli()) {
                 echo "\nCREATING DATABASE RECORDS\n\n";
             } else {
                 echo "\n<p><b>Creating database records</b></p>\n\n";
             }
         }
         foreach ($dataClasses as $dataClass) {
             // Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
             // Test_ indicates that it's the data class is part of testing system
             if (strpos($dataClass, 'Test_') === false && class_exists($dataClass)) {
                 if (!$quiet) {
                     if (Director::is_cli()) {
                         echo " * {$dataClass}\n";
                     } else {
                         echo "<li>{$dataClass}</li>\n";
                     }
                 }
                 singleton($dataClass)->requireDefaultRecords();
//.........这里部分代码省略.........
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:101,代码来源:DatabaseAdmin.php


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