public function viewPagesAction(Request $request, Application $app) { $db = new DbRepository($app['dbh']); $content = $db->getAllPagesContent(); $args_array = array('user' => $app['session']->get('user'), 'content' => $content); $templateName = '_viewPages'; return $app['twig']->render($templateName . '.html.twig', $args_array); }
public function processDeleteContentAction(Request $request, Application $app, $contentId) { $db = new DbRepository($app['dbh']); $result = $db->deleteContent($contentId); $content = $db->getAllPagesContent(); $args_array = array('user' => $app['session']->get('user'), 'content' => $content, 'result' => $result); $templateName = '_content'; return $app['twig']->render($templateName . '.html.twig', $args_array); }
/** * display one articles. * * renders a template with one articles. * * @param Request * @param Application * * @return an article template. */ public function oneArticleAction(Request $request, Application $app, $pageRoute, $contentId) { $db = new DbRepository($app['dbh']); $result = $db->showOne($contentId); $allContent = $db->getAllPagesContent(); $args_array = array('allContent' => $allContent, 'contentId' => $result->getContentId(), 'pageName' => $result->getPageName(), 'title' => $result->getContentitemtitle(), 'article' => $result->getContentitem(), 'image' => $result->getImagePath(), 'created' => $result->getCreated()); $templateName = 'onearticle'; return $app['twig']->render($templateName . '.html.twig', $args_array); }
public function userAction(Request $request, Application $app, $contentId) { $db = new DbRepository($app['dbh']); $content = $db->showOne($contentId); $user = $app['session']->get('user'); if ($user == false) { $allContent = $db->getAllPagesContent(); $args_array = array('allContent' => $allContent, 'contentId' => $content->getContentId(), 'pageName' => $content->getPageName(), 'title' => $content->getContentitemtitle(), 'article' => $content->getContentitem(), 'image' => $content->getImagePath(), 'created' => $content->getCreated()); $templateName = 'onearticle'; return $app['twig']->render($templateName . '.html.twig', $args_array); } else { $args_array = array('user' => $app['session']->get('user'), 'pagename' => $content->getPageName(), 'contentitemtitle' => $content->getContentItemTitle(), 'contentitem' => $content->getContentItem(), 'created' => $content->getCreated(), 'contentid' => $content->getContentId()); $templateName = '_singleContent'; return $app['twig']->render($templateName . '.html.twig', $args_array); } }
/** * A controller for processing the upload images form. * Validations: a jpg or png, under 1M and file must not already exist. * The image path will be stored in the db. * * @param request object * @param app object * * @return twig template */ public function processImageUploadAction(Request $request, Application $app) { $file = $request->files->get('image'); $pic = $file->getClientOriginalName(); $constraint = new Assert\Image(array('mimeTypes' => array('image/jpeg', 'image/png'), 'maxSize' => '2M')); $validfile = true; $message = ''; $errors = $app['validator']->validate($file, $constraint); if (count($errors) > 0) { foreach ($errors as $error) { $message = $error->getPropertyPath() . ' ' . $error->getMessage() . "\n"; } $validfile = false; } if (file_exists($request->getBasePath() . 'images/' . $file->getClientOriginalName())) { $message = 'Sorry, file already exists'; $validfile = false; } # if the validation variable is false, re-render the upload form with an error message if ($validfile == false) { $args_array = array('user' => $app['session']->get('user'), 'result' => $message); $templateName = '_uploadImageForm'; return $app['twig']->render($templateName . '.html.twig', $args_array); } elseif ($validfile == true) { $file->move($request->getBasePath() . 'images/', $file->getClientOriginalName()); $path = $file->getClientOriginalName(); $newImage = new Image(); $newImage->setImagePath($path); $image = $newImage->getImagePath(); $db = new DbRepository($app['dbh']); $result = $db->uploadImage($image); $images = $db->viewImages(); $content = $db->getAllPagesContent(); $args_array = array('user' => $app['session']->get('user'), 'result' => $result, 'images' => $images, 'content' => $content); $templateName = '_viewImages'; return $app['twig']->render($templateName . '.html.twig', $args_array); } }