Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save visay/2710335 to your computer and use it in GitHub Desktop.
Save visay/2710335 to your computer and use it in GitHub Desktop.
<?php
namespace TYPO3\Conference\Command;
/* *
* This script belongs to the FLOW3 package "Conference". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Party\Domain\Model\ElectronicAddress;
use TYPO3\Party\Domain\Model\PersonName;
use TYPO3\Conference\Domain\Model\Account\Participant;
use TYPO3\Conference\Domain\Model\Account\SpeakerProfile;
use TYPO3\Conference\Domain\Model\Conference;
use TYPO3\Faker\Name;
use Doctrine\ORM\Mapping as ORM;
use TYPO3\FLOW3\Annotations as FLOW3;
/**
* Command controller for setting up conference data and accounts
*
* @FLOW3\Scope("singleton")
*/
class SetupCommandController extends \TYPO3\FLOW3\Cli\CommandController {
/**
* @FLOW3\Inject
* @var \TYPO3\Conference\Domain\Repository\ConferenceRepository
*/
protected $conferenceRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\Conference\Domain\Repository\Conference\PaperRepository
*/
protected $paperRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\FLOW3\Security\AccountRepository
*/
protected $accountRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\Conference\Domain\Repository\Account\ParticipantRepository
*/
protected $participantRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\FLOW3\Security\AccountFactory
*/
protected $accountFactory;
/**
* @FLOW3\Inject
* @var \TYPO3\FLOW3\Package\PackageManagerInterface
*/
protected $packageManager;
/**
* Create local accounts for testing
*
* This creates a row of accounts which can be used for testing the Conference application during development.
* Note that you will only be able to login with these accounts when FLOW3 runs in Development context.
*
* The following accounts will be created by this command:
*
* ------------- ---------------------------------
* Identifier Roles
* ------------- ---------------------------------
* visitor Conference_Visitor
* speaker Conference_Visitor, Speaker
* speaker2 Conference_Visitor, Speaker
* trackchair Conference_Visitor, TrackChair
* trackchair2 Conference_Visitor, TrackChair
* administrator Conference_Visitor, Administrator
*
* The password of each account is equal to its account identifier.
*
* @return void
*/
public function createDummyAccountsCommand() {
$existingAdministratorAccount = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName('administrator', 'DevelopmentProvider');
if ($existingAdministratorAccount !== NULL) {
$this->outputLine('An administrator account already exists.');
$this->outputLine('You\'ll have to remove existing accounts in order to execute this command!');
return;
}
if ($this->packageManager->isPackageActive('TYPO3.Faker')) {
$this->createAccount(Name::firstName(), Name::lastName(), 'visitor', array('Conference_Visitor'));
$this->createAccount(Name::firstName(), Name::lastName(), 'speaker', array('Conference_Visitor', 'Speaker'));
$this->createAccount(Name::firstName(), Name::lastName(), 'speaker2', array('Conference_Visitor', 'Speaker'));
$this->createAccount(Name::firstName(), Name::lastName(), 'trackchair', array('Conference_Visitor', 'TrackChair'));
$this->createAccount(Name::firstName(), Name::lastName(), 'trackchair2', array('Conference_Visitor', 'TrackChair'));
$this->createAccount(Name::firstName(), Name::lastName(), 'administrator', array('Conference_Visitor', 'Administrator'));
} else {
$this->createAccount('Victor', 'Visitor', 'visitor', array('Conference_Visitor'));
$this->createAccount('Spencer', 'Speaker', 'speaker', array('Conference_Visitor', 'Speaker'));
$this->createAccount('Sebastian', 'Speaker', 'speaker2', array('Conference_Visitor', 'Speaker'));
$this->createAccount('Tracy', 'TrackChair', 'trackchair', array('Conference_Visitor', 'TrackChair'));
$this->createAccount('Tom', 'Tracker', 'trackchair2', array('Conference_Visitor', 'TrackChair'));
$this->createAccount('Armin', 'Administrator', 'administrator', array('Conference_Visitor', 'Administrator'));
}
$this->outputLine('Dummy accounts have been created.');
}
/**
* Create a conference for testing
*
* This command creates a dummy conference with sample data which can be used as a fixture during development and
* testing. This command must not be used on a production site as it will replace an existing, real conference
* if the --force flag is specified.
*
*
* @param boolean $force Create conference even if one is setup already. NOTE: This will delete any existing conference!
* @return void
*/
public function createDummyConferenceCommand($force = FALSE) {
$hasConferences = $this->conferenceRepository->countAll() > 0;
if ($hasConferences && $force === FALSE) {
$this->outputLine('A conference has been setup already. Specify force argument to ignore this.');
$this->outputLine('NOTE: This will delete any existing conference!');
return;
}
if ($hasConferences) {
$this->conferenceRepository->removeAll();
}
$conference = $this->createDummyConference();
$this->outputLine('Dummy conference "%s" has been created.', array($conference->getTitle()));
}
/**
* Creates an account for development use
*
* @param string $firstName
* @param string $lastName
* @param string $accountIdentifier
* @param array $roleIdentifiers
* @return void
*/
protected function createAccount($firstName, $lastName, $accountIdentifier, array $roleIdentifiers) {
$account = $this->accountFactory->createAccountWithPassword($accountIdentifier, $accountIdentifier, $roleIdentifiers, 'DevelopmentProvider');
$this->accountRepository->add($account);
$participant = new Participant();
$name = new PersonName('', $firstName, '', $lastName);
$participant->setName($name);
$participant->addAccount($account);
// speaker profile
if (in_array('Speaker', $roleIdentifiers)) {
$speakerProfile = new SpeakerProfile();
$speakerProfile->setShortBiography('Short biography of speaker "' . $firstName . ' ' . $lastName . '". Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut.');
$participant->setSpeakerProfile($speakerProfile);
}
// email address
$electronicAddress = new ElectronicAddress();
$electronicAddress->setIdentifier($firstName . '@' . $lastName . '.org');
$electronicAddress->setType(ElectronicAddress::TYPE_EMAIL);
$electronicAddress->setUsage(ElectronicAddress::USAGE_WORK);
$participant->setPrimaryElectronicAddress($electronicAddress);
$this->participantRepository->add($participant);
}
/**
* @return Conference
*/
protected function createDummyConference() {
$conference = new Conference();
$conference->setTitle('T3CON12 Asia');
$conference->setStartDate(new \DateTime('2012-08-17'));
$conference->setEndDate(new \DateTime('2012-08-19'));
$conference->setCallForPapersDueDate(new \DateTime("2012-05-25"));
$this->conferenceRepository->add($conference);
// location
$location = new Conference\Location();
$location->setTitle('Cambodia-Japan Cooperation Center');
$location->setAddress('Russian Boulevard' . chr(10) . 'Phnom Penh');
// rooms
$rooms = array();
foreach (array('Brüder-Grimm-Saal 01' => 600, 'Landgraf' => 250, 'Tagungsraum' => 200) as $title => $capacity) {
$room = new Conference\Location\Room();
$room->setTitle($title);
$room->setCapacity($capacity);
$rooms[] = $room;
$location->addRoom($room);
}
$conference->setLocation($location);
// session types
$sessionTypes = array();
foreach (
array(
array(
'title' => 'Talk',
'duration' => 45
),
array(
'title' => 'Talk (Long)',
'duration' => 90
),
array(
'title' => 'Exam',
'duration' => 45
),
array(
'title' => 'Tutorial',
'duration' => 240
),
array(
'title' => 'Tutorial (Long)',
'duration' => 480
),
) as $sessionTypeData) {
$sessionType = new Conference\SessionType();
$sessionType->setTitle($sessionTypeData['title']);
$sessionType->setDuration($sessionTypeData['duration']);
$sessionTypes[] = $sessionType;
$conference->addSessionType($sessionType);
}
// intermission types
$intermissionTypes = array();
foreach (
array(
array(
'title' => 'Coffee break',
'duration' => 45
),
array(
'title' => 'Lunch',
'duration' => 45
),
) as $intermissionTypeData) {
$intermissionType = new Conference\IntermissionType();
$intermissionType->setTitle($intermissionTypeData['title']);
$intermissionType->setDuration($intermissionTypeData['duration']);
$intermissionTypes[] = $intermissionType;
$conference->addIntermissionType($intermissionType);
}
// tracks
$tracks = array();
$trackChairs = $this->participantRepository->findByRoleIdentifier('TrackChair');
if (count($trackChairs) > 0) {
foreach (
array(
array(
'title' => 'Coding',
'description' => 'requires PHP knowledge, sub tracks: TYPO3 4.x, TYPO3 5.0, FLOW3',
'color' => 'red'
),
array(
'title' => 'Integration',
'description' => 'all about TypoScript, Templates and creating websites, cool Plugins & Distributions',
'color' => 'blue'
),
array(
'title' => 'Admin',
'description' => 'setting up and maintaining TYPO3 in various levels',
'color' => 'purple'
),
array(
'title' => 'Design and UX',
'description' => 'e.g. introduction to Fluid for webdesigners, UI design in TYPO3 5.0, creating themes, skins etc.',
'color' => 'green'
),
array(
'title' => 'Community',
'description' => 'e.g. "Welcome to TYPO3", "T3MOON – if T3DIVE doesn\'t thrill you anymore", "Promoting TYPO3", "TYPO3 Association"',
'color' => 'yellow'
),
array(
'title' => 'Business and Best Practices',
'description' => '',
'color' => 'pink'
),
) as $trackData) {
$track = new Conference\Track();
$track->setTitle($trackData['title']);
$track->setDescription($trackData['description']);
$track->setTrackChair($this->getRandomArrayEntry($trackChairs));
$track->setColor($trackData['color']);
$tracks[] = $track;
$conference->addTrack($track);
}
}
// papers
$papers = array();
$speakers = $this->participantRepository->findByRoleIdentifier('Speaker', 50); // Create at most 50 speakers
if (count($speakers) > 0) {
for ($i = 1; $i < 120; $i++) {
$paper = new Conference\Paper();
if ($this->packageManager->isPackageActive('TYPO3.Faker')) {
$paper->setTitle(substr(\TYPO3\Faker\Company::catchPhrase(), 0, 49));
$paper->setShortAbstract(\TYPO3\Faker\Company::bs() . ' ' . \TYPO3\Faker\Company::bs() . ' ' . \TYPO3\Faker\Company::bs());
$paper->setAbstract(\TYPO3\Faker\Lorem::paragraph(5));
} else {
$paper->setTitle('Paper #' . $i);
$paper->setShortAbstract('Lorem Ipsum Lorem Ipsum Lorem Ipsum');
$paper->setAbstract('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam volu');
}
$paper->setAuthor($this->getRandomArrayEntry($speakers));
$paper->setProposedSessionType($this->getRandomArrayEntry($sessionTypes));
$paper->setProposedTrack($this->getRandomArrayEntry($tracks));
$statusArray = array(
Conference\Paper::STATUS_DRAFT,
Conference\Paper::STATUS_ACCEPTED
);
$paper->setStatus($this->getRandomArrayEntry($statusArray));
if ($paper->isAccepted()) {
$paper->setFeatured($this->getRandomArrayEntry(array(TRUE, FALSE)));
}
$papers[] = $paper;
$this->paperRepository->add($paper);
}
}
// schedule
$schedule = new Conference\Schedule();
// sessions
foreach ($papers as $paper) {
$session = new Conference\Session();
$session->setPaper($paper);
$session->setRoom($this->getRandomArrayEntry($rooms));
$session->setStartTime(new \DateTime('now'));
$schedule->addActivity($session);
}
$conference->setSchedule($schedule);
$conference->activate();
return $conference;
}
/**
* @param array $array
* @return mixed a random entry of the given array
*/
protected function getRandomArrayEntry(array $array) {
$randomKey = array_rand($array);
return $array[$randomKey];
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment