Skip to content

Commit

Permalink
Merge pull request #60 from laposa/59-create-bocomponentnode_list_con…
Browse files Browse the repository at this point in the history
…tent

Add content card list component
  • Loading branch information
norbertlaposa committed Apr 3, 2024
2 parents bb3587e + 4270c98 commit 853cf27
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 29 deletions.
7 changes: 4 additions & 3 deletions controllers/bo/component/node_add.php
Expand Up @@ -27,6 +27,7 @@ public function mainAction() {
require_once('models/common/common_node.php');

$node_data = $_POST['node'];
$position = $_POST['position'] ?? null;

$Node = new common_node();

Expand All @@ -46,8 +47,7 @@ public function mainAction() {
/**
* insert a new node
*/

if($id = $Node->nodeInsert($node_data)) {
if($id = $Node->nodeInsert($node_data, $position)) {

//quick pages builder
//is broken :) $Page_builder = new Onyx_Request("bo/page_builder@blank&parent=$id&node_group={$node_data['node_group']}&node_controller={$node_data['node_controller']}");
Expand All @@ -73,10 +73,11 @@ public function mainAction() {

$node_controller = $node_data['node_controller'];
$node_group = $this->GET['node_group'];
$only_group = $this->GET['only_group'];
if ($node_group == 'container') $node_group = 'page';

// get the list of node types
$Node_type = new Onyx_Request("bo/component/node_type_menu~id=new:open={$node_controller}:node_group={$node_group}:expand_all=$expand_all~");
$Node_type = new Onyx_Request("bo/component/node_type_menu~id=new:open={$node_controller}:node_group={$node_group}:expand_all=$expand_all:only_group=$only_group~");
$this->tpl->assign("NODE_TYPE", $Node_type->getContent());

$this->tpl->parse('content.form');
Expand Down
93 changes: 93 additions & 0 deletions controllers/bo/component/node_list_cards.php
@@ -0,0 +1,93 @@
<?php
/**
* Copyright (c) 2007-2022 Laposa Limited (https://laposa.ie)
* Licensed under the New BSD License. See the file LICENSE.txt for details.
*
*/
require_once('controllers/bo/component/file.php');

class Onyx_Controller_Bo_Component_Node_List_Cards extends Onyx_Controller {

/**
* main action
*/

public function mainAction() {

require_once('models/common/common_node.php');

if (!is_numeric($this->GET['id'])) {
msg('node_child: id is not numeric', 'error');
return false;
}

$Node = new common_node();

$node_detail = $Node->getDetail($this->GET['id']);

if (!is_array($node_detail)) {
msg("node_child: Node not found", 'error');
return false;
}

/**
* set node group as parent if not provided
*/


if ($this->GET['node_group'] != '') $this->tpl->assign('NODE_GROUP', $this->GET['node_group']);
else $this->tpl->assign('NODE_GROUP', $node_detail['node_group']);

$this->tpl->assign("NODE", $node_detail);

//get children
$children = $Node->getChildren($node_detail['id'], 'parent_container ASC, priority DESC, id ASC');
$count = 0;

if (is_array($children) && count($children) > 0) {
foreach ($children as $key=>$child) {
if ($child['publish'] == 0) $child['class'] = 'disabled';
if ($child['node_group'] == 'content') {
$count++;
$content_excerpt = "";
if($child['content'] != "") {
$content = strip_tags($child['content']);
$content_excerpt = strlen($content > 200) ? substr($content, 0, 200) . "..." : $content;
}
$sub_items = $Node->getChildren($child['id'], 'parent_container ASC, priority DESC, id ASC');

$_Onyx_Request = new Onyx_Request("bo/component/file_list~type=add_to_node:node_id={$child['id']}:relation=node~");
$this->tpl->assign('FILE_LIST', $_Onyx_Request->getContent());
$this->tpl->assign("CHILD", $child);
$this->tpl->assign("INDEX", $key + 1);

if($child['description']) { $this->tpl->parse('content.children.item.description'); }
if($child['css_class']) { $this->tpl->parse('content.children.item.css_class'); }
if($child['custom_fields']) { $this->tpl->parse('content.children.item.custom_fields'); }

if($content_excerpt) {
$this->tpl->assign("CONTENT_EXCERPT", $content_excerpt);
$this->tpl->parse('content.children.item.content_excerpt');
}

if(count($sub_items) > 0) {
$this->tpl->assign("SUB_ITEMS", count($sub_items) ?? 0);
$this->tpl->parse('content.children.item.sub_items');
}

$this->tpl->parse('content.children.item');
};
}

if($count > 0) {
$this->tpl->parse('content.children');
} else {
$this->tpl->parse('content.empty');
}
} else {
$this->tpl->parse('content.empty');
}

return true;
}
}
18 changes: 12 additions & 6 deletions controllers/bo/component/node_type_menu.php
Expand Up @@ -142,12 +142,18 @@ public function reorder($md_tree) {

//reorder
$temp = array();
$temp[0] = $this->findInMdTree($md_tree, 'content');//content
$temp[1] = $this->findInMdTree($md_tree, 'layout');//layout
$temp[2] = $this->findInMdTree($md_tree, 'page');//page
$temp[3] = $this->findInMdTree($md_tree, 'container');//container
$temp[4] = $this->findInMdTree($md_tree, 'site');//site
$temp[4] = $this->findInMdTree($md_tree, 'variable');

if($this->GET['only_group'] && $this->GET['only_group'] !== "") {
$temp[0] = $this->findInMdTree($md_tree, $this->GET['only_group']);
} else {
$temp[0] = $this->findInMdTree($md_tree, 'content');//content
$temp[1] = $this->findInMdTree($md_tree, 'layout');//layout
$temp[2] = $this->findInMdTree($md_tree, 'page');//page
$temp[3] = $this->findInMdTree($md_tree, 'container');//container
$temp[4] = $this->findInMdTree($md_tree, 'site');//site
$temp[4] = $this->findInMdTree($md_tree, 'variable');
}


$md_tree = $temp;

Expand Down
6 changes: 5 additions & 1 deletion models/common/common_node.php
Expand Up @@ -717,7 +717,7 @@ function restoreRevision($revision_data) {
* @return integer $id
*/

function nodeInsert($node_data) {
function nodeInsert($node_data, $position = null) {

//if title is empty, create a generic title and don't display it
if ($node_data['title'] == '') {
Expand Down Expand Up @@ -771,6 +771,10 @@ function nodeInsert($node_data) {
$node_data['id'] = $id;

if ($node_data['node_group'] == 'page') $this->insertNewMappingURI($node_data);

if($position) {
$this->changePosition($id, $position);
}

return $id;
} else {
Expand Down

0 comments on commit 853cf27

Please sign in to comment.