Commit b7662950 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

[TASK] Finalize extension

* Adds filter functionality
* Adds membership logos to filter
* Adds membership repository
* Adds some labels
* Finalize templates
parent 1ecfe5f7
......@@ -25,6 +25,13 @@ class Tx_T3oMembership_Controller_MemberController extends Tx_Extbase_MVC_Contro
*/
protected $memberRepository;
/**
* membershipRepository
*
* @var Tx_T3oMembership_Domain_Repository_MembershipRepository
*/
protected $membershipRepository;
/**
* injectMemberRepository
*
......@@ -35,13 +42,42 @@ class Tx_T3oMembership_Controller_MemberController extends Tx_Extbase_MVC_Contro
$this->memberRepository = $memberRepository;
}
/**
* injectMembershipRepository
*
* @param Tx_T3oMembership_Domain_Repository_MembershipRepository $membershipRepository
* @return void
*/
public function injectMembershipRepository(Tx_T3oMembership_Domain_Repository_MembershipRepository $membershipRepository) {
$this->membershipRepository = $membershipRepository;
}
/**
* action list
*
* @return void
*/
public function listAction() {
$members = $this->memberRepository->findAll();
$filterMembership = 0;
$filterString = '';
if ($this->request->hasArgument('filter') && $this->request->getArgument('filter')) {
$filterString = htmlspecialchars($this->request->getArgument('filter'));
$this->view->assign('filter', $filterString);
}
if ($this->request->hasArgument('membership') && $this->request->getArgument('membership')) {
$filterMembership = (int) $this->request->getArgument('membership');
$this->view->assign('membership', $filterMembership);
}
if ($filterString || $filterMembership) {
$members = $this->memberRepository->findByStringAndMembership($filterString, $filterMembership);
} else {
$members = $this->memberRepository->findAll();
}
$memberships = $this->membershipRepository->findAll();
$this->view->assign('memberships', $memberships);
$this->view->assign('members', $members);
}
......
......@@ -34,6 +34,13 @@ class Tx_T3oMembership_Domain_Model_Membership extends Tx_Extbase_DomainObject_A
*/
protected $logo;
/**
* @return string
*/
public function __toString() {
return $this->name;
}
/**
* Returns the name
*
......
......@@ -18,4 +18,37 @@
*/
class Tx_T3oMembership_Domain_Repository_MemberRepository extends Tx_Extbase_Persistence_Repository {
/**
* @var array
*/
protected $defaultOrderings = array(
'membership' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
'name' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING
);
/**
* @param string $filterString
* @param integer $filterMembership
* @return Tx_Extbase_Persistence_QueryResultInterface
*/
public function findByStringAndMembership($filterString, $filterMembership) {
$query = $this->createQuery();
$constraints = array();
if ($filterString) {
$filterString = $this->getDatabaseConnection()->escapeStrForLike($filterString, 'tx_t3omembership_domain_model_member');
$constraints[] = $query->like('name', '%' . $filterString . '%');
}
if ($filterMembership) {
$constraints[] = $query->equals('membership', $filterMembership);
}
return $query->matching($query->logicalAnd($constraints))->execute();
}
/**
* @return t3lib_DB
*/
protected function getDatabaseConnection() {
return $GLOBALS['TYPO3_DB'];
}
}
\ No newline at end of file
<?php
/**
* 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!
*/
/**
* Class Tx_T3oMembership_Domain_Repository_MembershipRepository
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class Tx_T3oMembership_Domain_Repository_MembershipRepository extends Tx_Extbase_Persistence_Repository {
/**
* @var array
*/
protected $defaultOrderings = array(
'uid' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING
);
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ class Tx_T3oMembership_Task_ImportMembersTask extends tx_scheduler_Task {
if (!file_exists(PATH_site . $this->getImportFile())) {
return FALSE;
} else {
$this->getDatabaseConnection()->exec_TRUNCATEquery('tx_t3omembership_domain_model_member');
$fileData = file(PATH_site . $this->getImportFile());
foreach ($fileData as $key => $line) {
if ($key) {
......@@ -65,11 +66,13 @@ class Tx_T3oMembership_Task_ImportMembersTask extends tx_scheduler_Task {
* @return integer
*/
protected function getMembershipUid($membershipName) {
$membershipName = trim(str_replace('Membership', '', $membershipName));
$membershipName = $this->getDatabaseConnection()
->fullQuoteStr(trim(str_replace('Membership', '', $membershipName)), 'tx_t3omembership_domain_model_membership');
$membershipRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_t3omembership_domain_model_membership',
'name = "' . mysql_real_escape_string($membershipName) . '" AND NOT deleted AND NOT hidden'
'name = ' . $membershipName . ' AND NOT deleted AND NOT hidden'
);
if (!empty($membershipRecord)) {
$membershipUid = $membershipRecord['uid'];
......
......@@ -23,6 +23,7 @@
<label index="filter">Search</label>
<label index="importFile">CSV file to import</label>
<label index="storagePid">Where to store the member records</label>
<label index="allMemberships">All memberships</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
<div class="b-members-filter">
<ul>
<li class="membershiptype-reset act empty-option">
<f:link.action action="list" arguments="{filter: '{filterTerm}'}">
<f:translate key="allMemberships" />
</f:link.action>
</li>
<f:if condition="{filterTerm}">
<f:then>
<f:groupedFor each="{members}" as="membershipsOfMembers" groupBy="membership" groupKey="membership">
<li>
<f:link.action action="list" arguments="{filter: '{filterTerm}', membership: '{membership.uid}'}">
<f:image src="uploads/tx_t3omembership/{membership.logo}" alt="{membership.name}" />
</f:link.action>
</li>
</f:groupedFor>
</f:then>
<f:else>
<f:for each="{memberships}" as="membership">
<li>
<f:link.action action="list" arguments="{membership: '{membership.uid}'}">
<f:image src="uploads/tx_t3omembership/{membership.logo}" alt="{membership.name}" />
</f:link.action>
</li>
</f:for>
</f:else>
</f:if>
</ul>
</div>
\ No newline at end of file
......@@ -2,8 +2,8 @@
<f:section name="main">
<f:flashMessages />
<f:render partial="Member/Filter" />
<f:render partial="Member/Membership" />
<f:render partial="Member/Filter" arguments="{filterTerm: filter}" />
<f:render partial="Member/Membership" arguments="{members: members, memberships: memberships, filterTerm: filter}" />
<table class="tx_t3omembership" >
<tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment