Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/kjvdictionary_store/modules/store/model/ |
Upload File : |
<?php
class ProductGroup_model extends Database_Model {
private $record_id;
private $DATA;
private $x_data;
public function RecordId() {
if (func_num_args()) {
$old_id = $this->record_id;
$this->record_id = func_get_arg(0);
if ($old_id != $this->record_id) {
$this->Load();
}
return $this;
}
return $this->record_id;
}
public function empty() {
return !is_object($this->DATA) || $this->DATA->empty();
}
protected function Load() {
$record = $this->record_id ? $this->record_id : -1;
$this->DATA = $this->Query("select * from `store_category` as p")
->Where('sc_id=%d', $record)
->First();
}
static
public function toSlug($name) {
$name = strtolower($name);
$name = trim(preg_replace('/[^[:alnum:][:space:]]/u', ' ', $name));
return preg_replace('~\s+~', '-', $name);
}
public function uri() {
if ($this->record_id) {
return '/' . \Misc::AsSlug($this->DATA->sc_caption) . '/c/' . $this->record_id;
} else {
return FALSE;
}
}
public function AsHandleBars() {
$data = [
'sc_id' => $this->record_id,
'sc_caption' => $this->DATA->sc_caption,
'sc_parent' => $this->DATA->sc_parent,
'list_parent' => $this->ListGroups($this->record_id),
'uri' => $this->uri(),
];
return $data;
}
public function SaveDetails($post) {
$record = $this->record_id ? $this->record_id : NULL;
$x = $this->TableName('store_category')
->AutoInc('sc_id')
->InsertOrUpdate([
'sc_id' => $record,
],[
'sc_parent' => $post['sc_parent'],
'sc_caption' => trim($post['sc_caption']),
]);
$this->record_id = $x->sc_id;
// signal to other processes record has changed. This will clear out the json file
hook_execute('event.change.category', $this->record_id);
return TRUE;
}
public function CustomFields($rep) {
$rep->pagesize(25);
$col = $rep->AddColumn();
$col->name('sc_caption')
->caption('Group Name')
->render(function($value, $item) {
$safename = htmlspecialchars($value);
$auth = hook_execute('nonce.create', FALSE, 'progroup', $item->sc_id, 600);
return "<a href=\"/admin/store/product-group?auth={$auth}\">$safename</a>";
});
$col = $rep->AddColumn();
$col->name('sc_parent')
->caption('Parent')
->render(function($value) {
return intval($value) ? htmlspecialchars($this->x_data[$value]) : '(none)';
});
}
public function ListGroups($group_id = 0) {
$this->Query("select * from `store_category`");
if ($group_id) $this->Where('sc_id <> %d', $group_id);
$rows = $this->OrderBy('sc_caption')
->Get();
$output = [];
foreach($rows as $row) {
$output[] = [
'key' => $row->sc_id,
'value' => $row->sc_caption,
];
}
return $output;
}
public function ProductGroupList($rep) {
$rows = $this->Query("select * from `store_category`")
->Get();
$this->x_data = [];
foreach($rows as $row) {
$this->x_data[$row->sc_id] = $row->sc_caption;
}
$data = $rep->Query('select * from `store_category`')->Execute();
return ['data' => $data];
}
public function generateSelect() {
$result = [];
$rows = $this->Query("select * from `store_category`")
->OrderBy('sc_caption')
->Get();
foreach($rows as $row) {
$result[] = [
'key' => 'cat:' . $row->sc_id,
'value' => 'Category: ' . $row->sc_caption,
];
}
return $result;
}
public function AsDataTable_GroupUsage() {
return [
'columns' => [
['data' => 'sku', 'width' => '105px', 'render' => ['_' => 'disp', 'sort' => 'val'] ],
['data' => 'sp_product' ],
],
'order' => [[ 0, 'asc' ]],
'pageLength' => 10,
'bPaginate' => TRUE,
'bFilter' => TRUE,
'bInfo' => TRUE, // Showing x to y of z entries
];
}
private function _getChildCategories(&$result, $children, $category_id) {
if (!in_array($category_id, $result)) {
$result[] = $category_id;
if (isset($children[$category_id])) {
foreach($children[$category_id] as $cat) {
$this->_getChildCategories($result, $children, $cat);
}
}
}
}
// result includes parent category_id
public function getChildCategories($category_id = 0) {
$rows = $this->Query("select sc_id,sc_parent from `store_category`")
->OrderBy('sc_caption')
->Get();
$children = [];
foreach($rows as $row) {
$parent = $row->sc_parent;
$children[$parent][] = $row->sc_id;
}
if (!$category_id) $category_id = $this->record_id;
$result = [];
$this->_getChildCategories($result, $children, $category_id);
return $result;
}
}