本文整理汇总了PHP中DataList::Count方法的典型用法代码示例。如果您正苦于以下问题:PHP DataList::Count方法的具体用法?PHP DataList::Count怎么用?PHP DataList::Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataList
的用法示例。
在下文中一共展示了DataList::Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_default_content
/**
* Adds default content to a page or DataObject
*
* @todo Migrate this to a decorator. DataObjects should know how to seed themeselves.
* @param DataObject The object to modify
* @param integer The level to which to seed content (see "silversmith help")
* @param array Limit the seeding to certain fields
*/
public static function add_default_content(&$object, $level, $onlyFields = array())
{
if ($level < 2) {
return;
}
$fields = array();
if (!empty($onlyFields)) {
foreach ($onlyFields as $f) {
$fields[] = trim($f);
}
}
$site_tree = singleton('SiteTree');
$data_object = singleton('DataObject');
$is_sitetree = $object->class == "SiteTree" || is_subclass_of($object, "SiteTree");
foreach ($object->db() as $field => $type) {
if ($data_object->db($field) || $is_sitetree && $site_tree->db($field) || !empty($fields) && !in_array($field, $fields)) {
continue;
}
if (!$object->{$field}) {
if (strstr($field, "Email")) {
$object->{$field} = preg_replace('/[^a-z@\\.]/', '', strtolower(self::get_lipsum_words(1) . "@" . self::get_lipsum_words(1) . ".com"));
} elseif (strstr($field, "Phone")) {
$object->{$field} = rand(100, 999) . "-" . rand(100, 999) . "-" . rand(100, 999);
} else {
$object->{$field} = self::get_default_content($object->obj($field));
}
}
}
foreach ($object->has_one() as $relation => $class) {
if ($data_object->has_one($relation) || $site_tree->has_one($relation) || !empty($fields) && !in_array($relation, $fields)) {
continue;
}
$filter = $class == "File" ? "ClassName = 'File'" : null;
$o = DataList::create($class)->where($filter)->sort("RAND()")->first();
if ($o) {
$key = $relation . "ID";
$object->{$key} = $o->ID;
}
}
if ($level > 2) {
foreach ($object->has_many() as $relation => $class) {
if ($data_object->has_many($relation) || $site_tree->has_many($relation) || !SilverSmithProject::get_node($class) || !empty($fields) && !in_array($relation, $fields)) {
continue;
}
if ($name = array_search($object->class, singleton($class)->has_one())) {
$key = $name . "ID";
$count = rand(1, 5);
for ($i = 0; $i <= $count; $i++) {
if ($candidate = DataList::create($class)->where("{$key} = 0 OR {$key} IS NULL")->first()) {
$candidate->{$key} = $object->ID;
$candidate->write();
} elseif (!is_subclass_of($class, "SiteTree") && !is_subclass_of($class, "File")) {
$related = new $class();
$related->{$key} = $object->ID;
$related->write();
self::add_default_content($related, $level);
$related->write();
} else {
// We don't create a site tree object for the has many, because it will mess up the hierarchy.
}
}
}
}
foreach ((array) $object->stat('many_many') as $relation => $class) {
if ($class == $object->class || is_subclass_of($class, $object->class)) {
continue;
}
if ($data_object->many_many($relation) || $site_tree->many_many($relation) || !SilverSmithProject::get_node($class) || !empty($fields) && !in_array($relation, $fields)) {
continue;
}
$table = $object->class . "_" . $relation;
$parentKey = $object->class . "ID";
$childKey = $class . "ID";
$set = DataList::create($class)->sort("RAND()")->limit(5);
if (!$set) {
$set = new DataList();
}
// never create sitetree or file objects.
if (!is_subclass_of($class, "SiteTree") && !is_subclass_of($class, "File") && $class != $object->class) {
$count = $set->Count();
while ($count < 5) {
$related = new $class();
$related->write();
self::add_default_content($related, $level);
$related->write();
$count++;
}
}
$set = DataList::create($class)->sort("RAND()")->limit(rand(1, 5));
if ($set) {
$object->{$relation}()->setByIDList($set->column('ID'));
}
//.........这里部分代码省略.........