I have added the "Stock" module to my new Drupal site. Once setup, I noticed I could add a number of ticker symbols through the initial form interface but every subsequent time I returned to that form to add or remove symbols the previously added symbols were not read from the DB into the form for me to edit. I would essentially have to completely re-enter ALL the symbols from scratch every time.

I came up with some code modifications for "stock.module" that correct this issue.

These changes are all located within the the "stock_contents" function in the file "stock.module". See code snippet below:

I'm new to Drupal and not an expert web developer - if the changes I made below are unclear - please drop me a line.

function stock_contents( $format = 'block')
{
 global $user;

 switch ($format) {
 case 'block':
 	if ( $user->uid ) {
		// get the stored tickers
		$symbols = stock_get_user_quotes();

		// get the quotes
		$output = stock_do_quote ( 'short', $symbols );

		// format it

		// display
	}
	else {
    $output = l('login', 'user/login') . ' or ' . l('register', 'user/register') . ' for portfolio';
	}

	break;

 case 'page':
	$edit = $_POST['edit'];

	// The following 1 line commented out by SLACK1661 06/01/05
	//$symbols = strtoupper($edit['symbol']);

	// The following 2 lines added by SLACK1661 06/01/05
	$symbols = strtoupper(stock_get_user_quotes());
	$symbols_to_save = strtoupper($edit['symbol']);

	if (isset($_POST['button_quote'])) {
		// Query for the symbols
		$output .= stock_do_quote ( 'long', $symbols );
	}
	else
	{ // If the user pressed the Save button, save their preferences
		if (isset($_POST['button_save']) && $user->uid ) {
			// Save the user symbols 
			
			// The following 1 line commented out by SLACK1661 06/01/05
			// stock_save_user_quotes ( $symbols );
			
			// The following 2 lines added by SLACK1661 06/01/05
			stock_save_user_quotes ( $symbols_to_save );
			$symbols = $symbols_to_save;
		}
	}

  $output = variable_get("stock_description", "This is the stock quote page.");

	if ( $symbols ) {
		$output .= stock_do_quote ( 'long', $symbols );
	}

	$output .= stock_form( $symbols );

	break;
 }

 return $output ;
}

Comments

kbahey’s picture

Assigned: Unassigned » kbahey

Good catch. Fixed.

Anonymous’s picture