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


PHP DataGenerator::getAccountsData方法代码示例

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


在下文中一共展示了DataGenerator::getAccountsData方法的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;
 }
开发者ID:JodiWarren,项目名称:hms,代码行数:73,代码来源:Setup.php


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