Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Midhun Devasia committed Nov 18, 2016
0 parents commit 9f696c7
Show file tree
Hide file tree
Showing 265 changed files with 25,447 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace Tutorboy\Blogmaster\Controller;

/*
* This file is part of the Blogmaster project.
* Copyright (C) 2016 Midhun Devasia <[email protected]>
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 3
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* Blogmaster - A blog system for TYPO3!
*/

use \TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Abstract action controller
*
* @package Blogmaster
* @subpackage Blog
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org
* @author Midhun Devasia <[email protected]>
*/
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
* Return the persistance manager object instance
* @return \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
*/
protected function getPersistenceManager() {
return $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
}

/**
* Convert flex form to array
* @param string $flexForm Flex Configuration string
* @return array Flex value array
*/
public function convertFlexFormToArray($flexForm) {
$flexformService = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Service\FlexFormService');
$flexFormData = $flexformService->convertFlexFormContentToArray($flexForm);
return $flexFormData;
}

/**
* Database connection
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
public static function getDatabaseConnection() {
return $GLOBALS['TYPO3_DB'];
}
}
27 changes: 27 additions & 0 deletions Classes/Controller/BlogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Tutorboy\Blogmaster\Controller;

/*
* This file is part of the Blogmaster project.
* Copyright (C) 2016 Midhun Devasia <[email protected]>
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 3
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* Blogmaster - A blog system for TYPO3!
*/

/**
* Blog controller
*
* @package Blogmaster
* @subpackage Blog
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org
* @author Midhun Devasia <[email protected]>
*/
class BlogController extends AbstractController {
}
47 changes: 47 additions & 0 deletions Classes/Controller/BlogFrontendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace Tutorboy\Blogmaster\Controller;

/*
* This file is part of the Blogmaster project.
* Copyright (C) 2016 Midhun Devasia <[email protected]>
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 3
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* Blogmaster - A blog system for TYPO3!
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Blog frontend controller
*
* @package Blogmaster
* @subpackage Blog
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org
* @author Midhun Devasia <[email protected]>
*/
class BlogFrontendController extends AbstractController {

/**
* Render all view for the frontend plugin
* @return void
*/
public function renderAction() {
$settingsService = GeneralUtility::makeInstance(\Tutorboy\Blogmaster\Service\SettingsService::class);
$settingsService->setSettings($this->settings);

$data['contentObject'] = $this->configurationManager->getContentObject()->data;
$data['pi_flexform'] = $this->convertFlexFormToArray($this->configurationManager->getContentObject()->data['pi_flexform']);
$data['request'] = $this->request->getArguments();

$contentRenderer = GeneralUtility::makeInstance(\Tutorboy\Blogmaster\Frontend\ContentRenderer::class);
$contentRenderer->controllerContext = $this->controllerContext;
$content = $contentRenderer->render($data);
$this->view->assign('content', $content);
}
}
164 changes: 164 additions & 0 deletions Classes/Controller/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
namespace Tutorboy\Blogmaster\Controller;

/*
* This file is part of the Blogmaster project.
* Copyright (C) 2016 Midhun Devasia <[email protected]>
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 3
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* Blogmaster - A blog system for TYPO3!
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;

/**
* Category controller
*
* @package Blogmaster
* @subpackage Blog
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org
* @author Midhun Devasia <[email protected]>
*/
class CategoryController extends AbstractController {

/**
* CategoryRepository object
* @var \Tutorboy\Blogmaster\Domain\Repository\CategoryRepository
*/
protected $categoryRepository;

/**
* Inject repository
* @param \Tutorboy\Blogmaster\Domain\Repository\CategoryRepository $categoryRepository Category Repository
* @return void
*/
public function injectCategoryRepository(\Tutorboy\Blogmaster\Domain\Repository\CategoryRepository $categoryRepository) {
$this->categoryRepository = $categoryRepository;
}

/**
* List all categories
* @return void
*/
public function listAction() {
if ($this->request->hasArgument('bulk-action')) {
$action = $this->request->getArgument('bulk-action');
if ($this->request->hasArgument('items')) {
$items = $this->request->getArgument('items');
switch ($action) {
// Delete all selected categories.
case 'delete':
if (is_array($items) && count($items)) {
foreach ($items as $catId) {
if (($object = $this->categoryRepository->findOneByUid($catId)) instanceof \Tutorboy\Blogmaster\Domain\Model\Category) {
$this->categoryRepository->remove($object);
}
}
}
$this->getPersistenceManager()->persistAll();
$this->addFlashMessage('Category has been moved to trash', 'Done!', FlashMessage::WARNING);
break;
default:
}
}
}

// Search filter
if ($this->request->hasArgument('search')) {
$search = $this->request->getArgument('search');
$cats = $this->categoryRepository->search($search);
$this->view->assign('search', $search);
} else {
// Get all categories
$cats = $this->categoryRepository->findAllByBlog(0);
}

$this->view->assign('cats', $cats);
}

/**
* New category form
* @param \Tutorboy\Blogmaster\Domain\Model\Category|null $category Category
* @return void
* @dontvalidate $category
*/
public function newAction(\Tutorboy\Blogmaster\Domain\Model\Category $category = NULL) {
// Edit view
if ($this->request->hasArgument('id')) {
$id = $this->request->getArgument('id');
$category = $this->categoryRepository->findOneByUid($id);
$this->view->assign('categoryObject', $category);
} else {
$this->view->assign('categoryObject', $category);
}

$cats = $this->categoryRepository->findAllByBlog(0);
$catList[0] = 'None';
foreach ($cats as $cat) {
$catList[$cat->getUid()] = $cat->getTitle();
}
$this->view->assign('catList', $catList);
}

/**
* Create new category
* @param \Tutorboy\Blogmaster\Domain\Model\Category $category Category object
* @return void
*/
public function createAction(\Tutorboy\Blogmaster\Domain\Model\Category $category) {
$this->categoryRepository->add($category);
$this->getPersistenceManager()->persistAll();
if ($category->getUid()) {
$this->addFlashMessage('New category has been created', 'Done!', FlashMessage::OK);
} else {
$this->addFlashMessage('Category could not be saved.', 'Error!', FlashMessage::ERROR);
}
$this->redirect('new', NULL, NULL, ['id' => $category->getUid()]);
}

/**
* Delete category
* @return void
* @todo More ID validation codes
*/
public function deleteAction() {
$id = $this->request->getArgument('delete');
$this->categoryRepository->remove($this->categoryRepository->findOneByUid($id));
$this->addFlashMessage('One category has been moved to trash', 'Done!', FlashMessage::WARNING);
$this->redirect('new', NULL, NULL);
}

/**
* Ajax
* @return void
*/
public function ajaxAction() {
switch (GeneralUtility::_GP('action')) {
case 'add':
if (NULL !== (GeneralUtility::_GP('name'))) {
$category = $this->objectManager->get(\Tutorboy\Blogmaster\Domain\Model\Category::class);
$category->setTitle(GeneralUtility::_GP('name'));
$category->setParent(GeneralUtility::_GP('parent'));
$this->categoryRepository->add($category);
$this->getPersistenceManager()->persistAll();
if ($category->getUid()) {
$catObject['name'] = $category->getTitle();
$catObject['parent'] = $category->getParent();
$catObject['id'] = $category->getUid();
header('Content-Type: application/json');
echo json_encode($catObject);
}
}
break;
default:
}
die();
}
}
Loading

0 comments on commit 9f696c7

Please sign in to comment.