1 <?php
 2 /**
 3  * @package     FrameworkOnFramework
 4  * @subpackage  table
 5  * @copyright   Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
 6  * @license     GNU General Public License version 2 or later; see LICENSE.txt
 7  */
 8 // Protect from unauthorized access
 9 defined('FOF_INCLUDED') or die;
10 
11 /**
12  * FrameworkOnFramework table behavior class for content History
13  *
14  * @package  FrameworkOnFramework
15  * @since    2.2.0
16  */
17 class FOFTableBehaviorContenthistory extends FOFTableBehavior
18 {
19     /**
20      * The event which runs after storing (saving) data to the database
21      *
22      * @param   FOFTable  &$table  The table which calls this event
23      *
24      * @return  boolean  True to allow saving without an error
25      */
26     public function onAfterStore(&$table)
27     {
28         $aliasParts = explode('.', $table->getContentType());
29         $table->checkContentType();
30 
31         if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
32         {
33             $historyHelper = new JHelperContenthistory($table->getContentType());
34             $historyHelper->store($table);
35         }
36 
37         return true;
38     }
39 
40     /**
41      * The event which runs before deleting a record
42      *
43      * @param   FOFTable &$table  The table which calls this event
44      * @param   integer  $oid  The PK value of the record to delete
45      *
46      * @return  boolean  True to allow the deletion
47      */
48     public function onBeforeDelete(&$table, $oid)
49     {
50         $aliasParts = explode('.', $table->getContentType());
51 
52         if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
53         {
54             $historyHelper = new JHelperContenthistory($table->getContentType());
55             $historyHelper->deleteHistory($table);
56         }
57 
58         return true;
59     }
60 }
61