本文整理汇总了PHP中DataGenerator::getMembersData方法的典型用法代码示例。如果您正苦于以下问题:PHP DataGenerator::getMembersData方法的具体用法?PHP DataGenerator::getMembersData怎么用?PHP DataGenerator::getMembersData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataGenerator
的用法示例。
在下文中一共展示了DataGenerator::getMembersData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __generateData
/**
* Generate the data that will populate the database.
*
* @return bool True if data was generated and written correctly, false otherwise.
*/
private function __generateData()
{
$this->__logMessage('Generating test data');
$this->__pushLogIndent();
$totalMembersToGenerate = 200;
$membersRemaining = $totalMembersToGenerate;
$genDetails = array();
// Half the members should be current members
$genDetails[Status::CURRENT_MEMBER] = $this->__distribureMembers($membersRemaining, 2);
// 1/3rd of the remaining members should be ex members
$genDetails[Status::EX_MEMBER] = $this->__distribureMembers($membersRemaining, 3);
// Distribute the rest of the members evenly over the other statuses
$toAssign = (int) floor($membersRemaining / 4);
$genDetails[Status::PROSPECTIVE_MEMBER] = $toAssign;
$genDetails[Status::PRE_MEMBER_1] = $toAssign;
$genDetails[Status::PRE_MEMBER_2] = $toAssign;
$genDetails[Status::PRE_MEMBER_3] = $toAssign;
$membersRemaining -= $toAssign * 4;
// Any left? Make them current members
$genDetails[Status::CURRENT_MEMBER] += $membersRemaining;
$this->__logMessage("Generating data for {$totalMembersToGenerate} members.");
// Generate!
$dataGenerator = new DataGenerator();
foreach ($genDetails as $status => $num) {
for ($i = 0; $i < $num; $i++) {
$dataGenerator->generateMember($status);
}
}
// Finally generate the dev user
$details = array('firstname' => $this->__firstname, 'surname' => $this->__surname, 'email' => $this->__email, 'username' => $this->__username, 'groups' => array(Group::CURRENT_MEMBERS, Group::FULL_ACCESS, Group::MEMBERSHIP_ADMIN));
$dataGenerator->generateMember(Status::CURRENT_MEMBER, $details);
// Generate some subscriptions
$memberData = $dataGenerator->getMembersData();
$memberEmails = array_map(function ($data) {
return $data['email'];
}, $memberData);
$emailGenerator = new emailGenerator();
$randomEmails = array();
for ($i = 0; $i < 50; $i++) {
array_push($randomEmails, $emailGenerator->generate());
}
$allEmails = array_merge($memberEmails, $randomEmails);
$mailingListDataGenerator = new MailingListDataGenerator();
foreach ($mailingListDataGenerator->getMailingListsData() as $list) {
$numToAdd = rand(10, 30);
for ($i = 0; $i < $numToAdd; $i++) {
$timestamp = rand(strtotime('last year'), time());
$email = $allEmails[array_rand($allEmails)];
$mailingListDataGenerator->subscribeEmailToList($email, $list['id'], $timestamp);
}
}
$this->__logMessage('Writing SQL files');
$sqlData = array(array('filepath' => '../Sql/members_data.sql', 'tableName' => 'members', 'data' => $memberData), array('filepath' => '../Sql/member_group_data.sql', 'tableName' => 'member_group', 'data' => $dataGenerator->getMembersGroupData()), array('filepath' => '../Sql/account_data.sql', 'tableName' => 'account', 'data' => $dataGenerator->getAccountsData()), array('filepath' => '../Sql/pins_data.sql', 'tableName' => 'pins', 'data' => $dataGenerator->getPinsData()), array('filepath' => '../Sql/rfid_tags_data.sql', 'tableName' => 'rfid_tags', 'data' => $dataGenerator->getRfidTagsData()), array('filepath' => '../Sql/status_updates_data.sql', 'tableName' => 'status_updates', 'data' => $dataGenerator->getStatusUpdatesData()), array('filepath' => '../Sql/mailinglists_data.development.sql', 'tableName' => 'mailinglists', 'data' => $mailingListDataGenerator->getMailingListsData()), array('filepath' => '../Sql/mailinglist_subscriptions_data.development.sql', 'tableName' => 'mailinglist_subscriptions', 'data' => $mailingListDataGenerator->getMailingListSubscriptionsData()), array('filepath' => '../Sql/hms_emails_data.development.sql', 'tableName' => 'hms_emails', 'data' => $dataGenerator->getEmailRecordData()));
$sqlWriter = new sqlWriter();
foreach ($sqlData as $dataEntry) {
$sqlString = $sqlWriter->writeInsert($dataEntry['tableName'], $dataEntry['data']);
$path = $dataEntry['filepath'];
if ($this->__writeToFile($path, $sqlString)) {
$this->__logMessage("Wrote {$path}");
} else {
$this->__logMessage("Failed to write {$path}");
$this->__popLogIndent();
return false;
}
}
$this->__popLogIndent();
return true;
}