PartKeepr\CoreBundle\Services\SystemNoticeService::createUniqueSystemNotice PHP Method

createUniqueSystemNotice() public method

public createUniqueSystemNotice ( $type, $title, $description )
    public function createUniqueSystemNotice($type, $title, $description)
    {
        $dql = "SELECT sn FROM PartKeepr\\CoreBundle\\Entity\\SystemNotice sn WHERE sn.type = :type";
        $query = $this->entityManager->createQuery($dql);
        $query->setParameter('type', $type);
        try {
            $notice = $query->getSingleResult();
        } catch (\Exception $e) {
            $notice = new SystemNotice();
            $this->entityManager->persist($notice);
        }
        $notice->setDate(new \DateTime());
        $notice->setTitle($title);
        $notice->setDescription($description);
        $notice->setType($type);
        $this->entityManager->flush();
        return $notice;
    }

Usage Example

Example #1
0
 /**
  * Checks against the versions at partkeepr.org.
  *
  * If a newer version was found, create a system notice entry.
  */
 public function doVersionCheck()
 {
     if ($this->getVersion() === "{V_GIT}") {
         return;
     }
     if (substr($this->getVersion(), 0, 17) === "partkeepr-nightly") {
         return;
     }
     $latestVersion = $this->getLatestVersion();
     if ($latestVersion === false) {
         return;
     }
     if (version_compare($this->getVersion(), $latestVersion["version"], '<')) {
         $this->systemNoticeService->createUniqueSystemNotice("PARTKEEPR_VERSION_" . $latestVersion["version"], $this->translator->trans("New PartKeepr Version %version% available", array("%version%" => $latestVersion["version"])), $this->translator->trans("PartKeepr Version %version% changelog:", array("%version%" => $latestVersion["version"] . "\n\n" . $latestVersion["changelog"])));
     }
 }
All Usage Examples Of PartKeepr\CoreBundle\Services\SystemNoticeService::createUniqueSystemNotice