本文整理汇总了PHP中DataGenerator::generateParents方法的典型用法代码示例。如果您正苦于以下问题:PHP DataGenerator::generateParents方法的具体用法?PHP DataGenerator::generateParents怎么用?PHP DataGenerator::generateParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataGenerator
的用法示例。
在下文中一共展示了DataGenerator::generateParents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Generate records (populate them with either prepared or default values) and insert into database.
* This method could create parent records (we call "parent" all records in tables where generated
* record has foreign keys linked to).
*
* Returns array ids of created records.
*
* Examples:
*
* // Lazy generate 7 records
* $aMytableIds = DataGenerator::generate('mytable', 7);
*
* // Create dataobject and pass it into generator
* $doMyTable = OA_Dal::factoryDO('mytable');
* $doMyTable->column1 = 'some value';
* $aMytableIds = DataGenerator::generate($doMyTable, 7);
*
* @see DB_DataObject::insert()
* @param mixed $do Either DataObject or table name (as string)
* @param int $numberOfCopies How many records should be generated
* @param bool $generateParents Should parent records be generated?
* @return array Array ids of created records
* @access public
* @static
*/
function generate($do, $numberOfCopies = 1, $generateParents = false)
{
// Cleanup ancestor ids
DataGenerator::getReferenceId();
if (is_string($do)) {
// Lazy DataObject initialization
$do = OA_Dal::factoryDO($do);
if (PEAR::isError($do)) {
return array();
}
}
if ($generateParents) {
if (!empty($this) && is_a($this, 'DataGenerator')) {
$this->generateParents($do);
} else {
DataGenerator::generateParents($do);
}
}
$doOriginal = clone $do;
if (isset($this) && is_a($this, 'DataGenerator')) {
$this->setDefaultValues($do);
} else {
DataGenerator::setDefaultValues($do);
}
DataGenerator::trackData($do->getTableWithoutPrefix());
$ids = array();
for ($i = 0; $i < $numberOfCopies; $i++) {
$id = $do->insert();
$do = clone $doOriginal;
if (!empty($this) && is_a($this, 'DataGenerator')) {
$this->setDefaultValues($do, $i + 1);
} else {
DataGenerator::setDefaultValues($do, $i + 1);
}
$ids[] = $id;
}
return $ids;
}