Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
services
t3o sites
voting.typo3.org
extensions
election
Commits
29c34c1d
Commit
29c34c1d
authored
Dec 23, 2015
by
Oliver Eglseder
Browse files
[WIP][TASK] Create invitations for an election
parent
4cb65357
Changes
12
Hide whitespace changes
Inline
Side-by-side
Classes/Controller/BeElectionCircularController.php
View file @
29c34c1d
...
...
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Database\DatabaseConnection;
use
TYPO3\Election\Domain\Model\ElectionCircular
;
use
TYPO3\Election\Domain\Model\Elector
;
use
TYPO3\Election\Service\CircularService
;
use
TYPO3\Election\Service\ElectionInvitationService
;
use
TYPO3\Election\Utility\MailUtility
;
/**
...
...
@@ -149,8 +150,14 @@ class BeElectionCircularController extends AbstractProtectedBeController
*/
public
function
sendAction
(
ElectionCircular
$electionCircular
)
{
$circularService
=
$this
->
objectManager
->
get
(
CircularService
::
class
,
$this
->
configuration
);
$circularService
->
sendElectionCircular
(
$electionCircular
);
$electionInvitationService
=
$this
->
objectManager
->
get
(
ElectionInvitationService
::
class
);
$electionInvitationService
->
inviteElectors
(
$this
->
configuration
,
$electionCircular
);
$this
->
redirect
(
self
::
ACTION_SEND_PREVIEW
,
self
::
CONTROLLER_NAME
,
'election'
,
[
'electionCircular'
=>
$electionCircular
]
);
}
/**
...
...
Classes/Domain/Model/ElectionCircular.php
View file @
29c34c1d
...
...
@@ -138,7 +138,14 @@ class ElectionCircular extends AbstractEntity
*/
public
function
getRemainingReceivers
()
{
// TODO: return only those who did not receive an invitation yet
return
$this
->
getElection
()
->
getElectorate
()
->
getElectors
();
$election
=
$this
->
getElection
();
$electors
=
$election
->
getElectorate
()
->
getElectorsAsArray
();
$receivers
=
[];
foreach
(
$electors
as
$elector
)
{
if
(
!
$elector
->
hasElectionInvitationForElection
(
$election
))
{
$receivers
[]
=
$elector
;
}
}
return
$receivers
;
}
}
Classes/Domain/Model/ElectionInvitation.php
View file @
29c34c1d
...
...
@@ -25,20 +25,15 @@ class ElectionInvitation extends AbstractEntity
protected
$secret
=
''
;
/**
* @var \TYPO3\Election\Domain\Model\Election
* @var \TYPO3\Election\Domain\Model\Election
Circular
*/
protected
$election
=
null
;
protected
$election
Circular
=
null
;
/**
* @var \TYPO3\Election\Domain\Model\Elector
*/
protected
$elector
=
null
;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Election\Domain\Model\ElectionToken>
*/
protected
$electionTokens
=
[];
/**
* @return string
*/
...
...
@@ -56,19 +51,19 @@ class ElectionInvitation extends AbstractEntity
}
/**
* @return Election
* @return Election
Circular
*/
public
function
getElection
()
public
function
getElection
Circular
()
{
return
$this
->
election
;
return
$this
->
election
Circular
;
}
/**
* @param Election $election
* @param Election
Circular
$election
Circular
*/
public
function
setElection
(
$election
)
public
function
setElection
Circular
(
$election
Circular
)
{
$this
->
election
=
$election
;
$this
->
election
Circular
=
$election
Circular
;
}
/**
...
...
@@ -86,20 +81,4 @@ class ElectionInvitation extends AbstractEntity
{
$this
->
elector
=
$elector
;
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public
function
getElectionTokens
()
{
return
$this
->
electionTokens
;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $electionTokens
*/
public
function
setElectionTokens
(
$electionTokens
)
{
$this
->
electionTokens
=
$electionTokens
;
}
}
Classes/Domain/Model/Elector.php
View file @
29c34c1d
...
...
@@ -26,6 +26,11 @@ class Elector extends AbstractPerson
*/
protected
$electorates
=
''
;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Election\Domain\Model\ElectionInvitation>
*/
protected
$electionInvitations
=
[];
/**
* Elector constructor.
*/
...
...
@@ -60,4 +65,34 @@ class Elector extends AbstractPerson
$this
->
electorates
->
attach
(
$electorate
);
}
}
/**
* @return ElectionInvitation[]
*/
public
function
getElectionInvitations
()
{
return
$this
->
electionInvitations
;
}
/**
* @param ObjectStorage $electionInvitations
*/
public
function
setElectionInvitations
(
$electionInvitations
)
{
$this
->
electionInvitations
=
$electionInvitations
;
}
/**
* @param Election $election
* @return bool
*/
public
function
hasElectionInvitationForElection
(
Election
$election
)
{
foreach
(
$this
->
getElectionInvitations
()
as
$electionInvitation
)
{
if
(
$electionInvitation
->
getElectionCircular
()
->
getElection
()
===
$election
)
{
return
true
;
}
}
return
false
;
}
}
Classes/Domain/Model/Electorate.php
View file @
29c34c1d
...
...
@@ -46,7 +46,7 @@ class Electorate extends AbstractEntity
}
/**
* @return \TYPO3\
Election\Domain\Model\Elector[]
* @return \TYPO3\
CMS\Extbase\Persistence\ObjectStorage
*/
public
function
getElectors
()
{
...
...
Classes/Domain/Repository/ElectionInvitationRepository.php
0 → 100644
View file @
29c34c1d
<?php
namespace
TYPO3\Election\Domain\Repository
;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* 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.
*
* The TYPO3 project - inspiring people to share!
*/
use
TYPO3\CMS\Extbase\Persistence\Repository
;
/**
* Class ElectionInvitationRepository
*/
class
ElectionInvitationRepository
extends
Repository
{
}
Classes/Service/
Circular
Service.php
→
Classes/Service/
ElectionInvitation
Service.php
View file @
29c34c1d
...
...
@@ -14,49 +14,42 @@ namespace TYPO3\Election\Service;
* The TYPO3 project - inspiring people to share!
*/
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\Election\Domain\Model\Configuration
;
use
TYPO3\Election\Domain\Model\ElectionCircular
;
use
TYPO3\Election\Domain\Model\ElectionInvitation
;
use
TYPO3\Election\Domain\Model\Elector
;
/**
* Class
Circular
Service
* Class
ElectionInvitation
Service
*/
class
Circular
Service
class
ElectionInvitation
Service
{
/**
* @var Configuration
*/
protected
$configuration
=
null
;
/**
* @var \TYPO3\Election\Utility\MailUtility
* @var \TYPO3\Election\Domain\Repository\ElectionInvitationRepository
* @inject
*/
protected
$
mailUtilit
y
=
null
;
protected
$
electionInvitationRepositor
y
=
null
;
/**
* CircularService constructor.
*
* @param Configuration $configuration
*/
public
function
__construct
(
Configuration
$configuration
)
{
$this
->
configuration
=
$configuration
;
}
/**
* @param ElectionCircular $electionCircular
*/
public
function
sendElectionCircular
(
ElectionCircular
$electionCircular
)
public
function
inviteElectors
(
Configuration
$configuration
,
ElectionCircular
$electionCircular
)
{
$mailsToSend
=
$this
->
configuration
->
getNumberOfMails
();
$limit
=
$configuration
->
getNumberOfMails
();
$receiver
=
[];
$electors
=
[];
$allElectors
=
$electionCircular
->
getElection
()
->
getElectorate
()
->
getElectorsAsArray
();
while
(
count
(
$electors
)
<
$mailsToSend
&&
count
(
$allElectors
)
>
0
)
{
$electors
[]
=
array_pop
(
$allElectors
);
}
foreach
(
$electors
as
$elector
)
{
$this
->
mailUtility
->
sendElectionCircularToElector
(
$electionCircular
,
$elector
,
$this
->
configuration
);
$possibleReceivers
=
$electionCircular
->
getRemainingReceivers
();
while
(
count
(
$receiver
)
<
$limit
&&
count
(
$possibleReceivers
)
>
0
)
{
/** @var Elector $possibleReceiver */
$possibleReceiver
=
array_shift
(
$possibleReceivers
);
$receiver
[]
=
$possibleReceiver
;
$electionInvitation
=
new
ElectionInvitation
();
$electionInvitation
->
setElector
(
$possibleReceiver
);
$electionInvitation
->
setElectionCircular
(
$electionCircular
);
$electionInvitation
->
setSecret
(
GeneralUtility
::
getRandomHexString
(
mt_rand
(
180
,
220
)));
$this
->
electionInvitationRepository
->
add
(
$electionInvitation
);
}
}
}
Resources/Private/Language/locallang.xlf
View file @
29c34c1d
...
...
@@ -369,6 +369,9 @@
<trans-unit
id=
"view.be.election_circular.send_preview.remaining_receivers"
>
<source>
Remaining receivers
</source>
</trans-unit>
<trans-unit
id=
"view.be.election_circular.send_preview.send_invitations"
>
<source>
Send Invitations
</source>
</trans-unit>
<!-- MODEL ELECTION CIRCULARS -->
...
...
Resources/Private/Partials/Model/ElectionCircular/SendPreview.html
View file @
29c34c1d
<div>
<h2>
<f:translate
key=
"view.be.election_circular.send_preview.remaining_receivers"
>
Remaining receivers
</f:translate>
<f:translate
key=
"view.be.election_circular.send_preview.remaining_receivers"
>
Remaining receivers
</f:translate>
({electionCircular.remainingReceivers -> f:count()})
</h2>
<table
class=
"table"
>
...
...
Resources/Private/Templates/BeElectionCircular/SendPreview.html
View file @
29c34c1d
...
...
@@ -3,6 +3,11 @@
<f:layout
name=
"Backend"
/>
<f:section
name=
"LeftToolBar"
>
<f:link.action
class=
"btn btn-default"
action=
"send"
controller=
"BeElectionCircular"
arguments=
"{electionCircular:electionCircular}"
>
<core:icon
identifier=
"actions-move-right"
/>
<f:translate
key=
"view.be.election_circular.send_preview.send_invitations"
>
Send Invitations
</f:translate>
</f:link.action>
</f:section>
<f:section
name=
"RightToolBar"
>
...
...
ext_tables.sql
View file @
29c34c1d
...
...
@@ -46,17 +46,18 @@ CREATE TABLE tx_election_domain_model_election (
#
Table
structure
for
table
'tx_election_domain_model_elector'
#
CREATE
TABLE
tx_election_domain_model_elector
(
uid
INT
(
11
)
unsigned
NOT
NULL
auto_increment
,
pid
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_date
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_user
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
first_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
middle_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
last_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
gender
TINYINT
(
4
)
DEFAULT
'0'
NOT
NULL
,
email
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
electorates
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
uid
INT
(
11
)
unsigned
NOT
NULL
auto_increment
,
pid
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_date
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_user
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
first_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
middle_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
last_name
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
gender
TINYINT
(
4
)
DEFAULT
'0'
NOT
NULL
,
email
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
electorates
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
election_invitations
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
PRIMARY
KEY
(
uid
),
KEY
parent
(
pid
)
...
...
@@ -143,14 +144,14 @@ CREATE TABLE tx_election_domain_model_electioncircular (
#
Table
structure
for
table
'tx_election_domain_model_electioninvitation'
#
CREATE
TABLE
tx_election_domain_model_electioninvitation
(
uid
INT
(
11
)
unsigned
NOT
NULL
auto_increment
,
pid
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_date
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_user
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
secret
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
election
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
elector
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
uid
INT
(
11
)
unsigned
NOT
NULL
auto_increment
,
pid
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_date
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
creation_user
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
secret
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
election
_circular
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
elector
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
PRIMARY
KEY
(
uid
),
KEY
parent
(
pid
)
...
...
ext_typoscript_setup.txt
View file @
29c34c1d
...
...
@@ -44,6 +44,14 @@ config.tx_extbase.persistence.classes {
MM_opposite_field = electors
}
}
election_invitations {
mapOnProperty = electionInvitations
config {
type = inline
foreign_table = tx_election_domain_model_electioninvitation
foreign_field = elector
}
}
}
}
}
...
...
@@ -158,11 +166,11 @@ config.tx_extbase.persistence.classes {
tableName = tx_election_domain_model_electioninvitation
columns {
secret.mapOnProperty = secret
election {
mapOnProperty = election
election
_circular
{
mapOnProperty = election
Circular
config {
type = select
foreign_table = tx_election_domain_model_election
foreign_table = tx_election_domain_model_election
circular
}
}
elector {
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment