Developing New Paths

The Mojavi Project

Archive for August, 2009

August-27-09

Advanced shopping engine

posted by admin

searchThe search engine battlefield has gotten more interesting this summer as Bing has launched a massive ad campaign to lure site traffic and searches from google. The reports are that they have invested over $100 million in advertising to help create brand awareness and help people understand there is a new more targeted way to search for everyday items like Xbox 360. The traditional searches that most people use have been more broad based approaches although you can narrow down your search results if you know the correct format in which to search from. With this focus on more targeted searching consumers will now be able to enjoy better information on the exact items that they will search for.

This is why I was interested in shopwiki.com where they provide search results based solely on stores that are on the internet that may be selling the specific items that you are looking for. Take for example, you are searching for Madden 10 for the Xbox 360, you search on shopwiki.com and locate the top stores that sell this game along with a quick price comparison that you can see and compare. This provides the consumer the ultimate tool in cost comparison right in one location without having to search through each individual store.The ability to search for and gather both location and costs for the items you are looking for can make holiday shopping much easier. So why not give your mouse a rest and try a more targeted search for those hot Christmas items like new Xbox 360 elite system and find some of the best deals online in a matter of seconds.

Reblog this post [with Zemanta]
August-26-09

Global template

posted by admin

Component Driven Global Template System

PLEASE NOTE: the approach explained below has a few drawbacks, mainly that the execute method of action always need to be executed for the output to appear in a template. I’ve decided to use a different solution to the problem. We will be incorporating online surveys as new versions are created in order to keep the development community engaged in the entire process.

Like many of us I’ve been struggling with a global template approach to Mojavi 2.0 site development for a while. Most of the suggested solutions in the forum still require a fair bit of code duplication, so I tried to come up with my own idea.

I wanted a template “system” which lets me define one or more global templates which integrate the output of multiple actions into one single html page. Mojavi already has the basic tools for this: the ActionChain and Filter classes.

Used Classes

Here is the code to all classes used by my system

TemplateFilter.class.php

/**
 * This filter implements global templates
 * Used in combination with the AggregateAction class
 */
class TemplateFilter extends Filter
{

    function execute (&$filterChain, &$controller, &$request, &$user)
    {
        static $loaded = false;

        if(!$loaded)  //only load once!
        {
            $loaded = true;

            //set up main renderer and store it in the request instance
            $mainRenderer =& new Renderer($controller, $request, $user);
            $request->setAttributeByRef('mainRenderer',$mainRenderer);

            //contuinue processing the filter chain and store the output
            //in $body
            ob_start();
            $filterChain->execute($controller, $request, $user);
            $body = ob_get_contents();
            ob_end_clean();

            //mainRendererTemplate will only be set if the execute method
            //of the AggregateAction class was executed and there were
            //additional actions to be rendererd
            if($request->hasAttribute('mainRendererTemplate'))
            {
                //if the mainRenderer was used, add body to the renderer
                //and output to client
                $mainRenderer->setTemplate($request->getAttribute('mainRendererTemplate'));
                $mainRenderer->setAttribute('body',$body);
                $mainRenderer->setMode(RENDER_CLIENT);
                $mainRenderer->execute($controller,$request,$user);
            }
            else //otherwise, just echo the html to the browser
            {
                echo $body;
            }
        }
        else
        {
            $filterChain->execute($controller, $request, $user);
        }
    }
}

AggregateAction.class.php

/**
 * An easier way to add action chains to Actions
 */
class AggregateAction extends Action
{
    var $actChain = null;
    var $actNames = null;

    /**
     * Adds an action to the aggregate action chain
     *
     * @note params like ActionChain::register()
     */
    function addAction($name,$module,$action,$params = null)
    {
        if($this->actChain === null)
        {
            $this->actChain =& new ActionChain();
            $this->actNames = array();
        }

        $this->actChain->register($name,$module,$action,$params);
        $this->actNames[] = $name;
    }

    /**
     * Default template name
     *
     * @return string the template name
     */
    function getMainRendererTemplate()
    {
        return 'main.php';
    }

    function execute(&$controller, &$request, &$user)
    {
        //only execute this if we render to client
        if($controller->getRenderMode() == RENDER_VAR)
            return;

        $renderer =& $request->getAttribute('mainRenderer');

        if(!($this->actChain === null))
        {
            $this->actChain->execute($controller, $request, $user); 

            foreach($this->actNames as $name)
            {
                $renderer->setAttribute($name, $this->actChain->fetchResult($name));
            }

            $request->setAttribute('mainRendererTemplate',$this->getMainRendererTemplate());
        }
    }
}

MainTemplateAction.class.php (Example template action)

class MainTemplateAction extends AggregateAction
{

    /**
     * Initialize is used to add actions to the action chain
     *
     * @note It has to return true, otherwise processing will not continue
     */
    function initialize(&$controller,&$request,&$user)
    {
        $this->addAction('login','Default','Login');
        $this->addAction('nav','Default','MainNavigation');
        $this->addAction('cart','Cart','Show');

        return true;
    }

}

That’s all there is to it. The TemplateFilter has to be registered in the global filter chain and all my actions that might at some point be used to output the “body” into the main template extend MainTemplateAction.

The views don’t have to be modified, all the work of getting the renderer output into a global template is handled by the AggregateAction and TemplateFilter.

Setting the global template name in an Action with the getMainRendererTemplate() method is probably not very clean, but it all works like a charm for me and takes away a lot of the hassle of global templating with Mojavi.

The global renderer templates have to go into the YOURAPP/templates directory.

Please feel free to give comments on my approach in this forum topic.

August-10-09

Mojavi 3 Part 2

posted by admin

This is a list of the methods you can use in an Action and an explanation of what they do
execute ()

Note: This method is required in your Action class. Also there are File Extension SVG which stand for scalable vector graphics

This will execute any application/business logic for the action. This method is reached only after the request methods have been checked and any of the parameters have been validated.

When leaving, the execute() method should tell the controller what view is to be used. This is done by returning a string containing the view name associated with the action or an array of the parent module for the view to be executed, parent action for the view and the name of the view. I will show an example of return both in a later tutorial.
getCredential ()

This is a new feature in Mojavi 3. Basically, a credentials are a privilege array that describes any level of security. They work hand in hand with the security aspects of the User class. For Mojavi 2 users, note that this replaces the old Privileges. But it is also important to know that it can do more than just handle privileges. I will handle the usage of creditials in a later section. For now, it is sufficient to know that we set the creditial requirements for the action inside this method and that it is set to NULL by default.
getDefaultView ()

This is the view that will be executed when a given request is not served by the action. This could happen when a form being displayed for the first time or if we are displaying a static page. Be sure to reset any variable in the graphic engine and search out the File Extension SVG portions by using a simple search.

Again, just as with the execute() methoad, a string with a view name or an array of a module/action/view is passed back to the controller. By default it will pass back View::INPUT
getRequestMethods ()

You can also return a view from another module. You do this by passing an array with the view information instead of the standard View::INPUT. When you use this you create a two element array. The first element is the module name. The second element is which view you want. It cannot be just the Action name, but the file extension Action name with the specific view.

Here’s an example:

class MyClass extends Action
{

function execute()
{

$returnView[0] = MyModule;
$returnView[1] = DoSomethingInput;
-or-
$returnView[1] = DoSomethingError;
-not-
$returnView[1] = DoSomething;

return $returnView
}
}

View

I’ll add more to this later, describing the View class.

Tags: