setDate() 공개 메소드

Set date
public setDate ( DateTime $date )
$date DateTime
 public function setUp()
 {
     $kernel = static::createKernel();
     $kernel->boot();
     if ($kernel->getContainer()->getParameter('database_driver') == 'pdo_sqlite') {
         $this->markTestSkipped("The SQLite does not support joins.");
     }
     $this->em = $kernel->getContainer()->get('knp_bundles.entity_manager');
     $fileLocator = new FileLocator(__DIR__ . '/fixtures/');
     $path = $fileLocator->locate('trending-bundles.yml');
     $data = Yaml::parse($path);
     $developer = new Developer();
     $developer->setName('someName');
     $developer->setScore(0);
     $this->em->persist($developer);
     foreach ($data['bundles'] as $bundleName => $bundleData) {
         $bundle = new Bundle('vendor/' . $bundleName);
         $bundle->setDescription('some description');
         $bundle->setScore(100);
         $bundle->setOwner($developer);
         foreach ($bundleData['scores'] as $scoreData) {
             $bundle->setDescription(md5(time() . serialize($scoreData)));
             $score = new Score();
             $score->setDate(new \DateTime($scoreData['date']));
             $score->setBundle($bundle);
             $score->setValue($scoreData['value']);
             $this->em->persist($score);
         }
         $this->em->persist($bundle);
     }
     $this->em->flush();
 }
예제 #2
0
 /**
  * Set the score value for a given date and bundle.
  * If the entry does not yet exist in DB, create a new object
  * (you're responsible for persisting it)
  *
  * @param DateTime $date
  * @param Bundle $bundle
  * @param int Value of the score
  * @return Score
  */
 public function setScore(\DateTime $date, Bundle $bundle, $value)
 {
     $score = $this->findOneByDateAndBundle($date, $bundle);
     if (!$score) {
         $score = new Score();
         $score->setBundle($bundle);
         $score->setDate($date);
     }
     $score->setValue($value);
     return $score;
 }
예제 #3
0
파일: data.php 프로젝트: ruian/KnpBundles
 public function load($manager)
 {
     $users = array();
     $trilean = array(true, false, null);
     $i = 0;
     foreach ($this->names as $name => $fullName) {
         $i++;
         $user = new Entity\User();
         $user->fromArray(array('name' => $name, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'fullName' => $fullName, 'company' => $i % 2 ? 'Company ' . $i : null, 'location' => $i % 2 ? 'Location ' . $i : null, 'blog' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0));
         $manager->persist($user);
         $users[] = $user;
     }
     foreach ($users as $i => $user) {
         $contributors = array();
         $contributors[] = isset($users[$i + 1]) ? $users[$i + 1] : $users[0];
         $contributors[] = isset($users[$i - 1]) ? $users[$i - 1] : $users[count($users) - 1];
         $contributor = array_pop($contributors);
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => ucfirst($user->getName()) . 'FooBundle', 'username' => $user->getName(), 'user' => $user, 'description' => 'Description of my bundle', 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_repeat("README of the bundle number " . $i . "\n", 20), 'tags' => $i % 2 ? array('1.0', '1.1') : array(), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'lastCommitAt' => new \DateTime('-' . $i * 4 . ' day'), 'lastCommits' => array(array('author' => array('name' => $contributor->getFullName(), 'login' => $contributor->getName(), 'email' => $contributor->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-09:00', 'authored_date' => '2010-05-16T09:58:32-09:00', 'message' => 'Fix something on this ' . 'Bundle'), array('author' => array('name' => $user->getFullName(), 'login' => $user->getName(), 'email' => $user->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-07:00', 'authored_date' => '2010-05-16T09:58:32-07:00', 'message' => 'Commit something on this bundle')), 'isFork' => false, 'contributors' => array($contributor)));
         $manager->persist($bundle);
         // Add some scores for bundles
         $today = new \DateTime();
         // We add a various number of scores for a given bundle
         $daysBefore = crc32($bundle->getName() . '-days') % 50;
         $maxScore = crc32($bundle->getName()) % 50;
         $previousScore = $maxScore;
         while ($daysBefore-- > 0) {
             $date = clone $today;
             $date->sub(new \DateInterval('P' . $daysBefore . 'D'));
             $score = new Entity\Score();
             $score->setBundle($bundle);
             $score->setValue($previousScore + $daysBefore);
             $score->setDate($date);
             $manager->persist($score);
             $previousScore = $score->getValue();
         }
     }
     $manager->flush();
 }
예제 #4
0
파일: Data.php 프로젝트: KnpLabs/KnpBundles
 public function load(ObjectManager $manager)
 {
     $developers = array();
     $organizations = array();
     $i = 0;
     foreach ($this->orgNames as $name => $fullName) {
         $i++;
         $organization = new Entity\Organization();
         $organization->fromArray(array('name' => $name, 'fullName' => $fullName, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'location' => $i % 2 ? 'Location ' . $i : null, 'url' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0, 'createdAt' => new \DateTime(sprintf('%d days ago', rand(1, 50)))));
         $manager->persist($organization);
         $organizations[] = $organization;
     }
     $i = 0;
     foreach ($this->devNames as $name => $fullName) {
         $i++;
         $developer = new Entity\Developer();
         $developer->fromArray(array('name' => $name, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'fullName' => $fullName, 'githubId' => $name, 'company' => $i % 2 ? 'Company ' . $i : null, 'location' => $i % 2 ? 'Location ' . $i : null, 'url' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0, 'createdAt' => new \DateTime(sprintf('%d days ago', rand(1, 50)))));
         if (isset($organizations[$i + 1])) {
             $developer->addOrganization($organizations[$i + 1]);
         }
         $manager->persist($developer);
         $developers[] = $developer;
     }
     foreach ($developers as $i => $developer) {
         $contributors = array();
         $contributors[] = isset($developers[$i + 1]) ? $developers[$i + 1] : $developers[0];
         $contributors[] = isset($developers[$i - 1]) ? $developers[$i - 1] : $developers[count($developers) - 1];
         /* @var $contributor Entity\Developer */
         $contributor = array_pop($contributors);
         $bundle = $this->makeBundle($manager, $developer, $i, $contributor);
         if ($i % 5 == 0) {
             $bundle->setLastTweetedAt(new \DateTime());
         } else {
             $bundle->setVersionsHistory(array('symfony' => array('dev-master' => '2.1.*', '1.2.0' => '2.0.*', '1.1.0' => '2.*'), 'dependencies' => array('dev-master' => array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => array('twig/twig' => '*', 'doctrine/doctrine-bundle' => '*', 'swiftmailer/swiftmailer' => '*', 'willdurand/propel-typehintable-behavior' => 'dev-master', 'symfony/validator' => '2.1.*', 'symfony/yaml' => '2.1.*'), 'suggest' => array('doctrine/couchdb-odm-bundle' => '*', 'doctrine/doctrine-bundle' => '*', 'doctrine/mongodb-odm-bundle' => '*')), '1.2.x-dev' => array('name' => 'friendsofsymfony/user-bundle', 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => '', 'suggest' => ''))));
         }
         $bundle->setScore(mt_rand(10, 666));
         $bundle->addRecommender(isset($developers[$i + 2]) ? $developers[$i + 2] : ($developers[0] != $developer ? $developers[0] : $developers[1]));
         if (isset($this->keywords[$i])) {
             $keyword = new Entity\Keyword();
             $keyword->setValue($this->keywords[$i]);
             $bundle->addKeyword($keyword);
             $manager->persist($keyword);
         }
         if (isset($this->keywords[$i + 1])) {
             $keyword = new Entity\Keyword();
             $keyword->setValue($this->keywords[$i + 1]);
             $bundle->addKeyword($keyword);
             $manager->persist($keyword);
         }
         $manager->persist($bundle);
         // Add some scores for bundles
         $today = new \DateTime();
         // We add a various number of scores for a given bundle
         $daysBefore = crc32($bundle->getName() . '-days') % 50;
         $maxScore = crc32($bundle->getName()) % 50;
         $previousScore = $maxScore;
         while ($daysBefore-- > 0) {
             $date = clone $today;
             $date->sub(new \DateInterval('P' . $daysBefore . 'D'));
             $score = new Entity\Score();
             $score->setBundle($bundle);
             $score->setValue($previousScore + $daysBefore);
             $score->setDate($date);
             $manager->persist($score);
             $previousScore = $score->getValue();
         }
     }
     foreach ($organizations as $organization) {
         for ($i = 1; $i < rand(2, 7); $i++) {
             $manager->persist($this->makeBundle($manager, $organization, $i));
         }
     }
     $manager->flush();
 }