Jump to content
  • 0

Custom Modulu: How To Process Package Config Options Names For Provisioning?


Question

Posted

Hello all,

 

I have created package config option in:

Blesta > Packages > Options > Create option

- label: CPUs

- name: myprefix_cpu

- type quantity

 

I have assigned the option to group and package.

 

In the module file I need to get value of myprefix_cpu in the function getFieldsFromInput(). The value of myprefix_cpu is mandatory for provisioning. I can't figure out how to do this.

 

What I have tried in the function getFieldsFromInput():

$fields = array(
    // ... other keys
    'cpus' => $vars['configoptions']['myprefix_cpu']
);
return $fields;

However it is incorrect.

 

Thanks for any help in advance.

4 answers to this question

Recommended Posts

  • 0
Posted

The method getFieldsFromInput is a helper method we typically use in our modules, but it is not required, so I would need to know how you're using it to determine whether the fields you're setting make sense in the context its used.

 

You can take a look at the Multicraft module for an example of how config options are set.

  • 0
Posted

Hello Tyson,

 

The goal is to get to know what value of package option has been selected by customer or by admin when adding service.

 

If I take look at the array of config options I see:

print_r($vars['configoptions']);

Array ( [6] => 1024 [8] => 2 [5] => 1 [7] => 10 ) 

I understand that the keys represent package_options.id in DB.

 

I am not expecting to get ID, but the package option name e.g. myprefix_cpu.

 

Is there some elegant way how to do this?

 

My idea is to get array from DB package_options and do array_marge with $vars['configoptions'] to have new array like:

Array ( [myprefix_ram] => 1024 [myprefix_ips] => 2 [myprefix_cpu] => 1 [myprefix_disk] => 10 )

As mentioned the config options are used for provisioning the service.

 

// Sorry for my English. I hope it is more clear now.

  • 0
Posted

$vars['configoptions'] shouldn't be keyed by an ID, but rather the Name value from your package option. You may want to take a look at how your config options are setup to see why it differs.

 

Consider the Multicraft module. When Multicraft::addService is invoked, an array of $vars is provided, and in my example, $vars contains:

Array
(
    [parent_service_id] => 
    [package_group_id] => 5
    [pricing_id] => 2
    [module_row_id] => 5
    [qty] => 1
    [client_id] => 1
    [status] => active
    [use_module] => true
    [multicraft_server_name] => Minecraft Server
    [multicraft_server_id] => 
    [multicraft_user_id] => 
    [multicraft_daemon_id] => 
    [multicraft_ip] => 
    [multicraft_port] => 
    [multicraft_players] => 6
    [multicraft_memory] => 768
    [multicraft_jarfile] => 
    [multicraft_jardir] => daemon
    [multicraft_user_jar] => 1
    [multicraft_user_name] => 1
    [multicraft_user_schedule] => 1
    [multicraft_user_ftp] => 1
    [multicraft_user_visibility] => 1
    [multicraft_default_level] => 10
    [multicraft_autostart] => 1
    [multicraft_create_ftp] => 0
    [multicraft_server_visibility] => 1
    [configoptions] => Array
        (
            [jarfile] => default
            [players] => 10
            [daemon_id] => 4
            [memory] => 256
        )

    [coupon_id] => 
    [coupon_packages] => Array
        (
            [0] => 2
        )

    [date_added] => 2014-12-10 17:25:48
    [date_renews] => 2015-01-10 17:25:48
)

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...