Welcome Guest, Not a member yet? Register   Sign In
Looking for suggestions/help - a Todo App using CI2 and Datamapper ORM
#1

[eluser]matula[/eluser]
I'm a lone developer on a current project, and miss having others to bounce ideas off of and get suggestions, so I thought I'd throw this out there to see if anyone can offer some direction to problems I'm trying to wrap my brain around.

The project is essentially a Todo list, where a Customer needs to create a "widget". To create the widget, they must follow a predetermined list of steps, in order. There are actually 3 main steps, with multiple sub-steps... and some of those sub-steps also have sub-steps.

My first problem is how to setup the db tables. Right now, I'm working with a Customers table and a Widgets table (since the Customer can have multiple Widgets) and a Steps table. I've also created a widgets_steps table as a join table.
The tables are currently setup like this:
Quote:Customers: id(INT), name(VARCHAR255)
Widgets: id(INT), name(VARCHAR255), created(DATETIME), updated(DATETIME), customer_id(INT)
Steps: id(INT), step(VARCHAR255), order(INT),parentstep_id(INT)


In my models, I have this set up:
Code:
//customer.php
$has_many = array('widget');
//widget.php
$has_one = array('customer');
$has_many = array('step');
//step.php
$has_many = array('widget');

The three main steps have a parentstep_id = 0, and I'm able to print out all the steps like this:
Code:
$s = new Step();
$s->where('parentstep_id',0)->order_by('order')->get();
foreach($s as $step){
    echo "<h2>" . $step->step . "</h2>";
    $s2 = new Step();
    $s2->where('parentstep_id',$step->id)->order_by('order')->get();
    foreach($s2 as $sub1) {
    echo "<b>"  . $sub->step . "</b>";
    $s3 = new Step();
    $s3->where('parentstep_id',$sub1->id)->order_by('order')->get();
    foreach($s3 as $sub2) {
        echo "...." . $sub2->step . "<br/>";
    }
    }
}
This works, but it's messy and makes to many calls to the db. I know Doctrine has a Tree Relationship that can be set... but does Datamapper have anything similar? Or a work around? I've been toying around with adding a "level" field to the Steps table, so I know which level in the tree each Step is, but I don't know...

Also, I'm open to the possibility that I'm going about this total wrong way. Either way, here are my goals:
1. Customer creates a new Widget.
2. Customer is displayed the list of Steps needed for the Widget. Initially, everything is unchecked.
3. As Customer completes the Steps, they check off the Step.
4. If all sub-Steps are completed, the Parent Step is automatically checked. Conversely, if they uncheck a sub-Step where all sub-Steps had been completed, the Parent Step is unchecked as well.
5. Each Step must be completed in order, so the Customer can not check off a Step that is further down the list.
6. The Customer should be displayed a dashboard page, where all their Widgets are displayed, and the next Step they need to complete is shown next to it.
7. Finally, another big problem that I'm not able to get clear on, is creating an Admin page where a non-programmer type can go in and add/edit/delete Steps... and reorder them... and put them in the correct place, as far as what is their parent Step and sub-Steps.

Ideally, all this will be jQuery-ized... but I can get that working once I've got the basic structure of the app down.

Sorry for the rambling... but like I said, I'm a lone code slinger with no one to bounce ideas off of. If anyone has any ideas/ direction/ other code to check out/ snarky remarks/ whatever, I'd would totally be in your debt.

Thanks!
-Terry
#2

[eluser]WanWizard[/eluser]
If you're building a tree structure, you could check the new nested sets extension (https://bitbucket.org/wanwizard/datamapper/get/tip.zip) in the pre 1.8.0 code.
Not completely finished yet, but as long as you don't need symlinking it should work without problems.




Theme © iAndrew 2016 - Forum software by © MyBB