Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
@Alface

It's in the manual. There are 3 ways:

You can set an error using error_message, and not returning anything. (If there are any errors after validating, then the validation has failed.)

Alternatively, you can return a custom string from the validation. Any string value returned is assumed to be an error.

Finally, you can return FALSE, and DMZ will automatically look up the error from a language line based on the name of the validation rule.

Again, these are all explained exactly like this in the manual!

[eluser]PoetaWD[/eluser]
Hello Phil,

After looking this for almost a week I decided to use DATATABLES as my grid plugin.

It is not as heavy as jqGrid and has a great example page... Also, the main advantage I found is that it does not create a complex container structure in the DOM. Using FIREBUG you can see that most of the grid uses <div> inside <div> + <table> + etc. Datatables only uses a <table></table>.

It is not very well documented, but using FIREBUG I was able to see the post requests and the results sent from the server, and that is just GREAT because this way I am REALLY learning the concepts of AJAX, JSON, etc...

This plugin has a search filter that I found very interesting... the question I have is regarding this. (Already found a solution... at the end of the post).

The plugin send a $POST to the server with the value the user want to search.

In my object query I will use the like() method to find the objects that have that value in its data.

The problem is that I can only check one of its column at a time using the like()...

Code:
$obj = new Datatable();
        
        //Check if a post with search data exists
        if($this->input->post('sSearch'))
        {
            $obj->like('engine', $this->input->post('sSearch'));
            $obj->or_like('browser', $this->input->post('sSearch'));
            $obj->or_like('platform', $this->input->post('sSearch'));
            $obj->or_like('version', $this->input->post('sSearch'));
            $obj->or_like('grade', $this->input->post('sSearch'));
        }        
        
        //Execute the query
        $obj->get();

Is there a better way to perform this search ?

EDIT: Just found a solution myself. I created a array with the columns of the table and made a foreach loop. I had to do this because of the next feature of datatables, witch is sorting multiple columns.

Code:
$columns = array('engine','browser','platform','version','grade');

if($this->input->post('sSearch'))
        {
            
            foreach($columns as $position => $column)
            {
                
                if($position == 0)
                {
                    $obj->like($column, $this->input->post('sSearch'));
                }
                else
                {
                    $obj->or_like($column, $this->input->post('sSearch'));
                }
            }
        }

Thanks,

Gabriel

[eluser]OverZealous[/eluser]
@Poetawd
One tip: make sure you wrap your likes in a group, or the logic may return unexpected results. What you have there logically is this:
Code:
// Generated query
WHERE something
    AND col1 LIKE '%val%'
    OR col2 LIKE '%val%'

Which is actually interpreted as this, due to operator precedence:
Code:
// Most likely incorrect
WHERE (something AND col1 LIKE '%val%')
    OR col2 LIKE '%val%'

Also, once you wrap it, you can just or all of the results, without the $position check. This is because DMZ automatically drops the first operator when grouping items to prevent errors.
Code:
$columns = array('engine','browser','platform','version','grade');

if($this->input->post('sSearch'))
        {
            $obj->group_start();
            
            foreach($columns as $column)
            {
                $obj->or_like($column, $this->input->post('sSearch'));
            }

            $obj->group_end();
        }

:-)

[eluser]PoetaWD[/eluser]
@phil : Thanks for the TIP! It works perfectly!

It is 16:00 and I just woke up! I went to bed 8:00 am, I spent the whole night studying the concepts of AJAX and the grid.

After that I´ve made a code to generate the grid data automatically, all you need to pass is the name of the object and a array with the columns name.

Today I found up that I can pass the object name and the columns array as $POST using the javascript.

Right now I am translating my code (All the comments are in portuguese)...

After that I will post it here... I think it can help other people like me.

Maybe It is a good idea to make a plugin with that code... what do you think?

[eluser]PoetaWD[/eluser]
Its Done !

Please take a minute of yout time to look at this:

http://www.spassus.net/cidatatables/

A Data Grid getting json data DIRECT from database without any other CODING!

All you need to do is specify in your Datatable initialization the table(Datamapper Object) from your database and the columns you want to show!

Here is the controller:

http://spassus.net/cidatatables/datatable.zip (Too big to post here)

or in PasteBin:

http://pastebin.com/rnATM6Kh

@PHIL: This is thanks to you man! I hope that it shows you that I am learning how to script and how great teacher you are! Also, I hope you see that I learned my lesson about that incident we had... If I were you I would be DAMN proud of what I done with DMZ and all the effort you give to this comunnitie!

I am just learning PHP and JAVASCRIPT.. if you have ANY suggestion to improve this code please tell me!

BTW: Just try holding down the SHIFT key to SORT multiple columns!

[eluser]OverZealous[/eluser]
@Poetawd
That looks great! Your example works really well.

One thing you might need to tweak is that it is reporting the incorrect number of rows (it shows the number of visible rows, instead of the total number of rows). See the bottom left where it says "out of XXX unfiltered rows".

Make sure you add it to the wiki category! :-)

Edit: Well, it's not really an extension, so if you decide to convert it into an extension, then you can add it to the above! ;-)

(Note: it seems like this would be pretty easy to convert into an extension.)

[eluser]PoetaWD[/eluser]
[quote author="OverZealous" date="1270440849"]@Poetawd
That looks great! Your example works really well.
[/quote]

Its not really a extesion YET... just a example controller... I will improve it more and I will sure make a extension out of it!

I will also re-check the JSON being output.

It really means A LOT for me you saying that my example looks good...

My plans for the extension:

#1 - Automatically add the GRID in the view file (JavaScrits and HTML markups).
Example: The user would just need to do like this:
Code:
&lt;?php echo $obj->grid_generate() ?&gt;

#2 - The user would specify what columns he wants in the grid passing a array
Example:
Code:
$obj->grid_columns(array('engine' => 'Rendering Engine','browser' => 'Browser','platform' => 'Platform(s)','version' => 'Engine Version'));

#3 - He would also be able to add a column to the existing column array using this method:
Example:
Code:
$obj->grid_add_columns('grade', 'CSS Grade');
The user would also be able to send a array.

#4 - Add custom column DATA. The user might want to add data that is not acctually in that object table, something like a property from a related object;
Example:
Code:
$obj->grid_add_related_column('developer','name','Developer Name')
Example:
Code:
$obj->grid_add_custom_column('SOMETHING')

#5 - Add support for other grids like: jqGrid, extjs Grid, dijit Grid...
Example:
Code:
$obj->set_grid_type('dijit');


I think that would make a good extension... what do you think ? Any other Ideas? Do you think that it would be WASTE of my time?

EDIT: I dont really know how to do it, I would have to study some dmz examples to do it.. and, of course, get some help from you. Tongue

Thanks

[eluser]TheJim[/eluser]
@OverZealous

Hey, Phil, related to an ITFK issue I had mentioned a while back and got a fix in for, I forgot to make sure this part of the fix made it into DMZ:

Code:
DMZ 1.7.1 Line 1786

if(isset($this->has_one[$rf]) && in_array($other_column, $this->fields))
{
    if($this->{$other_column} != $o->id)
    {
        // ITFK: store on the table
        $this->{$other_column} = $o->id;

        // unset, so that it doesn't get re-saved later.
        unset($objects[$index]);

        // Remove reverse relationships for one-to-ones
        $this->_remove_other_one_to_one($rf, $o);
    }
}

If the ITFK field doesn't have to be changed, then the object in the list isn't unset. I propose:

Code:
if(isset($this->has_one[$rf]) && in_array($other_column, $this->fields))
{
    // unset, so that it doesn't get re-saved later.
    unset($objects[$index]);

    if($this->{$other_column} != $o->id)
    {
        // ITFK: store on the table
        $this->{$other_column} = $o->id;

        // Remove reverse relationships for one-to-ones
        $this->_remove_other_one_to_one($rf, $o);
    }
}

This is a bit obscure and probably doesn't affect many people, and in general I believe all it means is an extra call to the save function when _save_relation comes across the object. What exposed it for me is some extra functionality added to an inherited save function that actually ended up crashing the page load with some infinite recursion in this particular circumstance. So, undoubtedly most people wouldn't see much of a negative effect, but I think it's the "more correct" way to just remove it in _save_itfk.

Thanks,

Jim

[eluser]OverZealous[/eluser]
@TheJim

That's another great find. I'll try to remember it when I next get around to working on DMZ. Right now, I'm in crazy-what-am-I-doing-here-I-need-to-pack mode for this job.

Oh, and to make sure that my stress levels are at an all-time high, the netbook I was planning on using for my interim computer while away from home decided to die today. Now I have to see if Dell can overnight a replacement SSD, and that I can get it re-setup before I leave Friday morning.

Code:
if($weather_type == RAIN) {
    $weather_amount = POUR;
}

Smile

[eluser]TheJim[/eluser]
It can't ever be simple, can it? Anyway, good luck with the new job, the move, and sorting out everything that comes along with that.




Theme © iAndrew 2016 - Forum software by © MyBB