(07-13-2016, 02:47 PM)ivantcholakov Wrote: @mwebdesign
Have a look at this project of mine (The MIT license): https://github.com/ivantcholakov/starter...-edition-4
If you think that it could be useful, enable receiving private messages in your profile in this forum and send me a private message. I will give you for free source to a small CMS built on top of this starter. I think, it will give you an idea how you could structure your code with scalability in mind, without much talking. It would not fit exactly to what you need, some features you should port/write alone, but at least you will start at a higher level.
But honestly, I still feel skepticism. I hope I am wrong.
@
ivantcholakov
I've enabled private messages in my profile, but I'm not sure how to send one to you. I would love to see what you have come up with. I'm not so novice of a programmer that I can't recognize and utilize parts of good code when I see it!
Also, I understand your skepticism. I hope you are wrong as well
Since most of this thread has been conversation with no code (on my part), I wanted to post what I've been working on today and get feedback from you guys, if that's cool. Plus, I feel like it's only fair...I don't want you guys thinking you're wasting all this good advice on someone who's completely oblivious. (so if my code looks like I'm completely oblivious, please let me know!!)
So, I have a "Version" controller with a 'view' method, as follows: (it's a bit messy, but that's mostly because I'm still figuring it all out)
PHP Code:
public function view($versionid = "") {
if(empty($versionid)) $this->template->error(lang("error_51")); //invalid profile
$version = $this->apps_model->get_version_information($versionid);
$feature_array = $this->features_model->get_features_by_version_id($versionid);
for($i = 0; $i < count($feature_array); $i++){
$json = json_decode(json_encode($feature_array[$i]), true);
$tempFeature = new Feature();
$tempFeature->setBasics($json['feature_id'], $json['display_type'], $json['detail_display_type'], $json['display_order'], $json['name'], $json['feature_type'] );
if(isset($json['image'])){
$tempFeature->setImage($json['image']);
}
if(isset($json['parent_id'])){
$tempFeature->setParent($json['parent_id']);
}
//
$test_array[$i] = $tempFeature->getFeatureInfo(1);
}
$featureFam = new $FeatureFamily();
$versionSettings = json_decode($version->settings, true);
$this->load->view("versions/view.php", array(
"features" => $tempFeature,
"test" => $test_array,
"version" => $version,
"versionSettings" => $versionSettings
));
}
I'm struggling with exactly how to work with the JSON data that I pull from the db...but I'll eventually figure that out!
I then have 2 libraries (is this the best place to put this logic? I wasn't sure) called "Feature" and "FeatureFamily" which handle individual feature logic and a block of features, respectively (...i plan to rename FeatureFamily to FeatureBlock actually)
These are basically following along the Composite Design Pattern examples I found and aren't fully functional yet, but they're getting closer.
Feature library:
PHP Code:
class Feature extends AppBuild
{
private $feature_id;
private $display_type;
private $detail_display_type;
private $display_order;
private $name;
private $feature_type;
private $settings; // separate...? FeatureColorSettings class
private $image; // if relavant
private $parent_id; //if relevant
public function setBasics($feature_id, $display_type, $detail_display_type, $display_order, $name,$feature_type) {
$this->feature_id = $feature_id;
$this->display_type = $display_type;
$this->detail_display_type = $detail_display_type;
$this->display_order = $display_order;
$this->name = $name;
$this->feature_type = $feature_type;
}
public function setImage($image){
$this->image = $image;
}
public function setParent($parent_id){
$this->parent_id = $parent_id;
}
public function setSettings($settingsArray){
//...still working on
}
function getFeatureInfo($featureToGet) {
if(1 == $featureToGet){
return $this->name. " as feature type: " .$this->feature_type. "<br>";
} else {
return FALSE;
}
}
function getFeatureCount() { return 1; }
function setFeatureCount($newCount) { return FALSE; }
function addFeature($oneFeature) { return FALSE; }
function removeFeature($oneFeature) { return FALSE; }
}
FeatureFamily library:
PHP Code:
class FeatureFamily extends AppBuild
{
private $features = array();
private $featureCount;
public function __construct() {
$this->setFeatureCount(0);
}
public function getFeatureCount() {
return $this->featureCount;
}
public function setFeatureCount($newCount) {
$this->featureCount = $newCount;
}
public function getFeatureInfo($featureToGet) {
if ($featureToGet <= $this->featureCount) {
return $this->features[$featureToGet]->getFeatureInfo(1);
} else {
return FALSE;
}
}
public function addFeature($feature) {
$this->setFeatureCount($this->getFeatureCount() + 1);
$this->features[$this->getFeatureCount()] = $feature;
return $this->getFeatureCount();
}
public function removeFeature($feature) {
$counter = 0;
while (++$counter <= $this->getFeatureCount()) {
if($feature->getFeatureInfo(1) == $this->features[$counter]->getFeatureInfo(1)) {
for ($x = $counter; $x < $this->getFeatureCount(); $x++) {
$this->setFeatureCount($this->getFeatureCount() - 1);
}
}
return $this->getFeatureCount();
}
}
}
Oh, and there's also the abstract class AppBuild...although I'm not 100% sure on how useful this is:
PHP Code:
abstract class AppBuild {
abstract function getFeatureInfo($previousFeature);
abstract function getFeatureCount();
abstract function setFeatureCount($new_count);
abstract function addFeature($oneFeature);
abstract function removeFeature($oneFeature);
}
The view file (stupidly dubbed "view" at the moment) is just var dumping the results so I can tell they're not empty.
Lastly, to give you guys a taste of what an actual Feature object looks like...Here is 1 of my "Feature/Object.php" files...which I've done nothing with except declare all the appropriate properties for each one...
PHP Code:
class ButtonPageFeature
{
public $typeCode = 2;
public $supportedDisplayTypes = array(
'1' => 'Home Screen',
'2' => 'Menu Item',
'5' => 'Top Content',
'6' => 'Bottom Content',
'8' => 'Inline by Position',
);
public $supportDetailDisplayTypes = array(
'0' => 'None',
'1' => 'Normal',
'2' => 'Full Screen',
);
protected $settings; // EXTEND FEATURE TO GET THESE?
protected $displayType;
protected $detailDisplayType;
protected $displayOrder;
protected $name;
protected $parentId;
protected $active;
protected $show_title; //bool
protected $default_view; // string 'list_view' or 'tile_view'
protected $list_view; // object ->settings for list view or null
protected $tile_view; // object ->settings for tile view or null
public $isComposite = TRUE;
}
I'd love to hear any thoughts on if you think I'm way off track here. I feel like I should be able to pull all the data in from the db for 1 full app, build out the features of that app and place them in the appropriate feature blocks, (possibly utilizing an object pool or repository for some of this) - figure out a nice point and click compilation of (basically) rectangles inside an phone screen mockup for the users to click on, see appropriate options, and make changes. Of course, then I'm at the point where I need to figure out how to register those events and log the changes...but that's the next chapter!
(PS: don't pay too much mind to the actual data I'm returning from the libraries...I'm just throwing a couple of the properties back so I can see that the setting and getting of them is actually working. I've basically just started on the FeatureFamily functionality...if that wasn't already obvious!)