Give the site admin the ability to replace Yahoo symbols with more friendly ones

henns20 - May 26, 2009 - 00:02
Project:Stock
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Being new to coding and adding anything to modules was looking for some feedback and guidance...if this is not the place to put this- let me know where

The feature

A place in the stock form to customize the display names of stock/indices symbols to become more visitor friendly. IE... Yahoo Finance uses ^IXIC for NASDAQ. Most people would not recognize that ^IXIC. The better display for visitors is NASDAQ. See picture 227 below to get visual.

How to implement.

I am able to get this result by hacking the module with a str_replace function see this but I want to make it more drupal like in the implementation and be able to change it on front end.

Was thinking the following

- Create a field called something like "Symbols' Display Customization" in 2 places underneath the: 1. Stocks Block Default Field (located on the stock settings page) and Stock Symbol(s): (located on the stocks page).
Please see picture 226 blow to get visual.

I tried doing this for test purposes. Here is my code using case 'block' and using block default symbols for an example

//add form field   

$form['stock_customized_symbols'] = array(
    '#type' => 'textfield',
    '#title' => t('Customized Display Symbols'),
    '#default_value' => variable_get('stock_customized_symbols', ''),
    '#size' => 40,
    '#maxlength' => 255,
    '#description' => t('This is where you put the custom symbols'),
    );
....

// USING THE NEW FORM FIELD


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

  switch ($format) {
    case 'block':
      if ( $user->uid ) {
        // get the stored tickers
        $symbols = stock_get_user_quotes();
        if (!isset($symbols) || strlen($symbols) == 0) {
          $symbols = variable_get('stock_block_default_symbols', '');
        }

//Here Starts of My altering of Code************

        // get the quotes
        $output1 = stock_do_quote('short', $symbols);
       
        $custsymbols = variable_get('stock_customized_symbols', '');
        $output = str_replace($symbols, $mysym, $output1);
      }
      else {
        $symbols = variable_get('stock_block_default_symbols', '');
        if (strlen($symbols) > 0) {


//Here Starts of My altering of Code************

        $output1 = stock_do_quote('short', $symbols);
       
        $custsymbols = variable_get('stock_customized_symbols', '');
        $output = str_replace($symbols, $custsym, $output1);
        }
       
        else {
          $output = l('Login', 'user/login') .' or '. l('register', 'user/register') .' for portfolio.';
        }
      }
      break;

This is not working form me... also I am confused on a couple of things.

-How does Drupal Validate the input on this new field and the Existing Stock Quote field as I see no validating of the info.

-How can I create the feature the most efficient way for the user. For example... the way I am going about this right now. If user is getting quotes for say ^DJI YHOO ^IXIC and wants it to display DOW YHOO NASDAQ (No change to the third symbol)...they would have to enter all three in the customization field. Ss there an easy way for the only to have to enter the ones they need to customize?

Still thinking:)...

Jamie

AttachmentSize
Picture 226.png21.72 KB
Picture 227.png89.29 KB

#1

henns20 - May 26, 2009 - 00:33

I adding this to simplify my idea of the feature and questions I have...this is meant to help me as well:)

1. Add form field that allows you to change display names of stock symbols to the end user/vistor. Something titled like Customize How Stock/Indices Display : IE. ^IXIC to NASDAQ

2.Validate that form field so..
- to make sure there is a space between each of the custom display names
- no foreign, nonsensical, or foreign input
- to make ability to use short hand symbol such as # if the display name of one of the symbols should be the same as Yahoo Finances. IE ^DJI YHOO ^IXIC -> DOW # NASDAQ (# = use YHOO)

3. How does DRUPAL know how to take the one line input field of symbols and create an array

4. Take New form fields content and use it to replace the 'stock_block_default_symbols' & $symbols

5. Create Valid Patch for testing

#2

kbahey - May 26, 2009 - 01:54
Title:Want to add a feature to the module as a patch to be considered to become part of module....» Give the site admin the ability to replace Yahoo symbols with more friendly ones
Status:active» needs work

Please do not open new issues while existing ones are there. You could have added this to the issue you opened a few days ago, instead of creating a new one. I marked the other one as duplicate.

Anyway, I like this idea, and will accept a patch for it.

However, the user interface has to be simpler.

Maybe a text area, with "source target" pairs, separated by spaces, like this:

[foo bar      ]
[blah baz     ]
[             ]
[             ]
[             ]

This is easier than having one page per pair.

For an example on how to do this, look in the function customerror_check_redirect() in the customerror module.
Maybe investigate the token module as a way to change symbols?

#3

henns20 - June 3, 2009 - 12:47

@kbahey As far as opening another issue - sorry if i did that incorrectly...I changed the status to fixed and started this because I thought it was a new approach...next time I will continue with the one issue and evolve it.

I am game to give it a go.... I did some preliminary work...after looking at your function customerror_check_redirect()...I'll look to post something towards that in a within the week where i could get it...

jamie

#4

visualnotion - September 17, 2009 - 15:37

I'd love to have the ability to show user-friendly stock names as well. Most people don't know what the abbreviations stand for.

Has this been added to the dev release?

 
 

Drupal is a registered trademark of Dries Buytaert.