Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
onyx/model.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
85 lines (61 sloc)
2.42 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright (c) 2014-2021 Laposa Limited (https://laposa.ie) | |
* Licensed under the New BSD License. See the file LICENSE.txt for details. | |
* | |
* please note all local attribute should use "local_" prefix, i.e. client_customer.local_my_own_attribute. | |
* this will prevent any conflicts with future upgrades and also helps to identify what are your local attributes | |
* | |
*/ | |
require_once 'lib/onyx.db.php'; | |
class Onyx_Model extends Onyx_Db { | |
/** | |
* insertRevision | |
* | |
*/ | |
public function insertRevision($data) { | |
require_once('models/common/common_revision.php'); | |
$Revision = new common_revision(); | |
$revision_data = array(); | |
$revision_data['node_id'] = $data['id']; | |
$revision_data['object'] = $this->_class_name; | |
$revision_data['content'] = $data; | |
if ($revision_id = $Revision->insertRevision($revision_data)) { | |
msg("Saved revision ID $revision_id", 'ok', 1); | |
return $revision_id; | |
} else { | |
msg("Can't save revision for node ID {$revision_data['node_id']} on object {$revision_data['object']}", 'error'); | |
return false; | |
} | |
} | |
public function isRevisionEnabled() { | |
$enabled = ['common_node', 'common_file', 'common_image', 'common_configuration', 'ecommerce_offer', 'ecommerce_offer_group', 'ecommerce_product', 'ecommerce_product_image', 'ecommerce_product_variety', 'ecommerce_price', 'ecommerce_recipe', 'ecommerce_recipe_image','ecommerce_offer_product_variety', 'ecommerce_offer_taxonomy', 'ecommerce_store', 'ecommerce_store_image']; | |
if (in_array($this->_class_name, $enabled)) return true; | |
else return false; | |
} | |
/** | |
* insert a record | |
* | |
* @param array $data | |
* @return integer | |
*/ | |
public function insert($data) { | |
$result = parent::insert($data); | |
if ($result && $this->isRevisionEnabled()) { | |
$data['id'] = $result; | |
$this->insertRevision($data); | |
} | |
return $result; | |
} | |
/** | |
* update a record | |
* | |
* @param array $data | |
* @return integer | |
*/ | |
public function update($data) { | |
$result = parent::update($data); | |
if ($result && $this->isRevisionEnabled()) $this->insertRevision($data); | |
return $result; | |
} | |
} |