?

Log in

No account? Create an account
entries friends calendar profile adric.net Previous Previous Next Next
In lieu of an update - nil.enroll(aetheric_username, quantum_class_id)
yljatlhQo'! QIch lo'laltbebej!
adric
adric
In lieu of an update
Some more Rails code. This is the third try at describing the logic flow for order processing
for this project, and then trying to make it work.


#!/usr/bin/env ../script/runner

## third try on the order processing logic, started in pseudocode

## cache existing moodle users
moodle_users = User.all

## Run through Orders,lineitems, creating MoocashOrderProcessing 
##   where not found so we have is_processed? fields 
Order.all do |o|
    o.ordersproducts.all do |op|
      ## if there is not already a MoocashOrderProcessing line for this lineitem 
      if not MoocashOrderProcessing.find_by_orders_products_id(op.orders_products_id)
        ## make one
        MoocashOrderProcessing.new(op).save
      end
    end
  end

## For every line item not marked as processed 
MoocashOrderProcessing.find_by_processed(0) do |mop|
  ## if lineitem's product type is 'training'
  if lineitem.product.master_category_id == '1'

    ## FAKE: get class_id from lineitem.products_id => class_id
    quantum_class_id = '1'
    
    ## FAKE: get username from Order.orderstatushistory.comments REGEX ~= USERNAME:$username
    aetheric_username='jsmith'
    
    ## if we're given an existing Moodle user, set it up for enroll in new class_id
    if moodle_users.include? aetheric_username
      ## FAKE: enroll(aetheric_username, quantum_class_id)
      ## lineitem.processed = 1
      p 'Moocash : order processing : debug : username given: #{aetheric_username}'

    ## More likely create a new entry in the view so Moodle will add a new
    ## => user and enroll it.  
    else
      ## New MoocashOrder, pass the Order by id
      moop = MoocashOrder.new lineitem.order
      ## ask the MoocashOrder to enroll
      moop.enroll quantum_class_id
      ## if writing to DB does not fail spectacularly ...
      moop.save
      ## mark it done
      lineitem.processed = 1
    end
  end
end


I'd really like to burble about all of the sleep disturbances and work drama but this is all you get today. I'm so behind from last week that the work day is already over, and I'm to dinner.

*waves*

Tags:
Current Mood: *poof*

2 comments or Leave a comment
Comments
neleh_yam From: neleh_yam Date: December 4th, 2008 01:03 pm (UTC) (Link)
I see your busy too. You might have picked up from my lack of many posts that I've been pretty flat out. But I haven't forgotten you. I will write the email to you. It just might be awhile. So sorry about that. I suck at being a pen friend obviously.
adric From: adric Date: December 4th, 2008 09:35 pm (UTC) (Link)

Okay, honey

It's quite allright, but thank you for checking in.
2 comments or Leave a comment