Minor tidy ups to doc blocks and unused properties in HTTPBulkToolsResponse (#178)

This commit is contained in:
Robbie Averill 2018-08-17 00:37:19 +12:00 committed by Thierry François
parent 7f2045e7aa
commit b9dad64ca8
1 changed files with 19 additions and 17 deletions

View File

@ -4,7 +4,9 @@ namespace Colymba\BulkTools;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\SS_List; use SilverStripe\ORM\SS_List;
use SilverStripe\View\HTML; use SilverStripe\View\HTML;
@ -61,7 +63,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
protected $message = ''; protected $message = '';
/** /**
* Gridfield instance. * GridField instance.
* *
* @var GridField * @var GridField
*/ */
@ -99,7 +101,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
* Create a new bulk tools HTTP response * Create a new bulk tools HTTP response
* *
* @param boolean $removesRows Does the action removes rows? * @param boolean $removesRows Does the action removes rows?
* @param gridfield $gridfield gridfield instance that holds the records list * @param GridField $gridfield gridfield instance that holds the records list
* @param int $statusCode The numeric status code - 200, 404, etc * @param int $statusCode The numeric status code - 200, 404, etc
* @param string $statusDescription The text to be given alongside the status code. * @param string $statusDescription The text to be given alongside the status code.
* See {@link setStatusCode()} for more information. * See {@link setStatusCode()} for more information.
@ -107,7 +109,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
public function __construct($removesRows, $gridfield, $statusCode = null) public function __construct($removesRows, $gridfield, $statusCode = null)
{ {
$this->removesRows = $removesRows; $this->removesRows = $removesRows;
$this->gridfield = $gridfield; $this->gridField = $gridfield;
register_shutdown_function(array($this, 'shutdown')); register_shutdown_function(array($this, 'shutdown'));
@ -115,7 +117,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
} }
/** /**
* Overriden here so content-type cannot be changed * Overridden here so content-type cannot be changed
* Add a HTTP header to the response, replacing any header of the same name. * Add a HTTP header to the response, replacing any header of the same name.
* *
* @param string $header Example: "content-type" * @param string $header Example: "content-type"
@ -147,8 +149,9 @@ class HTTPBulkToolsResponse extends HTTPResponse
} }
/** /**
* Overriden here so the response body cannot be set manually * Overridden here so the response body cannot be set manually
* *
* @param string $body
* @return $this * @return $this
*/ */
public function setBody($body) public function setBody($body)
@ -168,7 +171,8 @@ class HTTPBulkToolsResponse extends HTTPResponse
/** /**
* Set the general response message * Set the general response message
* *
* @param string $message
* @return $this * @return $this
*/ */
public function setMessage($message) public function setMessage($message)
@ -201,14 +205,14 @@ class HTTPBulkToolsResponse extends HTTPResponse
/** /**
* Add an ID to the successfully modified list * Add an ID to the successfully modified list
* @param interger $id the newly modified ID * @param int $id the newly modified ID
* @param string $className object class name (default to gridfield getModelClass()) * @param string $className object class name (default to gridfield getModelClass())
* @return $this * @return $this
*/ */
/*public function addSuccessID($id, $className = null) /*public function addSuccessID($id, $className = null)
{ {
if (!$className) { if (!$className) {
$className = $this->gridfield->getModelClass(); $className = $this->>gridField->getModelClass();
} }
//we use all caps ID since DO have their ID ion all caps, so createBody finds it... //we use all caps ID since DO have their ID ion all caps, so createBody finds it...
$this->successRecords[] = (object) ['ID' => (int) $id, 'ClassName' => $className]; $this->successRecords[] = (object) ['ID' => (int) $id, 'ClassName' => $className];
@ -230,7 +234,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
}*/ }*/
/** /**
* Return the list of succesful records * Return the list of successful records
* @return array * @return array
*/ */
public function getSuccessRecords() public function getSuccessRecords()
@ -280,19 +284,17 @@ class HTTPBulkToolsResponse extends HTTPResponse
*/ */
protected function getRecordGridfieldRow($record) protected function getRecordGridfieldRow($record)
{ {
$total = count($this->gridfield->getList()) + count($this->successRecords); $this->gridField->setList(new ArrayList(array($record)));
$index = 0;
$this->gridfield->setList(new ArrayList(array($record)));
$rowContent = ''; $rowContent = '';
foreach ($this->gridfield->getColumns() as $column) { foreach ($this->gridField->getColumns() as $column) {
$colContent = $this->gridfield->getColumnContent($record, $column); $colContent = $this->gridField->getColumnContent($record, $column);
// Null means this columns should be skipped altogether. // Null means this columns should be skipped altogether.
if ($colContent === null) { if ($colContent === null) {
continue; continue;
} }
$colAttributes = $this->gridfield->getColumnAttributes($record, $column); $colAttributes = $this->gridField->getColumnAttributes($record, $column);
$rowContent .= HTML::createTag( $rowContent .= HTML::createTag(
'td', 'td',
$colAttributes, $colAttributes,
@ -362,7 +364,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
} }
/** /**
* Catches fatal PHP eror and output something useful for the front end * Catches fatal PHP error and output something useful for the front end
*/ */
public function shutdown() public function shutdown()
{ {