protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); $password = $input->getArgument('password'); $em = $this->getContainer()->get('doctrine')->getEntityManager(); $user = new User(); $user->setUsername($username); $user->setFirstName('Test'); $user->setLastName('Test'); //$user->setIsApproved(1); //$user->setIsActive(1); //$user->setPasswordQuestion(''); //$user->setPasswordAnswer(''); //$user->setComment(''); // encode the password $factory = $this->getContainer()->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $encodedPassword = $encoder->encodePassword($password, $user->getSalt()); $user->setPassword($encodedPassword); $em->persist($user); $em->flush(); $output->writeln(sprintf('Added %s user with password %s', $username, $password)); }
/** * Returns array [ * [ * 'product' => Product, * 'before' => ProductStatus, * 'after' => ProductStatus, * 'user' => User, * 'customer' => Customer, * ], * ... * ] * @param \DateTime $date * @param Customer $customer * @param User $user * @param ProductsSet $productSet * @return type */ public function getForProductsByDate(\DateTime $date, Customer $customer = null, User $user = null, ProductsSet $productSet = null, ProductStatus $statusAfter = null) { $em = $this->_em; $connection = $em->getConnection(); $conditions = []; $conditionValues = []; $conditions[] = 'date = :date'; $conditionValues[':date'] = $date->format('Y-m-d'); if (!empty($user)) { $conditions[] = 'user_id = :user_id'; $conditionValues[':user_id'] = $user->getId(); } if (!empty($customer)) { $conditions[] = 'customer_id = :customer_id'; $conditionValues[':customer_id'] = $customer->getId(); } if (!empty($productSet)) { $conditions[] = 'product_set_id = :product_set_id'; $conditionValues[':product_set_id'] = $productSet->getId(); } if (!empty($statusAfter)) { $conditions[] = 'status_after_change_id = :status_after_change_id'; $conditionValues[':status_after_change_id'] = $statusAfter->getId(); } $sql = ' SELECT DISTINCT customer_id, product_id, status_before_change_id, status_after_change_id, user_id FROM statistics_product_status_changes WHERE ' . implode(' AND ', $conditions) . ' '; $stmt = $connection->prepare($sql); foreach ($conditionValues as $key => $value) { $stmt->bindValue($key, $value); } $stmt->execute(); $rows = $stmt->fetchAll(); $result = []; foreach ($rows as $row) { $result[] = ['product' => empty($row['product_id']) ? null : $em->getRepository('CoreBundle:Product')->find($row['product_id']), 'before' => empty($row['status_before_change_id']) ? null : $em->getRepository('CoreBundle:ProductStatus')->find($row['status_before_change_id']), 'after' => empty($row['status_after_change_id']) ? null : $em->getRepository('CoreBundle:ProductStatus')->find($row['status_after_change_id']), 'user' => empty($row['user_id']) ? null : $em->getRepository('UsersBundle:User')->find($row['user_id']), 'customer' => empty($row['customer_id']) ? null : $em->getRepository('CoreBundle:Customer')->find($row['customer_id'])]; } return $result; }