Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

[eluser]wandschrank[/eluser]
Hello DMZ-Users,
i have made a quick/small checkbox-multicolumn hack for the "htmlform"-extension.

Code:
$form_fields = array(
                'id',
                'tag' => array(
                    'input_separator' => '',
                    'checkbox_cols' => 3
                )
            );

'checkbox_cols' is the new feature.

The changes in the htmlforms.php are in the _checkbox function:

Code:
// renders one or more checkboxes or radio buttons
function _checkbox($type, $id, $value, $options, $sub_id = '', $label = '')
{
    if(isset($options['value']))
    {
        $value = $options['value'];
        unset($options['value']);
    }
    // if there is a list in options, render our multiple checkboxes.
    if(isset($options['list']))
    {
        $list = $options['list'];
        unset($options['list']);
        $ret = '';
        if( ! is_array($value))
        {
            if(is_null($value) || $value === FALSE || $value === '')
            {
                $value = array();
            }
            else
            {
                $value = array($value);
            }
        }

        $sep = '<br/>';
        if(isset($options['input_separator']))
        {
            $sep = $options['input_separator'];
            unset($options['input_separator']);
        }

        $col = 0; // Standard 1 Column
        if(isset($options['checkbox_cols']))
        {
            $col = $options['checkbox_cols']-1;
            unset($options['checkbox_cols']);
        }

        $num = 0;
        foreach($list as $k => $v)
        {
            if( ! empty($ret))
            {
                // put each node on one line.
                $ret .= $sep;
            }

            if($col!=0){
                if($num==0){
                    $ret .= '<tr><td>'.$this->_checkbox($type, $id, $value, $options, $k, $v).'</td>';
                    $num++;
                }elseif ($num%$col == 0){
                    $ret .= '<td>'.$this->_checkbox($type, $id, $value, $options, $k, $v).'</td></tr>';
                    $num=0;
                }else {
                    $ret .= '<td>'.$this->_checkbox($type, $id, $value, $options, $k, $v).'</td>';
                    $num++;
                }
            }else{
                $ret .= $this->_checkbox($type, $id, $value, $options, $k, $v);
            }

        }
        return '<table class="cb">'.$ret.'</table>';
    }
    else
    {
        // just render the single checkbox.
        $node_id = $id;
        if( ! empty($sub_id))
        {
            // there are multiple nodes with this id, append the sub_id
            $node_id .= '_' . $sub_id;
            $field_value = $sub_id;
        }
        else
        {
            // sub_id is the same as the node's id
            $sub_id = $id;
            $field_value = '1';
        }
        $name = $id;
        if(is_array($value))
        {
            // allow for multiple results
            $name .= '[]';
        }

        // node attributes
        $a = $options + array(
            'type' => $type,
            'id' => $node_id,
            'name' => $name,
            'value' => $field_value
        );
        // if checked wasn't overridden
        if( ! isset($a['checked']))
        {
            // determine if this is a multiple checkbox or not.
            $checked = $value;
            if(is_array($checked))
            {
                $checked = in_array($sub_id, $value);
            }
            if($checked)
            {
                $a['checked'] = 'checked';
            }
        }
        $ret = $this->_render_node('input', $a);
        if( ! empty($label))
        {
            $ret .= ' ' . $this->_render_node('label', array('for' => $node_id), $label);
        }
        return $ret;
    }
}

Greetings

[eluser]Alface[/eluser]
Can anyone take a look on my unanswered question? it is here http://ellislab.com/forums/viewreply/695462/

[eluser]Wazzu[/eluser]
Delete several rows

I want to delete all students wich are 17 years old.
I can't get it with this simple code. It just deletes one by one, instead of deleting all rows. What's wrong?

Code:
//Set age
$age = 17;

// Get student
$u = new Student();
$u->where('age', $age)->get();

// Delete user
$u->delete();

[eluser]OverZealous[/eluser]
Wazzu
Delete only acts on the top-level item. Search the manual for delete_all - this is what you need.

[eluser]Wazzu[/eluser]
Ok, I see it clearly: http://www.overzealous.com/dmz/pages/deleteall.html
Thanks very much

[eluser]Wazzu[/eluser]
Advanced Relationship

Hi all. I'm not able to understand how advanced relationships work.
I've read user guide and made tests, but I can't understand how field names are used.

This is my sample case:
- table users(id, name)
- table quotes(id, client_id, worker_id)
- user model and quote model

One user (worker_id) can create a new quote for other user (client_id).
'worker_id' and 'client_id' are in fact ids from users table.

How should I make relationships? This is what I've done:

Code:
class Quote extends DataMapper {
  var $has_many = array(
        'client_id' => array('class' => 'user','other_field' => 'client'),
        'worker_id' => array('class' => 'user','other_field' => 'worker')
  );
}

Code:
class User extends DataMapper {
  var $has_one = array(
    'client' => array('class' => 'quote', 'other_field' => 'client_id'),
    'worker' => array('class' => 'quote', 'other_field' => 'worker_id')
  );
}

Is that right? And from my controller, how should I populate this? I want to get something like this:

Code:
&lt;?php
$q = new Quote($id);

$q->client->get();
echo $q->client->name;

$q->worker->get();
echo $q->worker->name;
?&gt;

Please, help me understanding this relationships.
Thanks all

[eluser]OverZealous[/eluser]
@Wazzu

Please post in the new forum. DMZ 1.6 has been deprecated for a while now.

You are more likely to get answers there.

[eluser]Wazzu[/eluser]
Thanks, Phil.
I posted here because of the version I use.
I'll post there anyway.

[eluser]7amza[/eluser]
sorry i posted it here the reply is here
http://ellislab.com/forums/viewthread/14...80/#789462




Theme © iAndrew 2016 - Forum software by © MyBB