本文整理汇总了PHP中SilverStripe\ORM\DataObject::has_own_table方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::has_own_table方法的具体用法?PHP DataObject::has_own_table怎么用?PHP DataObject::has_own_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SilverStripe\ORM\DataObject
的用法示例。
在下文中一共展示了DataObject::has_own_table方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ancestry
/**
* Returns the passed class name along with all its parent class names in an
* array, sorted with the root class first.
*
* @param string $class
* @param bool $tablesOnly Only return classes that have a table in the db.
* @return array
*/
public static function ancestry($class, $tablesOnly = false)
{
if (is_string($class) && !class_exists($class)) {
return array();
}
$class = self::class_name($class);
$lClass = strtolower($class);
$cacheKey = $lClass . '_' . (string) $tablesOnly;
$parent = $class;
if (!isset(self::$_cache_ancestry[$cacheKey])) {
$ancestry = array();
do {
if (!$tablesOnly || DataObject::has_own_table($parent)) {
$ancestry[$parent] = $parent;
}
} while ($parent = get_parent_class($parent));
self::$_cache_ancestry[$cacheKey] = array_reverse($ancestry);
}
return self::$_cache_ancestry[$cacheKey];
}
示例2: canBeVersioned
/**
* Determine if a class is supporting the Versioned extensions (e.g.
* $table_versions does exists).
*
* @param string $class Class name
* @return boolean
*/
public function canBeVersioned($class)
{
return ClassInfo::exists($class) && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject') && DataObject::has_own_table($class);
}
示例3: cleanup
/**
* Remove invalid records from tables - that is, records that don't have
* corresponding records in their parent class tables.
*/
public function cleanup()
{
$allClasses = get_declared_classes();
foreach ($allClasses as $class) {
if (get_parent_class($class) == 'SilverStripe\\ORM\\DataObject') {
$baseClasses[] = $class;
}
}
foreach ($baseClasses as $baseClass) {
// Get data classes
$subclasses = ClassInfo::subclassesFor($baseClass);
unset($subclasses[0]);
foreach ($subclasses as $k => $subclass) {
if (DataObject::has_own_table($subclass)) {
unset($subclasses[$k]);
}
}
if ($subclasses) {
$records = DB::query("SELECT * FROM \"{$baseClass}\"");
foreach ($subclasses as $subclass) {
$recordExists[$subclass] = DB::query("SELECT \"ID\" FROM \"{$subclass}\"")->keyedColumn();
}
foreach ($records as $record) {
foreach ($subclasses as $subclass) {
$id = $record['ID'];
if ($record['ClassName'] != $subclass && !is_subclass_of($record['ClassName'], $subclass) && isset($recordExists[$subclass][$id])) {
$sql = "DELETE FROM \"{$subclass}\" WHERE \"ID\" = {$record['ID']}";
echo "<li>{$sql}";
DB::query($sql);
}
}
}
}
}
}
示例4: TestHasOwnTable
public function TestHasOwnTable()
{
/* Test DataObject::has_own_table() returns true if the object has $has_one or $db values */
$this->assertTrue(DataObject::has_own_table("DataObjectTest_Player"));
$this->assertTrue(DataObject::has_own_table("DataObjectTest_Team"));
$this->assertTrue(DataObject::has_own_table("DataObjectTest_Fixture"));
/* Root DataObject that always have a table, even if they lack both $db and $has_one */
$this->assertTrue(DataObject::has_own_table("DataObjectTest_FieldlessTable"));
/* Subclasses without $db or $has_one don't have a table */
$this->assertFalse(DataObject::has_own_table("DataObjectTest_FieldlessSubTable"));
/* Return false if you don't pass it a subclass of DataObject */
$this->assertFalse(DataObject::has_own_table("SilverStripe\\ORM\\DataObject"));
$this->assertFalse(DataObject::has_own_table("ViewableData"));
$this->assertFalse(DataObject::has_own_table("ThisIsntADataObject"));
}