Example #1
0
 /**
  * Replace various variables in the code template with data
  * relevant to the assigned article.
  * @param PublishedArticle $publishedArticle
  */
 function replaceCodeVars($publishedArticle = null)
 {
     $application = Application::getApplication();
     $request = $application->getRequest();
     $router = $request->getRouter();
     $context = $request->getContext();
     $code = $this->getCode();
     $codeVariables = array('journalUrl' => $router->url($request, null, 'index'), 'journalName' => $context->getLocalizedName());
     if (isset($publishedArticle)) {
         $codeVariables = array_merge($codeVariables, array('articleUrl' => $router->url($request, null, 'article', 'view', $publishedArticle->getId()), 'articleTitle' => $publishedArticle->getLocalizedTitle()));
     }
     // Replace variables in message with values
     foreach ($codeVariables as $key => $value) {
         if (!is_object($value)) {
             $code = str_replace('{$' . $key . '}', $value, $code);
         }
     }
     $this->setCode($code);
 }