/** * Serialize an entity and return its ID. * * @param EntityInterface $entity * * @return string */ public function serializeEntityId(EntityInterface $entity) { /** @var EntityAccessor $entityAccessor */ $entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor']; $serializer = new IdSerializer(); $serializer->setDataProviderName($entity->entityTableName()); $serializer->setId($entityAccessor->getPrimaryKey($entity)); return $serializer->getSerialized(); }
/** * @param mixed|EntityInterface $entity * @param mixed $id * @param mixed $_ */ public function setPrimaryKey($entity, $id) { $class = new \ReflectionClass($entity); if ($class->isSubclassOf('Contao\\Doctrine\\ORM\\EntityInterface')) { $keyNames = $entity->entityPrimaryKeyNames(); } else { $keyNames = array('id'); } $keyCount = count($keyNames); // clear primary key if ($id === null) { $keyValues = array_fill(0, $keyCount, null); } else { $keyValues = (array) $id; } if ($keyCount != count($keyValues)) { throw new \RuntimeException(sprintf('The entity %s has %d primary key values [%s]', get_class($entity), $keyCount, implode(', ', $keyNames))); } $keys = array_combine($keyNames, $keyValues); $this->setRawProperties($entity, $keys); return $this; }
/** * @param EntityInterface $recipient * * @return string * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function addAddedByToLabel(EntityInterface $recipient) { global $TL_LANG; $label = ' <span style="color:#b3b3b3; padding-left:.5em;">('; $label .= sprintf($TL_LANG['orm_avisota_recipient']['added_at'], $recipient->getCreatedAt()->format(\Config::get('datimFormat'))); if ($recipient->getAddedById() > 0) { $database = \Database::getInstance(); $user = $database->prepare("SELECT * FROM tl_user WHERE id=?")->execute($recipient->getAddedById()); if ($user->next()) { $format = $TL_LANG['orm_avisota_recipient']['added_by']; $parameters = array($user->name, $user->username, 'contao/main.php?' . http_build_query(array('do' => 'user', 'act' => 'edit', 'id' => $user->id, 'rt' => defined('REQUEST_TOKEN') ? REQUEST_TOKEN : null, 'ref' => defined('TL_REFERER_ID') ? TL_REFERER_ID : null))); } else { $format = $TL_LANG['orm_avisota_recipient']['added_by_unlinked']; $parameters = array($recipient->getAddedByName(), $recipient->getAddedByUsername()); } $label .= vsprintf($format, $parameters); } $label .= ')</span>'; return $label; }
/** * Return layout used information by message. * * @param EntityInterface $entity The Entity. * * @param EnvironmentInterface $environment The Environment. * * @return string */ protected function getLayoutUsedInformation(EntityInterface $entity, EnvironmentInterface $environment) { $dataProvider = $environment->getDataProvider(); $entityManager = $dataProvider->getEntityManager(); $repository = $entityManager->getRepository('Avisota\\Contao:Message'); $messageResult = $repository->findBy(array('layout' => $entity->getId()), array('subject' => 'ASC')); if (count($messageResult) < 1) { return ''; } $information = ''; foreach ($messageResult as $message) { $information .= "\\n"; $information .= $message->getCategory()->getTitle(); $information .= ' => '; $information .= $message->getSubject(); } return $information; }