protected function execute(InputInterface $input, OutputInterface $output) { $faker = \Faker\Factory::create(); $unit = intval($input->getArgument("amount")); $app = $this->getSilexApplication(); $progress = new ProgressBar($output, $unit); $progress->start(); $i = 0; while ($i < $unit) { $sex = $faker->randomElement(['f', 'm']); $gender = $sex === 'f' ? 'female' : 'male'; $human = new Human(); $human->setName($faker->firstName($gender))->setMiddleName($faker->lastName)->setSurName($faker->lastName)->setSex($sex); $app['livetext.family.repository']->insert($human); $progress->advance(); $i++; } $progress->finish(); }
/** * Loads the values corresponding to the given choices. * * The values are returned with the same keys and in the same order as the * corresponding choices in the given array. * * Optionally, a callable can be passed for generating the choice values. * The callable receives the choice as first and the array key as the second * argument. * * @param array $choices An array of choices. Non-existing choices in * this array are ignored * @param null|callable $value The callable generating the choice values * * @return string[] An array of choice values */ public function loadValuesForChoices(array $choices, $value = null) { $results = []; $this->loadedChoices = []; foreach ($choices as $choice) { if ($choice instanceof Human) { $results[] = $choice->getId(); $this->loadedChoices[Human::getFullName($choice)] = $choice->getId(); } else { $results[] = $choice; $this->loadedChoices[$choice] = $choice; } } return $results; }
public function autocompleteAction(Request $request, Application $app) { $q = $request->get('q', null); if (Text::checkMin($q, 1)) { return $app->json([]); } $sex = $request->get('sex', null); if (!in_array($sex, ['f', 'm'])) { $sex = 'm'; } $data = $this->familyRepository->autocomplete($q, $sex, 10); $formatData = array_map(function ($row) { return ['id' => $row['id'], 'text' => Human::getFullName($row)]; }, $data); return $app->json(['items' => $formatData]); }
/** * Получить полное семейное древо * @param Human $human * @return array */ public function getFamilyTree(Human $human) { $notFound = [$human->getId()]; $results = []; while (!empty($notFound)) { $rootParents = $this->getRootParents($notFound); $results = ArrayUtil::arrayMerge($results, $this->getChildrenFullData($rootParents)); $notFound = $this->checkAllFound($results); } $result = array_map(function ($row) { return array_merge($row, ['label' => Human::getFullName($row)]); }, $results); return $result; }