getRepository() public method

public getRepository ( $className )
Beispiel #1
0
 /**
  * Modify an individual ContentType's records.
  *
  * @param string $contentTypeName ContentType slug
  * @param array  $changeRequest   Change array in the format of:
  *                                [id => [action => [field => value]]]
  */
 public function action($contentTypeName, array $changeRequest)
 {
     foreach ($changeRequest as $recordId => $actionData) {
         if ($actionData === null) {
             continue;
         }
         $repo = $this->em->getRepository($contentTypeName);
         foreach ($actionData as $action => $fieldData) {
             if (!($entity = $repo->find($recordId))) {
                 continue;
             }
             $this->modifyContentTypeRecord($repo, $entity, $action, $fieldData);
         }
     }
 }
Beispiel #2
0
 public function testGetDefaultRepositoryFactory()
 {
     $app = $this->getApp();
     $em = $app['storage'];
     $repo = $em->getRepository('showcases');
     // The first check should work, this one should fail because the factory has not been set.
     $this->setExpectedException('RuntimeException');
     $em = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata']);
     $repo = $em->getRepository('showcases');
 }
Beispiel #3
0
 /**
  * Convert POST relationship values to an array of Entity objects keyed by
  * ContentType.
  *
  * @param array $contenttype
  *
  * @return array
  */
 private function getRelationsList(array $contenttype)
 {
     $list = [];
     if (!isset($contenttype['relations']) || !is_array($contenttype['relations'])) {
         return $list;
     }
     foreach ($contenttype['relations'] as $contentType => $relation) {
         $repo = $this->em->getRepository($contentType);
         $list[$contentType] = $repo->getSelectList($contentType, $relation['order']);
     }
     return $list;
 }
Beispiel #4
0
 /**
  * Convert POST relationship values to an array of Entity objects keyed by
  * ContentType.
  *
  * @param array $contentType
  *
  * @return array
  */
 private function getRelationsList(array $contentType)
 {
     $list = [];
     if (!isset($contentType['relations']) || !is_array($contentType['relations'])) {
         return $list;
     }
     foreach ($contentType['relations'] as $relationName => $relationValues) {
         $repo = $this->em->getRepository($relationName);
         $relationConfig = $this->config->get('contenttypes/' . $relationName, []);
         $list[$relationName] = $repo->getSelectList($relationConfig, $relationValues['order']);
     }
     return $list;
 }
Beispiel #5
0
 /**
  * Convert POST relationship values to an array of Entity objects keyed by
  * ContentType.
  *
  * @param ContentType $contentType
  *
  * @return array
  */
 private function getRelationsList(ContentType $contentType)
 {
     $list = [];
     if (!isset($contentType['relations']) || !is_array($contentType['relations'])) {
         return $list;
     }
     foreach ($contentType['relations'] as $relationName => $relationValues) {
         /** @var Repository\ContentRepository $repo */
         $repo = $this->em->getRepository($relationName);
         $relationConfig = $this->config->get('contenttypes/' . $relationName, []);
         $neededFields = $this->neededFields($relationValues, $relationConfig);
         $order = isset($relationValues['order']) ? $relationValues['order'] : null;
         $list[$relationName] = $repo->getSelectList($relationConfig, $order, $neededFields);
     }
     return $list;
 }
Beispiel #6
0
 /**
  * Commit the record to the database.
  *
  * @param Entity\Content      $content
  * @param Entity\Content|null $oldContent
  * @param array               $contentType
  * @param boolean             $new
  * @param string              $comment
  * @param string              $returnTo
  * @param string              $editReferrer
  *
  * @return Response
  */
 private function saveContentRecord(Entity\Content $content, $oldContent, array $contentType, $new, $comment, $returnTo, $editReferrer)
 {
     // Save the record
     $repo = $this->em->getRepository($contentType['slug']);
     // Update the date modified timestamp
     $content->setDatechanged('now');
     $repo->save($content);
     $id = $content->getId();
     // Create the change log entry if configured
     $this->logChange($contentType, $content->getId(), $content, $oldContent, $comment);
     // Log the change
     if ($new) {
         $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-new', ['%contenttype%' => $contentType['slug']]));
         $this->loggerSystem->info('Created: ' . $content->getTitle(), ['event' => 'content']);
     } else {
         $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-changes', ['%contenttype%' => $contentType['slug']]));
         $this->loggerSystem->info('Saved: ' . $content->getTitle(), ['event' => 'content']);
     }
     /*
      * We now only get a returnto parameter if we are saving a new
      * record and staying on the same page, i.e. "Save {contenttype}"
      */
     if ($returnTo) {
         if ($returnTo === 'new') {
             return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], 'id' => $id, '#' => $returnTo]));
         } elseif ($returnTo === 'saveandnew') {
             return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], '#' => $returnTo]));
         } elseif ($returnTo === 'ajax') {
             return $this->createJsonUpdate($content, true);
         } elseif ($returnTo === 'test') {
             return $this->createJsonUpdate($content, false);
         }
     }
     // No returnto, so we go back to the 'overview' for this contenttype.
     // check if a pager was set in the referrer - if yes go back there
     if ($editReferrer) {
         return new RedirectResponse($editReferrer);
     } else {
         return new RedirectResponse($this->generateUrl('overview', ['contenttypeslug' => $contentType['slug']]));
     }
 }
 /**
  * Delete any save authtokens for a user.
  *
  * @param Entity\Users $user
  */
 private function deleteAuthtokens(Entity\Users $user)
 {
     /** @var \Bolt\Storage\Repository\AuthtokenRepository $repo */
     $repo = $this->em->getRepository('Bolt\\Storage\\Entity\\Authtoken');
     $repo->deleteTokens($user->getUsername());
 }
Beispiel #8
0
 /**
  * @depends testInsert
  */
 public function testDelete()
 {
     $app = $this->getApp();
     $entityName = 'Bolt\\Storage\\Entity\\Users';
     $this->runListenCount($app, 'preDelete');
     $this->runListenCount($app, 'postDelete');
     $em = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata']);
     $repo = $em->getRepository($entityName);
     $existing = $repo->findOneBy(['displayname' => 'Test User']);
     $result = $repo->delete($existing);
     $confirm = $repo->findOneBy(['displayname' => 'Test User']);
     $this->assertFalse($confirm);
     $this->assertEquals(1, $this->eventCount['preDelete']);
     $this->assertEquals(1, $this->eventCount['postDelete']);
 }