New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress between Stage1 to Stage2 #1

Closed
wants to merge 4 commits into
base: stage1
from
Jump to file or symbol
Failed to load files and symbols.
+94 −0
Diff settings

Always

Just for now

@@ -0,0 +1,51 @@
<?php
class TestingCategoryGetNodesProcessor extends modObjectGetListProcessor {
public $classKey = 'TestingCategory';
public $languageTopics = array('testing:default');
public $objectType = 'testing.category';
public $defaultSortField = 'menuindex';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = null;
if ($_POST['node'] != 'root') {
$parent = explode('_', $_POST['node'])[1];
}
$c->where([
'parent' => $parent
]);
return parent::prepareQueryBeforeCount($c);
}
public function prepareRow(xPDOObject $object) {
$c = $this->modx->newQuery('TestingCategory');
$c->where([
'parent' => $object->get('id')
]);
$childrenCount = $this->modx->getCount('TestingCategory', $c);
$objectArray = [
'text' => $object->get('name'),
'id' => 'n_' . $object->get('id'),
'cls' => 'icon-menu',
'iconCls' => 'icon icon-' . ( $object->get('parent') != null ? 'navicon' : 'folder' ),
'type' => 'menu',
'pk' => $object->get('id'),
'leaf' => ($object->get('parent') != null),
'data' => $object->toArray()
];
if ($childrenCount < 1) {
// Workaround for leaf record not to display "arrows"
$objectArray['loaded'] = true;
}
return $objectArray;
}
public function outputArray(array $array, $count = false) {
return $this->modx->toJSON($array);
}
}
return 'TestingCategoryGetNodesProcessor';
@@ -0,0 +1,43 @@
<?php
class TestingCategorySortProcessor extends modProcessor {
public function process() {
$data = $this->getProperty('data');
if (empty($data)) {
return $this->failure();
}
$data = urldecode($data);
$data = $this->modx->fromJSON($data);
$nodes = [];
foreach ($data as $k => $v) {
$children = [];
foreach ($v as $ik => $iv) {
$children[] = explode('_', $ik)[1];
}
$nodes[] = [
'parent' => explode('_', $k)[1],
'children' => $children
];
}
for ($i = 0; $i < count($nodes); $i++) {
$parent_obj = $this->modx->getObject('TestingCategory', $nodes[$i]['parent']);
$parent_obj->set('parent', null);
$parent_obj->set('menuindex', $i);
$parent_obj->save();
for ($j = 0; $j < count($nodes[$i]['children']); $j++) {
$child_obj = $this->modx->getObject('TestingCategory', $nodes[$i]['children'][$j]);
$child_obj->set('parent', $nodes[$i]['parent']);
$child_obj->set('menuindex', $j);
$child_obj->save();
}
}
return $this->success();
}
}
return 'TestingCategorySortProcessor';
ProTip! Use n and p to navigate between commits in a pull request.