Extbase FeUser Example Extension

GIT: https://github.com/wallpageNET/infochy_feuserexample
TER: https://typo3.org/extensions/repository/view/infochy_feuserexample

Model

    /**
     * user
     *
     * @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
     */
    protected $user;
    
    /**
     * Returns the user
     *
     * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $user
     */
    public function getUser() {
        return $this->user;
    }

    /**
     * Sets the user
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $user
     * @return void
     */
    public function setUser($user) {
        $this->user = $user;
    }

Controller

    /**
     * action create
     *
     * @param \Infochy\InfochyFeuserexample\Domain\Model\MyData $newMyData
     * @return void
     */
    public function createAction(\Infochy\InfochyFeuserexample\Domain\Model\MyData $newMyData)
    {
        $this->addFlashMessage('createAction ADD FrontendUser', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);       

		
	$newMyData->getUser()->addUsergroup($this->getFrontendUserGroup());          
        $this->myDataRepository->add($newMyData);
        $this->redirect('list');
    }
    
    private function getFrontendUserGroup(){
    	$frontendUserGroups = $this->frontendUserGroupRepository->findByTitle('InfochyFeuserexample');
		$frontendUserGroup = $frontendUserGroups->getFirst();
		if(!is_null($frontendUserGroup)){
			return $frontendUserGroup;
		}else{
			$frontendUserGroup = $this->objectManager->get('TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup');
			$frontendUserGroup->setTitle('InfochyFeuserexample');
			$frontendUserGroup->setDescription('Title display only on Sys-Pages');
			$this->frontendUserGroupRepository->add($frontendUserGroup);
			$persistenceManager =  $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
			$persistenceManager->persistAll();	
	    	$frontendUserGroups = $this->frontendUserGroupRepository->findByTitle('InfochyFeuserexample');
			return $frontendUserGroups->getFirst();					
		}
    }

Controller -> frontendUserGroupRepository

    /**
     * frontendUserGroupRepository
     *
     * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository
     * @inject
     */
    protected $frontendUserGroupRepository = NULL;

TCA

		'user' => array(
			'exclude' => 1,
			'label' => 'Fe User',
			'config' => array(
				'type' => 'inline',
				'foreign_table' => 'fe_users',
				'minitems' => 0,
				'maxitems' => 1,
				'appearance' => array(
					'collapseAll' => 0,
					'levelLinksPosition' => 'top',
					'showSynchronizationLink' => 1,
					'showPossibleLocalizationRecords' => 1,
					'showAllLocalizationLink' => 1
				),
			),
		),	

Fluid-HTML

<label for="user.username">
	FeUser->username
</label><br />
	<f:form.textfield property="user.username" /><br />
	
<label for="user.password">
	FeUser->password
</label><br />
	<f:form.textfield property="user.password" /><br />
	
<label for="user.name">
	FeUser->name
</label><br />
	<f:form.textfield property="user.name" /><br />
	
<label for="user.email">
	FeUser->email
</label><br />
	<f:form.textfield property="user.email" /><br />

Extbase Ajax Example Extension

GIT: https://github.com/wallpageNET/infochy_ajaxexample
TER: https://typo3.org/extensions/repository/view/infochy_ajaxexample

Typoscript

page.includeJSFooter {
  infochy_ajaxexample = EXT:infochy_ajaxexample/Resources/Public/Javascript/ajax.js
}
ajaxCall = PAGE
ajaxCall {
   typeNum = 22222
   config {
    disableAllHeaderCode = 1
    xhtml_cleaning = 0
    admPanel = 0
    additionalHeaders = Content-type: text/plain
    no_cache = 1
    debug = 0
   }
   10 = USER
   10 {
	    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
	    extensionName = InfochyAjaxexample
	    pluginName = Plugin
	    vendorName = Infochy
	    controller = Ajaxexample
	    action = ajax
	    view < plugin.tx_infochyajaxexample_plugin.view
	    persistence < plugin.tx_infochyajaxexample_plugin.persistence
	    settings < plugin.tx_infochyajaxexample_plugin.settings
   }
}

JavaScript

$("form.newAjaxexample").submit(function (event) {
    event.preventDefault();
    var form = $(this);
    var action = form.attr("action"),
          method = form.attr("method"),
          data = form.serialize();

    $.ajax({
        url: action,
        type: method,
        data: data
        }).done(function (data) {
            $( "div.tx-infochy-ajaxexample" ).replaceWith( data );
        }).fail(function () {
			( "div.tx-infochy-ajaxexample" ).replaceWith("errorMessage");  
        }).always(function () {
        
        });
});

HTML

<f:form action="ajax" 
    controller="Ajaxexample" 
    extensionName="InfochyAjaxexample" 
    pluginName="Plugin"
    name="newAjaxexample"
    method="POST"  
    pageType="22222"
    class="newAjaxexample"  object="{newAjaxexample}">    
<f:render partial="Ajaxexample/FormFields" />
	<f:form.submit value="Ajax new" />
</f:form>

save FeUser To Model

/**
* action createFrontendUserAction
*
* @param \Vendor\extName\Domain\Model\Example $newExample
*/
public function createFrontendUserAction(\Vendor\extName\Domain\Model\Example $newExample) {
	$feuser = $this->objectManager->create('TYPO3\CMS\Extbase\Domain\Model\FrontendUser');
	$feuser->setName('Name');
	$feuser->setEmail('example@email.de');
	$feuser->setUsername('Username');
	$feuser->setPassword('Password');
	$newExample->setUser($feuser);
	$this->ExampleRepository->add($newExample);
}

FeUserService

class

namespace Infochy\InfochyFeuserexample\Domain\Service;

use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;

class FeUserService implements \TYPO3\CMS\Core\SingletonInterface {

  /**
   * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
   * @inject
   */
  protected $frontendUserRepository;

  /**
   * @return boolean
   */
  public function isUserActive() {
    return $this->getFrontendController()->loginUser;
  }

  /**
   * @return FrontendUser
   */
  public function getFrontendUser() {
    return $this->frontendUserRepository->findByIdentifier($this->getFrontendController()->fe_user->user['uid']);
  }

  /**
   * @param DomainObjectInterface $user
   * @return void
   */
  public function setFeUserActiv(DomainObjectInterface $user) {
    $frontendController = $this->getFrontendController();
    $frontendController->fe_user->createUserSession($user->_getCleanProperties());
    $frontendController->fe_user->loginSessionStarted = TRUE;
    $frontendController->fe_user->user = $frontendController->fe_user->fetchUserSession();
    $frontendController->loginUser = TRUE;
  }

  /**
   * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
   */
  protected function getFrontendController() {
    return $GLOBALS['TSFE'];
  }
}

inject

    /**
     * @var \Infochy\InfochyFeuserexample\Domain\Service\FeUserService
     * @inject
     */
    protected $feUserService;

FluidMail

class

use TYPO3\CMS\Extbase\Object\ObjectManager;

class FluidMail {
    protected $templateFolder = 'Resources/Private/Templates/Email/';

    protected $objectManager;
    protected $extKey;

    protected $recipient = array();
    protected $sender = array();
    protected $subject = '';

    protected $templateName;
    protected $viewArrayMultiple = array();

    public function __construct() {
        $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
    }
    public function setObjectManager($objectManager){
        $this->objectManager = $objectManager;
    }
    public function setExtKey($extKey){
        $this->extKey = $extKey;
    }
    public function setTemplateName($templateName){
        $this->templateName = $templateName;
    }
    public function setArrayToViewObject($viewArrayMultiple){
        $this->viewArrayMultiple = $viewArrayMultiple;
    }
    public function setTemplateFolder($templateFolder){
        $this->templateFolder = $templateFolder;
    }
    public function setMailParams(array $recipient, array $sender, $subject){
        $this->recipient = $recipient;
        $this->sender = $sender;
        $this->subject = $subject;
    }
    public function send(){
        $emailBody = $this->getHtmlTemplate();
        $message = $this->objectManager->get('TYPO3\CMS\Core\Mail\MailMessage');
        $message->setTo($this->recipient)
            ->setFrom($this->sender)
            ->setSubject($this->subject);
        $message->setBody($emailBody, 'text/html');
        $message->send();
        return $message->isSent();
    }
    protected function getHtmlTemplate(){
        $emailView = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');
        $emailView->setTemplatePathAndFilename($this->getTemplatePathAndFilename());
        $emailView->assignMultiple($this->viewArrayMultiple);
        return $emailView->render();

    }
    protected function getTemplatePathAndFilename(){
        return \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:'.$this->extKey.'/'.$this->templateFolder ) . $this->templateName . '.html';
    }
}

Use FluidMail

$fluidMail = new \Vendor\extName\Utility\FluidMail();
$fluidMail->setExtKey($this->extKey);
$fluidMail->setTemplateName('templateName');
$fluidMail->setArrayToViewObject(array('key' => 'value'));
$fluidMail->setMailParams(array('mail@to.de' => 'To'),array('mail@from.de' => 'From'),'hallo');
$fluidMail->send();

Tca Hook

ext_localconf.php

$hookPath = "EXT:extName/Classes/TcaHooks/class.Tx_extName_tcemainprocdm.php:Tx_extName_tcemainprocdm";
$GLOBALS["TYPO3_CONF_VARS"]["SC_OPTIONS"]["t3lib/class.t3lib_tcemain.php"]["processDatamapClass"][] = $hookPath;

Tx_extName_tcemainprocdm

class Tx_extName_tcemainprocdm {
    function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray) {
        if ($status == 'update' && $table == 'fe_users') {
        }
    }
}

Simple FeUser Session

$GLOBALS['TSFE']->fe_user->setKey('ses', 'extensionKey', $data);
$GLOBALS['TSFE']->fe_user->storeSessionData();	
$GLOBALS['TSFE']->fe_user->setKey('ses', 'extensionKey', null);
$GLOBALS['TSFE']->fe_user->storeSessionData();

Projekt: Formular-Engine

Die Formular-Engine gibt die Möglichkeit, mehrseitige Formulare über eine Konfigurationssprache
zu entwickeln. Die echte Konfigurationssprache wird automatisch aus dem Quellcode generiert. Mit
den Mitteln der aspektorientierten Programmierung und der Konfigurationssprache ist es möglich,
Funktionen dynamisch auszutauschen und zu cachen. Dieses Programm ist momentan in der
Planung und Entwicklung.

Projekt: Mikimag

Mikimag ist vergleichbar mit den Online-Magazinen NEON.de oder JETZT.de. Die Socialmedia
Anwendung erlaubt es jedem, aktiv als Autor mitzuschreiben. Es können mehrere Redakteure
Artikel schreiben und neue korrigierte Versionen eines Artikels anlegen. Der Chefredakteur hat die
Möglichkeit, einen Artikel frei zu schalten. Artikel werden automatisch nach Wertigkeit und Rubrik
auf die verschiedenen Seiten verteilt. Das Layout wird Anhand eines Konfigurations-Algorithmus
automatisch erzeugt.