Skip to content

Commit

Permalink
Merge pull request #25 from joomdonation/helper_cleanup
Browse files Browse the repository at this point in the history
Clean up UserlogsHelper
thanks @joomdonation
  • Loading branch information
alikon authored May 9, 2018
2 parents b2c60e6 + 475fbb4 commit a1ba21b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions administrator/components/com_userlogs/helpers/userlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ class UserlogsHelper
/**
* Method to extract data array of objects into CSV file
*
* @param array $data Has the data to be exported
* @param array $data The logs data to be exported
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function dataToCsv($data)
{
$date = JFactory::getDate();
$date = JFactory::getDate();
$filename = "logs_" . $date;
$data = json_decode(json_encode($data), true);

$app = JFactory::getApplication();
$app->setHeader('Content-Type', 'application/csv', true)
Expand All @@ -47,9 +46,11 @@ public static function dataToCsv($data)

foreach ($data as $log)
{
$app->triggerEvent('onLogMessagePrepare', array (&$log['message'], $log['extension']));
$log = (array) $log;
$log['ip_address'] = JText::_($log['ip_address']);
$log['extension'] = self::translateExtensionName(strtoupper(strtok($log['extension'], '.')));
$log['extension'] = self::translateExtensionName(strtoupper(strtok($log['extension'], '.')));

$app->triggerEvent('onLogMessagePrepare', array(&$log['message'], $log['extension']));

fputcsv($fp, $log, ',');
}
Expand Down Expand Up @@ -87,7 +88,7 @@ public static function translateExtensionName($extension)
*
* @param string $context The context of the content
*
* @return mixed An array of parameters, or false on error.
* @return mixed An object contain type parameters, or null if not found
*
* @since __DEPLOY_VERSION__
*/
Expand All @@ -101,14 +102,7 @@ public static function getLogMessageParams($context)

$db->setQuery($query);

$items = $db->loadObjectList();

if (empty($items))
{
return false;
}

return $items[0];
return $db->loadObject();
}

/**
Expand All @@ -128,6 +122,11 @@ public static function getDataByPks($pks, $field, $tableType, $tablePrefix = 'JT
$items = array();
$table = JTable::getInstance($tableType, $tablePrefix);

if ($table === false)
{
return $items;
}

foreach ($pks as $pk)
{
if ($table->load($pk))
Expand Down

0 comments on commit a1ba21b

Please sign in to comment.