SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/ColModifierActionLogData.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. /**
  17.  * Tries to extract a name from an action log entry to display with an ID
  18.  */
  19. class ColModifierActionLogData extends SortedColModifier
  20. {
  21.  
  22. /**
  23.   * Modify a column value
  24.   * This value will be html/csv/etc encoded afterwards.
  25.   *
  26.   * @param string $val The incoming value
  27.   * @param string $field_name The name of the field being modified
  28.   * @return string The modified value
  29.   */
  30. public function modify($val, $field_name)
  31. {
  32. $val = (int) $val;
  33. $q = "SELECT record_table, record_id, data FROM ~history_items WHERE id = ?";
  34. $row = Pdb::q($q, [$val], 'row');
  35.  
  36. $out = $row['record_id'];
  37. $name = '';
  38. $data = json_decode($row['data'], true);
  39. if (!empty($data['name'])) $name = $data['name'];
  40. if ($row['record_table'] == 'files') $name = $data['filename'];
  41. if ($name) $out .= ": {$name}";
  42. return $out;
  43. }
  44.  
  45. }
  46.