Jump to content
  • 0

Array To Fieldselect


Blesta Addons

Question

another time is me :)

i'm creating a module for cpanel manage2 , i have almost all done now, but i have something wrong with my code in getPackageFields(), i want to pass the outpot of array (packages) to an select box . my array is :
 

Array (
    [@attributes] => Array (
        [reason] => OK
        [status] => 1
        [version] => 0.3 )
    [packages] => Array (
        [@attributes] => Array (
            [Pxxx7] => THREE-YEAR
            [Pxxx8] => ONE-YEAR
            [Pxxx6] => FREE-ONE-YEAR-ENKOMPASS
            [Pxxx4] => TWO-YEAR
            [Pxx61] => ONE-YEAR-VPS
            [Pxx46] => xxxx-INTERNAL
            [Pxx50] => xxxx-INTERNAL-VPS
            [Pxx90] => xxxx-CLOUDLINUX-INTERNAL-WITH-CPANEL
            [Pxx94] => xxxx-CLOUDLINUX-INTERNAL-WITHOUT-CPANEL
        )
    )
)



what wrong in my code ?

 

    public function getPackageFields($vars=null) {
        Loader::loadHelpers($this, array("Html"));
        $module_row = $this->getModuleRow();
        $fields = new ModuleFields();
        
           
        $types = $this->getLicenseTypes($module_row)  ;
        $license_type = $fields->label(Language::_("CpanelManagetwo.package_fields.license_type", true), "license_type");
        $license_type->attach($fields->fieldSelect("meta[license_type]", $types['packages']['@attributes'],
            $this->Html->ifSet($vars->meta['license_type']), array('id'=>"license_type")));
        $fields->setField($license_type);

        return $fields;
    }
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

GOT IT , the full code for reference :

    public function getPackageFields($vars=null) {
        Loader::loadHelpers($this, array("Html"));
        // $module_row = $this->getModuleRow($vars->module_row);
        $fields = new ModuleFields();
            
        // Fetch all packages available for the given server or server group
        $module_row = null;
        if (isset($vars->module_group) && $vars->module_group == "") {
            if (isset($vars->module_row) && $vars->module_row > 0) {
                $module_row = $this->getModuleRow($vars->module_row);
            }
            else {
                $rows = $this->getModuleRows();
                if (isset($rows[0]))
                    $module_row = $rows[0];
                unset($rows);
            }
        }
        else {
            // Fetch the 1st server from the list of servers in the selected group
            $rows = $this->getModuleRows($vars->module_group);

            if (isset($rows[0]))
                $module_row = $rows[0];
            unset($rows);
        }            
            
        if ($module_row) {
            $types = $this->getLicenseTypes($module_row)  ;
        }            
                    
        $license_type = $fields->label(Language::_("CpanelManagetwo.package_fields.license_type", true), "license_type");
        $license_type->attach($fields->fieldSelect("meta[license_type]", $this->Html->ifSet($types['packages']['@attributes'])  ,
            $this->Html->ifSet($vars->meta['license_type']), array('id'=>"license_type")));
        $fields->setField($license_type);

        return $fields;
    }
Link to comment
Share on other sites

  • 0

i think i have get the probleme

$module_row = $this->getModuleRow();
$module_row = $this->getModuleRow($vars->module_row);

is not returning any data ?

 

how to get the getModuleRow inside the getPackageFields() function ?

 

The module row may not yet be known when selecting package fields. Most modules that need it will default to the first module row, similar to how the cPanel module currently works.

 

 

 

another time is me :)

i'm creating a module for cpanel manage2 , i have almost all done now, but i have something wrong with my code in getPackageFields(), i want to pass the outpot of array (packages) to an select box . my array is :

 

Array (
    [@attributes] => Array (
        [reason] => OK
        [status] => 1
        [version] => 0.3 )
    [packages] => Array (
        [@attributes] => Array (
            [Pxxx7] => THREE-YEAR
            [Pxxx8] => ONE-YEAR
            [Pxxx6] => FREE-ONE-YEAR-ENKOMPASS
            [Pxxx4] => TWO-YEAR
            [Pxx61] => ONE-YEAR-VPS
            [Pxx46] => xxxx-INTERNAL
            [Pxx50] => xxxx-INTERNAL-VPS
            [Pxx90] => xxxx-CLOUDLINUX-INTERNAL-WITH-CPANEL
            [Pxx94] => xxxx-CLOUDLINUX-INTERNAL-WITHOUT-CPANEL
        )
    )
)

what wrong in my code ?

 

    public function getPackageFields($vars=null) {
        Loader::loadHelpers($this, array("Html"));
        $module_row = $this->getModuleRow();
        $fields = new ModuleFields();
        
           
        $types = $this->getLicenseTypes($module_row)  ;
        $license_type = $fields->label(Language::_("CpanelManagetwo.package_fields.license_type", true), "license_type");
        $license_type->attach($fields->fieldSelect("meta[license_type]", $types['packages']['@attributes'],
            $this->Html->ifSet($vars->meta['license_type']), array('id'=>"license_type")));
        $fields->setField($license_type);

        return $fields;
    }

 

What is the output? $types['packages']['@attributes'] should be fine as long as that is an array of key/value pairs.

Link to comment
Share on other sites

  • 0

the probleme is not the code , the probleme is from the getModuleRow()

 

this one is also not working

        // Fetch all packages available for the given server or server group
        $module_row = null;
        if (isset($vars->module_group) && $vars->module_group == "") {
            if (isset($vars->module_row) && $vars->module_row > 0) {
                $module_row = $this->getModuleRow($vars->module_row);
            }
            else {
                $rows = $this->getModuleRows();
                if (isset($rows[0]))
                    $module_row = $rows[0];
                unset($rows);
            }
        }
        else {
            // Fetch the 1st server from the list of servers in the selected group
            $rows = $this->getModuleRows($vars->module_group);

            if (isset($rows[0]))
                $module_row = $rows[0];
            unset($rows);
        }            
            
            
        $types = $this->getLicenseTypes($module_row)  ;

i have tried the same code as cpanel but is not working , how i can see the output of the getModuleRow() ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...