Customizing vTiger custom views with dynamic “variables” – II

A quick follow up to my previous post Customizing vTiger custom views with dynamic “variables” . There is an easy extension to enable multiple variables to be used in the custom views.

This is the code:

        /* Associative array with list of replacement pairs */
        $dvReplacements = array(
                "yourstring" => $variable,
               //
        );
        /* Replace each of the variables */
        foreach ($dvReplacements as $dvKey=>$dvValue) {
            if (strstr($advfsql,$dvKey))
            {
                $advfsql = str_replace ($dvKey, $dvValue, $advfsql );
            }
        }

For example, say I want to replace the variables SP_CURRENTNAME and SP_TODAY with the username of the logged in user and today’s date, respectively. The code is as follows (I am using “2099-12-31″ as the replacement key, since for dates, vTiger requires you to enter them in date format. So, if I want a custom view to check against today’s date, I enter this value in the date field.)


$dvReplacements = array(
            "CURRENTUSER" => $current_user->user_name,
            "2099-12-31" => date("Y-m-d")
        );
        foreach ($dvReplacements as $dvKey=>$dvValue) {
            if (strstr($advfsql,$dvKey))
            {
                $advfsql = str_replace ($dvKey, $dvValue, $advfsql );
            }
        }

No comments yet

Leave a reply