Created
April 8, 2013 08:32
-
-
Save dfeyer/5335194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ttree\Medialib\Backoffice\Service\Account\Import; | |
/* * | |
* This script belongs to the FLOW3 package "Ttree.Medialib". * | |
* * | |
* */ | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\Flow\Security\Account; | |
use TYPO3\Flow\Utility\Now; | |
/** | |
* @Flow\Scope("session") | |
* @package Ttree\Medialib\Backoffice\Domain\Model\Dto | |
*/ | |
class ProcessingReport { | |
/** | |
* @var \TYPO3\Flow\Utility\Now | |
*/ | |
protected $sessionDate; | |
/** | |
* @var \Ttree\Medialib\Backoffice\Service\Account\Import\Source | |
*/ | |
protected $source = NULL; | |
/** | |
* @var integer | |
*/ | |
protected $processed = 0; | |
/** | |
* @var integer | |
*/ | |
protected $success = 0; | |
/** | |
* @var integer | |
*/ | |
protected $error = 0; | |
/** | |
* @var array | |
*/ | |
protected $messages = array(); | |
/** | |
* @Flow\Inject | |
* @var \Ttree\Medialib\Core\Service\TranslatorService | |
*/ | |
protected $translatorService; | |
/** | |
* @return \DateTime | |
*/ | |
public function getSessionDate() { | |
return $this->sessionDate; | |
} | |
/** | |
* @return int | |
*/ | |
public function getError() { | |
return $this->error; | |
} | |
/** | |
* @return int | |
*/ | |
public function getProcessed() { | |
return $this->processed; | |
} | |
/** | |
* @return int | |
*/ | |
public function getSuccess() { | |
return $this->success; | |
} | |
/** | |
* @return \Ttree\Medialib\Backoffice\Service\Account\Import\Source | |
*/ | |
public function getSource() { | |
return $this->source; | |
} | |
/** | |
* @param \Ttree\Medialib\Backoffice\Service\Account\Import\Source $source | |
* @Flow\Session(autoStart = TRUE) | |
*/ | |
public function setSource(Source $source) { | |
$this->processed = 0; | |
$this->success = 0; | |
$this->error = 0; | |
$this->messages = array(); | |
$this->sessionDate = new Now(); | |
$this->source = $source; | |
} | |
/** | |
* @param Account $account | |
* @param string $password | |
* @return $this | |
*/ | |
public function registerSuccess(Account $account, $password, $message = 'Account created with success') { | |
$this->processed++; | |
$this->success++; | |
$this->messages[] = array( | |
'status' => 200, | |
'account' => $account->getAccountIdentifier(), | |
'data' => array( | |
'password' => $password | |
), | |
'message' => $this->translatorService->translateByOriginalLabel($message, array(), NULL, NULL, 'AccountImport', 'Ttree.Medialib') | |
); | |
return $this; | |
} | |
/** | |
* @param string $message | |
* @param string $account | |
* @param string $fullname | |
* @param array $arguments | |
* @return \TYPO3\Flow\Error\Error | |
*/ | |
public function registerError($message, $account, $fullname = NULL, array $arguments = array()) { | |
$this->processed++; | |
$this->error++; | |
$message = $this->translatorService->translateByOriginalLabel($message, $arguments, NULL, NULL, 'AccountImport', 'Ttree.Medialib'); | |
if ($fullname !== NULL) { | |
$message = $fullname . ': ' . $message; | |
} | |
$this->messages[] = array( | |
'status' => 500, | |
'account' => $account, | |
'message' => $message | |
); | |
$message = $message . '(' . $account . ')'; | |
return new \TYPO3\Flow\Error\Error($message); | |
} | |
/** | |
* @return bool | |
*/ | |
public function hasErrors() { | |
if ($this->error > 0) { | |
return FALSE; | |
} | |
return TRUE; | |
} | |
/** | |
* @return array | |
*/ | |
public function getErrorMessages() { | |
return $this->getMessagesByStatus(500); | |
} | |
/** | |
* @param int $status | |
* @return array | |
*/ | |
protected function getMessagesByStatus($status = 200) { | |
return array_filter($this->messages, function ($el) use ($status) { | |
return $el['status'] === $status; | |
}); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment