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

[TASK] Adds member importer

* Adds scheduler task to import members
parent 33b261d7
<?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_Task_ImportMembersAdditionalFields
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class Tx_T3oMembership_Task_ImportMembers_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
/**
* Gets additional fields to render in the form to add/edit a task
* @param array $taskInfo
* @param tx_scheduler_Task $task
* @param tx_scheduler_Module $schedulerModule
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '',
* 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
*/
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) {
$additionalFields = array();
// adds field for setting file path for CSV file to import
$additionalFields['importFile'] = array(
'code' => '<input type="text" name="tx_scheduler[importFile]" value="' . $task->getImportFile() . '" />',
'label' => Tx_Extbase_Utility_Localization::translate('importFile', 't3o_membership')
);
// adds field for setting storage PID
$additionalFields['storagePid'] = array(
'code' => '<input type="text" name="tx_scheduler[storagePid]" value="' . $task->getMembershipStoragePid() . '" />',
'label' => Tx_Extbase_Utility_Localization::translate('storagePid', 't3o_membership')
);
return $additionalFields;
}
/**
* Validates the additional fields' values
* @param array $submittedData
* @param tx_scheduler_Module $schedulerModule
* @return boolean
*/
public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) {
// only validation for importFile would be a file_exists, but it will be validated in the task itself
return TRUE;
}
/**
* Takes care of saving the additional fields' values in the task's object
* @param array $submittedData
* @param tx_scheduler_Task $task
* @return void
*/
public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
$task->setImportFile($submittedData['importFile']);
$task->setMembershipStoragePid($submittedData['storagePid']);
}
}
\ 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_Task_ImportMembersTask extends tx_scheduler_Task {
/**
* @var string
*/
protected $importFile = '';
/**
* @var integer
*/
protected $membershipStoragePid = 0;
/**
* @return boolean
*/
public function execute() {
// does the import file exist?
if (!file_exists(PATH_site . $this->getImportFile())) {
return FALSE;
} else {
$fileData = file(PATH_site . $this->getImportFile());
foreach ($fileData as $key => $line) {
if ($key) {
$fields = t3lib_div::trimExplode("\t", $line);
$member = array(
'name' => $fields[6],
'external_id' => (int) $fields[0],
'address' => $fields[7] ? $fields[7] : $fields[8],
'zip' => $fields[10],
'city' => $fields[11],
'end_date' => strtotime($fields[16]),
'membership' => $this->getMembershipUid($fields[12]),
'pid' => $this->getMembershipStoragePid(),
'crdate' => time(),
'tstamp' => time()
);
$this->getDatabaseConnection()->exec_INSERTquery(
'tx_t3omembership_domain_model_member',
$member
);
}
}
}
return TRUE;
}
/**
* @param string $membershipName
* @return integer
*/
protected function getMembershipUid($membershipName) {
$membershipName = trim(str_replace('Membership', '', $membershipName));
$membershipRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_t3omembership_domain_model_membership',
'name = "' . mysql_real_escape_string($membershipName) . '" AND NOT deleted AND NOT hidden'
);
if (!empty($membershipRecord)) {
$membershipUid = $membershipRecord['uid'];
} else {
$newMembership = array(
'name' => mysql_real_escape_string($membershipName),
'pid' => $this->getMembershipStoragePid(),
'crdate' => time(),
'tstamp' => time()
);
$this->getDatabaseConnection()->exec_INSERTquery(
'tx_t3omembership_domain_model_membership',
$newMembership
);
$membershipUid = $this->getDatabaseConnection()->sql_insert_id();
}
return $membershipUid;
}
/**
* Gets importFile
* @return string
*/
public function getImportFile() {
return $this->importFile;
}
/**
* Sets importFile
* @param string $importFile
*/
public function setImportFile($importFile) {
$this->importFile = $importFile;
}
/**
* Gets membershipStoragePid
* @return int
*/
public function getMembershipStoragePid() {
return $this->membershipStoragePid;
}
/**
* Sets membershipStoragePid
* @param int $membershipStoragePid
*/
public function setMembershipStoragePid($membershipStoragePid) {
$this->membershipStoragePid = $membershipStoragePid;
}
/**
* @return t3lib_DB
*/
protected function getDatabaseConnection() {
return $GLOBALS['TYPO3_DB'];
}
}
\ No newline at end of file
......@@ -9,6 +9,6 @@ plugin.tx_t3omembership {
}
persistence {
# cat=plugin.tx_t3omembership//a; type=string; label=Default storage PID
storagePid = 883
storagePid = 884
}
}
\ No newline at end of file
......@@ -21,6 +21,8 @@
<label index="tx_t3omembership_domain_model_membership.name">name</label>
<label index="tx_t3omembership_domain_model_membership.logo">logo</label>
<label index="filter">Search</label>
<label index="importFile">CSV file to import</label>
<label index="storagePid">Where to store the member records</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
......@@ -6,7 +6,7 @@
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="tx_t3omembership_domain_model_member">Member</label>
<label index="tx_t3omembership_domain_model_member.name">Name</label>
<label index="tx_t3omembership_domain_model_member.external_id">External Id</label>
......@@ -23,6 +23,8 @@
<label index="tx_t3omembership_domain_model_membership.name">Name</label>
<label index="tx_t3omembership_domain_model_membership.logo">Logo</label>
<label index="tx_t3omembership_task_importmemberstask.name">Import members from CSV file</label>
<label index="tx_t3omembership_task_importmemberstask.description">Import members from CSV file</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
<f:layout name="Default" />
<f:section name="main">
<h1>Listing for Member</h1>
<f:flashMessages />
<f:render partial="Member/Filter" />
......
<?php
$extensionClassesPath = t3lib_extMgm::extPath('t3o_membership', 'Classes/');
return array(
'tx_t3omembership_task_importmemberstask' => $extensionClassesPath . 'Task/ImportMembersTask.php',
'tx_t3omembership_task_importmembers_additionalfieldprovider' => $extensionClassesPath . 'Task/ImportMembersAdditionalFieldProvider.php'
);
......@@ -8,13 +8,19 @@ Tx_Extbase_Utility_Extension::configurePlugin(
'List',
array(
'Member' => 'list',
),
// non-cacheable actions
array(
'Member' => '',
)
);
?>
\ No newline at end of file
// Import members
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_T3oMembership_Task_ImportMembersTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_t3omembership_task_importmemberstask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_t3omembership_task_importmemberstask.description',
'additionalFields' => 'tx_t3omembership_task_importmembers_additionalfieldprovider',
);
\ No newline at end of file
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