actionAttributes attribute type

Discuss about Group-Office development here

Moderator: Developers

jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

actionAttributes attribute type

Postby jamesarthur » Fri Dec 06, 2013 3:26 pm

Hey

When getting the attributes for a model using actionAttributes, it would be useful to know what data type the attribute is - so that in the query builder you could restrict the comparison operators. For example to exclude >= from the 'city' field in a contact.

At the moment I extend the contract controller and put this info in using the afterAttributes method.
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: actionAttributes attribute type

Postby mschering » Tue Dec 10, 2013 7:58 am

Could you share the code?
Best regards,

Merijn Schering
Intermesh
jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

Re: actionAttributes attribute type

Postby jamesarthur » Wed Dec 18, 2013 10:54 am

Hi

I have the following code in a subclass of the contact controller:

Code: Select all

protected function afterAttributes(&$attributes, &$response, &$params, GO_Base_Db_ActiveRecord $model) {
    $ret = parent::afterAttributes($attributes, $response, $params, $model);
    
    if(!$this->_cf_fields) {
        $records = GO_Customfields_Model_Field::model()->find()->fetchAll();
        foreach($records as $record) {
            $this->_cf_fields[$record->id] = $record;
        }
    }
    
    foreach($attributes as &$attr) {
        if(isset($attr['gotype'])) {
            switch($attr['gotype']) {
                
                case 'customfield':
                    preg_match('col_(\d+)', $attr['name'], $col_id);
                    $cf_name = $this->_cf_fields[$col_id[0]]['datatype'];
                    switch($cf_name) {
                        
                        case 'GO_Customfields_Customfieldtype_Number':
                        case 'GO_Customfields_Customfieldtype_Function':
                            $attr['compType'] = 'number';
                            break;
                        
                        case 'GO_Customfields_Customfieldtype_Checkbox':
                            $attr['compType'] = 'boolean';
                            break;
                            
                        
                        case 'GO_Customfields_Customfieldtype_Date':
                            $attr['compType'] = 'date';
                            break;
                        
                        case 'GO_Customfields_Customfieldtype_Datetime':
                            $attr['compType'] = 'datetime';
                            break;
                            
                        case 'GO_Customfields_Customfieldtype_EncryptedText':
                        case 'GO_Customfields_Customfieldtype_Heading':
                        case 'GO_Customfields_Customfieldtype_Infotext':
                        case 'GO_Customfields_Customfieldtype_Html':
                            unset($attr);
                            break;
                                                    
                        
                        case 'GO_Customfields_Customfieldtype_Select':
                        case 'GO_Customfields_Customfieldtype_Textarea':
                        case 'GO_Customfields_Customfieldtype_Text':
                        case 'GO_Customfields_Customfieldtype_Treeselect':
                        case 'GO_Customfields_Customfieldtype_TreeselectSlave':
                        case 'GO_Customfields_Customfieldtype_User':
                        default:
                            $attr['compType'] = 'text';
                            break;
                        
                    }
                    break;
                
                case 'number':
                case 'unixtimestamp':
                case 'date':
                    $attr['compType'] = $attr['gotype'];
                    break;
        
                case 'textfield':
                case 'textarea':
                default:
                    $attr['compType'] = 'textfield';
                    break;
        
            }
        } else {
            unset($attr);
        }
    }
    return $ret;
}
 
NB the bit with the custom fields doesn't work because currently afterAttributes is called before the customfields are added.

Who is online

Users browsing this forum: No registered users and 1 guest

cron