moving data from one module to another

blindmime
@blindmime
10 years ago
772 posts
I have a custom aparna-generated module which consists of a long bid form. My customer fills this in when bidding a project. When the project is approved, each approved item in the form then becomes a task in another custom module.

Currently they are filling the tasks in manually week to week. I would like to automate this by moving the data from the fields in the bid module over to task module, keeping the bid form. There are additional things to set up to facilitate this for the client, such as they want the bid module data displayed in tab or cascading menus together with the task data. Each bid item is organized into categories (tabs) with a button to click to enter it as a task.

This is beyond my jamroom comfort zone, but maybe if I had something similar to look at, at least in terms of moving data from one module to the other, I could possibly figure it out. Barring that I could pay someone to at least get me started or even do the smart work depending on the cost.

Let me know your thoughts, please.

updated by @blindmime: 04/12/15 05:30:26AM
brian
@brian
10 years ago
10,149 posts
There's no functionality built into JR that's going to help you here, nor are we doing anything like that in any module.

However, all you would really need to do is get the item from the one DS, then rewrite the keys so the prefix is correct for the new DS, and enter it.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
10 years ago
772 posts
Can I pay someone to show me how to do this?
michael
@michael
10 years ago
7,800 posts
First figure out how you want to move them. If you want to move them by you visiting a url, then you want a new view in the index file of your module.


eg:
function view_xxYourModule_somewhere($_post, $_user, $_conf)
{
fires when you visit the url
your-site.com/yourmodule/somewhere

If you want to fire the module once a day then use events and listeners to fire the module's function off when 'daily_maintenance' fires.

To do that, add the name of the function you want to fire into your modules _init() function, eg:

jrCore_register_event_listener('jrCore', 'daily_maintenance', 'jrPanel_daily_maintenance_listener');

is in the include.php file for the jrPanel module and it fires jrPanel_daily_maintenance_listener() once a day.

The next thing you need to do is to get the datastore items your interested in, so need to know which those are, then search for them.

To look for examples of searching for stuff inside a function search for '$_sp =' and that will show you other locations where modules are searching for stuff. It looks like this:
    $_sp = array(
        'search'   => array(
            "guestbook_owner_id = " . intval($_post['profile_id'])
        ),
        'order_by' => array(
            '_created' => 'DESC'
        ),
        'limit'    => 250
    );
    $_rt = jrCore_db_search_items('jrGuestBook', $_sp);
( example above ^ came from jrGuestBook )
That will give you all the found items inside $_rt['_items'] so then check that the array exists to make sure you have items, then itterate over them but change the prefix.

so:
if (isset($_rt) && is_array($_rt['_items'])) {
  $pfx = jrCore_db_get_prefix('xxDestinationModule'); //replace destination module with where you want to put the new info.
  foreach($_rt['_items'] as $item){
    $_sv[] = array(
    $pfx.'_title' = $item['whatever_title'],
    $pfx.'_description' = $item['whatever_description']
    ); // continue on with that with the fields your after.
  }
}

Then you have an array of items to either be created or updated. I think your after creating, so
jrCore_db_create_multiple_items('xxDestinationModule', $_sv);
should get the new stuff saved in the wanted datastore.

Tags