Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minors (Model.php) #1712

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Model
//--------------------------------------------------------------------

/**
* The column used for insert timestampes
* The column used for insert timestamps
*
* @var string
*/
Expand Down Expand Up @@ -487,28 +487,27 @@ public function save($data)
return $response;
}

//--------------------------------------------------------------------

/**
* Takes a class an returns an array of it's public and protected
* properties as an array suitable for use in creates and updates.
*
* @param string|object $data
* @param string $dateFormat
* @param string|null $primaryKey
* @param string $dateFormat
*
* @return array
* @throws \ReflectionException
*/
public static function classToArray($data, $pk = null, string $dateFormat = 'datetime'): array
public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array
{
if (method_exists($data, 'toRawArray'))
{
$properties = $data->toRawArray(true);

// Always grab the primary key otherwise updates will fail.
if (! empty($properties) && ! empty($pk) && ! in_array($pk, $properties))
if (! empty($properties) && ! empty($primaryKey) && ! in_array($primaryKey, $properties))
{
$properties[$pk] = $data->$pk;
$properties[$primaryKey] = $data->{$primaryKey};
}
}
else
Expand Down Expand Up @@ -573,14 +572,16 @@ public function getInsertID()

//--------------------------------------------------------------------


/**
* Inserts data into the current table. If an object is provided,
* it will attempt to convert it to an array.
*
* @param array|object $data
* @param boolean $returnID Whether insert ID should be returned or not.
* @param boolean $returnID Whether insert ID should be returned or not.
*
* @return integer|string|boolean
* @throws \ReflectionException
*/
public function insert($data = null, bool $returnID = true)
{
Expand Down Expand Up @@ -698,9 +699,10 @@ public function insertBatch($set = null, $escape = null, $batchSize = 100, $test
* it will attempt to convert it into an array.
*
* @param integer|array|string $id
* @param array|object $data
* @param array|object $data
*
* @return boolean
* @throws \ReflectionException
*/
public function update($id = null, $data = null)
{
Expand Down