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


PHP DataObject::getSchema方法代码示例

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


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

示例1: scaffoldFormField

 public function scaffoldFormField($title = null, $params = null)
 {
     if (empty($this->object)) {
         return null;
     }
     $relationName = substr($this->name, 0, -2);
     $hasOneClass = DataObject::getSchema()->hasOneComponent(get_class($this->object), $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:SpiritLevel,项目名称:silverstripe-framework,代码行数:31,代码来源:DBForeignKey.php

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

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

示例4: foreignIDFilter

 protected function foreignIDFilter($id = null)
 {
     if ($id === null) {
         $id = $this->getForeignID();
     }
     // Apply relation filter
     $key = DataObject::getSchema()->sqlColumnForField($this->dataClass(), $this->getForeignKey());
     if (is_array($id)) {
         return array("{$key} IN (" . DB::placeholders($id) . ")" => $id);
     } else {
         if ($id !== null) {
             return array($key => $id);
         }
     }
     return null;
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:16,代码来源:HasManyList.php

示例5: getBaseClass

 /**
  * Get the base dataclass for the list of subclasses
  *
  * @return string
  */
 public function getBaseClass()
 {
     // Use explicit base class
     if ($this->baseClass) {
         return $this->baseClass;
     }
     // Default to the basename of the record
     $schema = DataObject::getSchema();
     if ($this->record) {
         return $schema->baseDataClass($this->record);
     }
     // During dev/build only the table is assigned
     $tableClass = $schema->tableClass($this->getTable());
     if ($tableClass && ($baseClass = $schema->baseDataClass($tableClass))) {
         return $baseClass;
     }
     // Fallback to global default
     return 'SilverStripe\\ORM\\DataObject';
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:24,代码来源:DBClassName.php

示例6: getIsMultiUpload

 /**
  * Check if allowed to upload more than one file
  *
  * @return bool
  */
 public function getIsMultiUpload()
 {
     if (isset($this->multiUpload)) {
         return $this->multiUpload;
     }
     // Guess from record
     $record = $this->getRecord();
     $name = $this->getName();
     // Disabled for has_one components
     if ($record && DataObject::getSchema()->hasOneComponent(get_class($record), $name)) {
         return false;
     }
     return true;
 }
开发者ID:silverstripe,项目名称:silverstripe-asset-admin,代码行数:19,代码来源:UploadField.php

示例7: doBuild


//.........这里部分代码省略.........
             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();
             }
         }
         // Remap obsolete class names
         $schema = DataObject::getSchema();
         foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) {
             $badRecordCount = $newClassName::get()->filter(["ClassName" => $oldClassName])->count();
             if ($badRecordCount > 0) {
                 if (Director::is_cli()) {
                     echo " * Correcting {$badRecordCount} obsolete classname values for {$newClassName}\n";
                 } else {
                     echo "<li>Correcting {$badRecordCount} obsolete classname values for {$newClassName}</li>\n";
                 }
                 $table = $schema->baseDataTable($newClassName);
                 DB::prepared_query("UPDATE \"{$table}\" SET \"ClassName\" = ? WHERE \"ClassName\" = ?", [$newClassName, $oldClassName]);
             }
         }
     }
     touch(TEMP_FOLDER . '/database-last-generated-' . str_replace(array('\\', '/', ':'), '.', Director::baseFolder()));
     if (isset($_REQUEST['from_installer'])) {
         echo "OK";
     }
     if (!$quiet) {
         echo Director::is_cli() ? "\n Database build completed!\n\n" : "<p>Database build completed!</p>";
     }
     ClassInfo::reset_db_cache();
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:101,代码来源:DatabaseAdmin.php

示例8: liveChildren

 /**
  * Return children in the live site, if it exists.
  *
  * @param bool $showAll              Include all of the elements, even those not shown in the menus. Only
  *                                   applicable when extension is applied to {@link SiteTree}.
  * @param bool $onlyDeletedFromStage Only return items that have been deleted from stage
  * @return DataList
  * @throws Exception
  */
 public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
 {
     if (!$this->owner->hasExtension(Versioned::class)) {
         throw new Exception('Hierarchy->liveChildren() only works with Versioned extension applied');
     }
     $baseClass = $this->owner->baseClass();
     $hide_from_hierarchy = $this->owner->config()->hide_from_hierarchy;
     $hide_from_cms_tree = $this->owner->config()->hide_from_cms_tree;
     $children = $baseClass::get()->filter('ParentID', (int) $this->owner->ID)->exclude('ID', (int) $this->owner->ID)->setDataQueryParam(array('Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage', 'Versioned.stage' => 'Live'));
     if ($hide_from_hierarchy) {
         $children = $children->exclude('ClassName', $hide_from_hierarchy);
     }
     if ($hide_from_cms_tree && $this->showingCMSTree()) {
         $children = $children->exclude('ClassName', $hide_from_cms_tree);
     }
     if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
         $children = $children->filter('ShowInMenus', 1);
     }
     return $children;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:29,代码来源:Hierarchy.php

示例9: processRecord

 /**
  * @todo Better messages for relation checks and duplicate detection
  * Note that columnMap isn't used.
  *
  * @param array $record
  * @param array $columnMap
  * @param BulkLoader_Result $results
  * @param boolean $preview
  *
  * @return int
  */
 protected function processRecord($record, $columnMap, &$results, $preview = false)
 {
     $class = $this->objectClass;
     // find existing object, or create new one
     $existingObj = $this->findExistingObject($record, $columnMap);
     /** @var DataObject $obj */
     $obj = $existingObj ? $existingObj : new $class();
     $schema = DataObject::getSchema();
     // first run: find/create any relations and store them on the object
     // we can't combine runs, as other columns might rely on the relation being present
     foreach ($record as $fieldName => $val) {
         // don't bother querying of value is not set
         if ($this->isNullValue($val)) {
             continue;
         }
         // checking for existing relations
         if (isset($this->relationCallbacks[$fieldName])) {
             // trigger custom search method for finding a relation based on the given value
             // and write it back to the relation (or create a new object)
             $relationName = $this->relationCallbacks[$fieldName]['relationname'];
             /** @var DataObject $relationObj */
             $relationObj = null;
             if ($this->hasMethod($this->relationCallbacks[$fieldName]['callback'])) {
                 $relationObj = $this->{$this->relationCallbacks[$fieldName]['callback']}($obj, $val, $record);
             } elseif ($obj->hasMethod($this->relationCallbacks[$fieldName]['callback'])) {
                 $relationObj = $obj->{$this->relationCallbacks[$fieldName]['callback']}($val, $record);
             }
             if (!$relationObj || !$relationObj->exists()) {
                 $relationClass = $schema->hasOneComponent(get_class($obj), $relationName);
                 $relationObj = new $relationClass();
                 //write if we aren't previewing
                 if (!$preview) {
                     $relationObj->write();
                 }
             }
             $obj->{"{$relationName}ID"} = $relationObj->ID;
             //write if we are not previewing
             if (!$preview) {
                 $obj->write();
                 $obj->flushCache();
                 // avoid relation caching confusion
             }
         } elseif (strpos($fieldName, '.') !== false) {
             // we have a relation column with dot notation
             list($relationName, $columnName) = explode('.', $fieldName);
             // always gives us an component (either empty or existing)
             $relationObj = $obj->getComponent($relationName);
             if (!$preview) {
                 $relationObj->write();
             }
             $obj->{"{$relationName}ID"} = $relationObj->ID;
             //write if we are not previewing
             if (!$preview) {
                 $obj->write();
                 $obj->flushCache();
                 // avoid relation caching confusion
             }
         }
     }
     // second run: save data
     foreach ($record as $fieldName => $val) {
         // break out of the loop if we are previewing
         if ($preview) {
             break;
         }
         // look up the mapping to see if this needs to map to callback
         $mapped = $this->columnMap && isset($this->columnMap[$fieldName]);
         if ($mapped && strpos($this->columnMap[$fieldName], '->') === 0) {
             $funcName = substr($this->columnMap[$fieldName], 2);
             $this->{$funcName}($obj, $val, $record);
         } else {
             if ($obj->hasMethod("import{$fieldName}")) {
                 $obj->{"import{$fieldName}"}($val, $record);
             } else {
                 $obj->update(array($fieldName => $val));
             }
         }
     }
     // write record
     if (!$preview) {
         $obj->write();
     }
     // @todo better message support
     $message = '';
     // save to results
     if ($existingObj) {
         $results->addUpdated($obj, $message);
     } else {
         $results->addCreated($obj, $message);
//.........这里部分代码省略.........
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:101,代码来源:CsvBulkLoader.php

示例10: get_version

 /**
  * Return the specific version of the given id.
  *
  * Caution: The record is retrieved as a DataObject, but saving back
  * modifications via write() will create a new version, rather than
  * modifying the existing one.
  *
  * @param string $class
  * @param int $id
  * @param int $version
  *
  * @return DataObject
  */
 public static function get_version($class, $id, $version)
 {
     $baseClass = DataObject::getSchema()->baseDataClass($class);
     $list = DataList::create($baseClass)->setDataQueryParam(["Versioned.mode" => 'version', "Versioned.version" => $version]);
     return $list->byID($id);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:19,代码来源:Versioned.php

示例11: prepareColumns

 /**
  * Adds table identifier to the every column.
  * Columns must have table identifier to prevent duplicate column name error.
  *
  * @param array $columns
  * @return string
  */
 protected function prepareColumns($columns)
 {
     $cols = preg_split('/"?\\s*,\\s*"?/', trim($columns, '(") '));
     $table = DataObject::getSchema()->tableForField($this->model, current($cols));
     $cols = array_map(function ($col) use($table) {
         return sprintf('"%s"."%s"', $table, $col);
     }, $cols);
     return implode(',', $cols);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:16,代码来源:FulltextFilter.php

示例12: testGetRemoteJoinField

 public function testGetRemoteJoinField()
 {
     $schema = DataObject::getSchema();
     // Company schema
     $staffJoinField = $schema->getRemoteJoinField(DataObjectTest_Company::class, 'CurrentStaff', 'has_many', $polymorphic);
     $this->assertEquals('CurrentCompanyID', $staffJoinField);
     $this->assertFalse($polymorphic, 'DataObjectTest_Company->CurrentStaff is not polymorphic');
     $previousStaffJoinField = $schema->getRemoteJoinField(DataObjectTest_Company::class, 'PreviousStaff', 'has_many', $polymorphic);
     $this->assertEquals('PreviousCompanyID', $previousStaffJoinField);
     $this->assertFalse($polymorphic, 'DataObjectTest_Company->PreviousStaff is not polymorphic');
     // CEO Schema
     $this->assertEquals('CEOID', $schema->getRemoteJoinField(DataObjectTest_CEO::class, 'Company', 'belongs_to', $polymorphic));
     $this->assertFalse($polymorphic, 'DataObjectTest_CEO->Company is not polymorphic');
     $this->assertEquals('PreviousCEOID', $schema->getRemoteJoinField(DataObjectTest_CEO::class, 'PreviousCompany', 'belongs_to', $polymorphic));
     $this->assertFalse($polymorphic, 'DataObjectTest_CEO->PreviousCompany is not polymorphic');
     // Team schema
     $this->assertEquals('Favourite', $schema->getRemoteJoinField(DataObjectTest_Team::class, 'Fans', 'has_many', $polymorphic));
     $this->assertTrue($polymorphic, 'DataObjectTest_Team->Fans is polymorphic');
     $this->assertEquals('TeamID', $schema->getRemoteJoinField(DataObjectTest_Team::class, 'Comments', 'has_many', $polymorphic));
     $this->assertFalse($polymorphic, 'DataObjectTest_Team->Comments is not polymorphic');
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:21,代码来源:DataObjectTest.php

示例13: saveInto

 /**
  * @param DataObject|DataObjectInterface $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     if (!isset($_FILES[$this->name])) {
         return;
     }
     $fileClass = File::get_class_for_file_extension(File::get_file_extension($_FILES[$this->name]['name']));
     /** @var File $file */
     if ($this->relationAutoSetting) {
         // assume that the file is connected via a has-one
         $objectClass = DataObject::getSchema()->hasOneComponent(get_class($record), $this->name);
         if ($objectClass === File::class || empty($objectClass)) {
             // Create object of the appropriate file class
             $file = Object::create($fileClass);
         } else {
             // try to create a file matching the relation
             $file = Object::create($objectClass);
         }
     } else {
         if ($record instanceof File) {
             $file = $record;
         } else {
             $file = Object::create($fileClass);
         }
     }
     $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->getFolderName());
     if ($this->upload->isError()) {
         return;
     }
     if ($this->relationAutoSetting) {
         if (empty($objectClass)) {
             return;
         }
         $file = $this->upload->getFile();
         $record->{$this->name . 'ID'} = $file->ID;
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:39,代码来源:FileField.php

示例14: applyBaseTableFields

 /**
  * @todo move to SQLSelect
  * @todo fix hack
  */
 protected function applyBaseTableFields()
 {
     $classes = ClassInfo::dataClassesFor($this->modelClass);
     $baseTable = DataObject::getSchema()->baseDataTable($this->modelClass);
     $fields = array("\"{$baseTable}\".*");
     if ($this->modelClass != $classes[0]) {
         $fields[] = '"' . $classes[0] . '".*';
     }
     //$fields = array_keys($model->db());
     $fields[] = '"' . $classes[0] . '".\\"ClassName\\" AS "RecordClassName"';
     return $fields;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:16,代码来源:SearchContext.php

示例15: searchEngine

 /**
  * The core search engine, used by this class and its subclasses to do fun stuff.
  * Searches both SiteTree and File.
  *
  * @param array $classesToSearch
  * @param string $keywords Keywords as a string.
  * @param int $start
  * @param int $pageLength
  * @param string $sortBy
  * @param string $extraFilter
  * @param bool $booleanSearch
  * @param string $alternativeFileFilter
  * @param bool $invertedMatch
  * @return PaginatedList
  * @throws Exception
  */
 public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false)
 {
     $pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
     $fileClass = 'File';
     $pageTable = DataObject::getSchema()->tableName($pageClass);
     $fileTable = DataObject::getSchema()->tableName($fileClass);
     if (!class_exists($pageClass)) {
         throw new Exception('MySQLDatabase->searchEngine() requires "SiteTree" class');
     }
     if (!class_exists($fileClass)) {
         throw new Exception('MySQLDatabase->searchEngine() requires "File" class');
     }
     $keywords = $this->escapeString($keywords);
     $htmlEntityKeywords = htmlentities($keywords, ENT_NOQUOTES, 'UTF-8');
     $extraFilters = array($pageClass => '', $fileClass => '');
     if ($booleanSearch) {
         $boolean = "IN BOOLEAN MODE";
     }
     if ($extraFilter) {
         $extraFilters[$pageClass] = " AND {$extraFilter}";
         if ($alternativeFileFilter) {
             $extraFilters[$fileClass] = " AND {$alternativeFileFilter}";
         } else {
             $extraFilters[$fileClass] = $extraFilters[$pageClass];
         }
     }
     // Always ensure that only pages with ShowInSearch = 1 can be searched
     $extraFilters[$pageClass] .= " AND ShowInSearch <> 0";
     // File.ShowInSearch was added later, keep the database driver backwards compatible
     // by checking for its existence first
     $fields = $this->getSchemaManager()->fieldList($fileTable);
     if (array_key_exists('ShowInSearch', $fields)) {
         $extraFilters[$fileClass] .= " AND ShowInSearch <> 0";
     }
     $limit = $start . ", " . (int) $pageLength;
     $notMatch = $invertedMatch ? "NOT " : "";
     if ($keywords) {
         $match[$pageClass] = "\n\t\t\t\tMATCH (Title, MenuTitle, Content, MetaDescription) AGAINST ('{$keywords}' {$boolean})\n\t\t\t\t+ MATCH (Title, MenuTitle, Content, MetaDescription) AGAINST ('{$htmlEntityKeywords}' {$boolean})\n\t\t\t";
         $fileClassSQL = Convert::raw2sql($fileClass);
         $match[$fileClass] = "MATCH (Name, Title) AGAINST ('{$keywords}' {$boolean}) AND ClassName = '{$fileClassSQL}'";
         // We make the relevance search by converting a boolean mode search into a normal one
         $relevanceKeywords = str_replace(array('*', '+', '-'), '', $keywords);
         $htmlEntityRelevanceKeywords = str_replace(array('*', '+', '-'), '', $htmlEntityKeywords);
         $relevance[$pageClass] = "MATCH (Title, MenuTitle, Content, MetaDescription) " . "AGAINST ('{$relevanceKeywords}') " . "+ MATCH (Title, MenuTitle, Content, MetaDescription) AGAINST ('{$htmlEntityRelevanceKeywords}')";
         $relevance[$fileClass] = "MATCH (Name, Title) AGAINST ('{$relevanceKeywords}')";
     } else {
         $relevance[$pageClass] = $relevance[$fileClass] = 1;
         $match[$pageClass] = $match[$fileClass] = "1 = 1";
     }
     // Generate initial DataLists and base table names
     $lists = array();
     $baseClasses = array($pageClass => '', $fileClass => '');
     foreach ($classesToSearch as $class) {
         $lists[$class] = DataList::create($class)->where($notMatch . $match[$class] . $extraFilters[$class], "");
         $baseClasses[$class] = '"' . $class . '"';
     }
     $charset = Config::inst()->get('SilverStripe\\ORM\\Connect\\MySQLDatabase', 'charset');
     // Make column selection lists
     $select = array($pageClass => array("ClassName", "{$pageTable}.\"ID\"", "ParentID", "Title", "MenuTitle", "URLSegment", "Content", "LastEdited", "Created", "Name" => "_{$charset}''", "Relevance" => $relevance[$pageClass], "CanViewType"), $fileClass => array("ClassName", "{$fileTable}.\"ID\"", "ParentID", "Title", "MenuTitle" => "_{$charset}''", "URLSegment" => "_{$charset}''", "Content" => "_{$charset}''", "LastEdited", "Created", "Name", "Relevance" => $relevance[$fileClass], "CanViewType" => "NULL"));
     // Process and combine queries
     $querySQLs = array();
     $queryParameters = array();
     $totalCount = 0;
     foreach ($lists as $class => $list) {
         $table = DataObject::getSchema()->tableName($class);
         /** @var SQLSelect $query */
         $query = $list->dataQuery()->query();
         // There's no need to do all that joining
         $query->setFrom($table);
         $query->setSelect($select[$class]);
         $query->setOrderBy(array());
         $querySQLs[] = $query->sql($parameters);
         $queryParameters = array_merge($queryParameters, $parameters);
         $totalCount += $query->unlimitedRowCount();
     }
     $fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY {$sortBy} LIMIT {$limit}";
     // Get records
     $records = $this->preparedQuery($fullQuery, $queryParameters);
     $objects = array();
     foreach ($records as $record) {
         $objects[] = new $record['ClassName']($record);
     }
     $list = new PaginatedList(new ArrayList($objects));
     $list->setPageStart($start);
//.........这里部分代码省略.........
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:101,代码来源:MySQLDatabase.php


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