Jump to content

Help structuring a very lightweight CMS of sorts


thenorman138

Recommended Posts

I'm creating a very lightweight interface that allows some users in our office to select predefined content (text, images, youtube/social links) or create their own text content using TinyMCE, and allow it to be viewed on different displays throughout the building.

In concept it's fairly simple: The user chooses one of four templates that each have a banner and footer, and either 1,2 or 3 div elements inside the body for different content. Each of these is defined as a panel. The template links pull 1 of 4 php class files that houses the html templating for each page and then I'm assinging tags to each panel type. So I have panel types of Banner, Footer, FullWidth, HalfLeft, HalfRight, etc. 

So if a user chooses the full width template, it has a banner, a footer, and one full width container div (ID is fullWidth). Upon saving this, that means I'm saving three panels to the database (panel_type of banner, footer, or fullWidth) as well a page record, since the three panels make up one page that will be assigned to a display or displays.

Would it make the most sense here to have a class for saving/adding panels and a separate class for saving/adding pages? 

In other words, when the save button is clicked, I'm at one time saving 3 panels that relate by foreign key to 1 page. At the same time this saves a reference to one or multiple displays. 

I'm basically asking, would I be better off to have one big class that saves all of this to the three respective tables, or should I call multiple classes, one for each part.

Here's an example of a full width template:

<div class="row top">
    <div class="col-lg-12">
        <div class="row" id="banner">
            Banner Text
        </div>
    </div>
</div>

<div class="row middle">
    <div class="col-lg-12">
        <div id="fullWidth" >
            <textarea id="mytextarea"></textarea><!--This is the usage of TinyMCE for their text content-->
            <input type="submit" value="Save Data">
        </div>
    </div>
</div>

<div class="row bottom">
    <div class="col-lg-12">
        <div class="marquee" id="footer">Footer Text</div>
    </div>
</div>

So they chose a template which calls a php file containing that above code (the html templating) and now upon submit I would call a 'save' class that saves the page record and assigns the 3 panels with a foreign key to the page ID.

Does this sound like a decent approach to this?

Link to comment
Share on other sites

If you want a very simple solution, serialization. The panel classes don't do anything except implement Serializable, and the database saving/restoring code simply un/serializes the objects as needed. They get serialized into a string which you can store directly. It's not searchable in the database, but I don't think the nature of this problem really lends itself to searching anyways.

Adding Serializable means a little more work because if the classes might possibly change implementations in the future then non-Serializable classes can break: if stored in one form, changed in the code, then unserialized later you can get weird results. A common way to use Serializable would be like

public function serialize() {
	return json_encode([
		"v" => 1,
		"header" => $this->header,
		"fullWidth" => $this->fullWidth,
		"footer" => $this->footer
	]);
}

public function unserialize($string) {
	$array = json_decode($string, false);
	switch ($array["v"]) {
		case 1:
		default:
			$this->header = $array["header"] ?? "";
			$this->fullWidth = $array["fullWidth"] ?? "";
			$this->footer = $array["footer"] ?? "";
			break;
	}
}

Should the class need to change in the future you update the methods accordingly.

public function serialize() {
	return json_encode([
		"v" => 2,
		"banner" => $this->banner,
		"fullWidth" => $this->fullWidth,
		"marquee" => $this->footer
	]);
}

public function unserialize($string) {
	$array = json_decode($string, false);
	switch ($array["v"]) {
		case 1:
			$this->banner = $array["header"];
			$this->fullWidth = $array["fullWidth"];
			$this->marquee = $array["footer"];
			break;
		case 2:
		default:
			$this->banner = $array["banner"] ?? "";
			$this->fullWidth = $array["fullWidth"] ?? "";
			$this->marquee = $array["marquee"] ?? "";
			break;
	}
}

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.