[EXTENSION] Dashboard controller

jQueryUI based Dashboard controller here

How to use it, can you give some example code?

Sample controller DashController is present under controller folder.

Override init() function, set up array of portlets & DB-related params.

Nice extension. A few notes:

Autosaving doesn’t seem to work here. It doesn’t send http requests in the background.

Also at the moment it’s not good to save dasboard prefs in the user table, because the prefs are not just updated but the whole row deleted and inserted. Which kills all other columns of the user. (UIDashController:162-171). Maybe that could be improved.

But thanks for this base.

Tobias, thanks for the help. Now fixed :rolleyes:

Please, download ver 1.1

Ok so ive been using YII for about 3 days now so these are no expert tips but just a few points to be aware of that i came across while playing around with this which took me a while to figure out! (they are by no means definitive or the best way to do it!)

I couldnt figure out why once i got the saving working it was always loading my saved data even if i wasnt logged in. In UIController.php it has




// for testing purpose

if (empty($this->uid))

   $this->uid = 1;



This meant it always had a uid of 1 and as my testing userid was 1 it kept loading it! Just something to be aware of!

Anyway how i set it up:

Extracted the files to the protected folder (components, controllers and messages) maybe be nice if this was a self contained extension? Can that be done?)

I created a db table as so:




CREATE TABLE IF NOT EXISTS tbl_dashboard (

  `userId` INT UNSIGNED NOT NULL ,

  `configData` VARCHAR(255) ,

  PRIMARY KEY (`userId`) )

ENGINE = InnoDB;



Then created the Dashboard Model using GII

Then updated a couple of the methods in UIDashboardController to use the models:




private function getPreference()

    {

    	$dashboard = Dashboard::model()->find(

    		$this->_userIdFieldName." = :id", 

        	array(":id" => $this->uid)

        );

        

	    return ($dashboard === null) ? '' : unserialize($dashboard->configData);

    }






private function setPreference($preference)

    {

        $dashboard = Dashboard::model()->find(

    		$this->_userIdFieldName." = :id", 

        	array(":id" => $this->uid)

        );

        if( $dashboard === null ) {

    		$dashboard = new Dashboard();

    		$dashboard->userId = $this->uid;

        }

        

        $dashboard->configData = $preference;

        return $dashboard->save();



My main reason for changing setPreference was that when it was called for the first time the record didnt exist and as the command invoked update it and there was nothing to update it didnt work. I first played about with invoking insert first but then figured the model was an easier approach in my case.

All suggestions/error pointing outs welcome :rolleyes:

Anyhow i like the extension so far and look forward to more improvements.

Thanks

Ross

I have changed the functions a little bit to use the variables and ActiveRecords.




     /**

     * Store dashboard state to DB

     * If $preference is null - reset to default

     * @param <string> $preference

     * @return <bool>

     */

    private function setPreference($preference)

    {

        $dashboard = CActiveRecord::model($this->_tableName)->find(

                $this->_userIdFieldName." = :id",

                array(":id" => $this->uid)

        );

        if( $dashboard === null ) {

                $dashboard = new $this->_tableName();

                $dashboard->{$this->_userIdFieldName} = $this->uid;

        }


        $dashboard->{$this->_userPrefFieldName} = $preference;


        return  $dashboard->save();

    }


    /**

     * Read dashboard state from DB

     * @return <array>

     */

    private function getPreference()

    {

        $pref = CActiveRecord::model($this->_tableName)->find($this->_userIdFieldName . ' = :id',array(":id" => $this->uid));

        return (count($pref) === 0) ? '' : unserialize($pref->{$this->_userPrefFieldName});

    }



Thanks for the extension.

I tried calling a view that uses CGridView as the ‘content’ of one of the portlet. I used renderPartial.

But this results in whole page getting overwritten and all the page source code shows is




<div id="product-grid" class="grid-view"> 

<table class="items"> 

<thead> 

<tr> 

<th id="product-grid_c0">



what am i doing wrong. How do i used CGridView inside one of the portlet?

Ok, I am a total nood to yii and to php. I have been teaching my self php and i thought yii made it quit simple. i have been trying to get this dashboard to work and am failing. could you give a step by step guide for dummies (Dashboard controller for Dummies v. 1.0)

Simple unzip this archive under protected folder and look http://localhost/dash in your browser.

I still see this problem, any ideas?

here is code from my controller for the dashboard.



// set array of portlets


        &#036;this-&gt;setPortlets(


                array(                    


                    array('id' =&gt; 1, 'title' =&gt; 'Overview', 'content' =&gt; &#036;this-&gt;renderPartial('application.views.dashboard._overview', array('dashData'=&gt;intval(&#036;nMyVal),),true)),


                    array('id' =&gt; 2, 'title' =&gt; 'Products', 'content' =&gt; &#036;this-&gt;renderPartial('application.views.product.index', array('dataProvider'=&gt;&#036;dataProvider,),true,false)),


                   


                )


        );

problem is with that second portlet, it is pointing to the view that uses CGridView.

here is complete code of the that view.



&lt;h2&gt;My Products&lt;/h2&gt;


&lt;?php &#036;this-&gt;widget('zii.widgets.grid.CGridView', array(


	'dataProvider'=&gt;&#036;dataProvider,


	'columns'=&gt;array( 


        'productName',


        'productType',		


        'productVersion', 


	),


)); ?&gt;

I have to make two dashboard in my site, can you help me. What all changes to be done.

Did you solve this? Is it possible to render CGridView inside the portlet?

Not really…


CDbCommand failed to execute the SQL statement: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "dashboard_page" does not exist. The SQL statement executed was: SELECT "title"

FROM "dashboard_page"

WHERE user_id = :id. Bound with :id=1

i have problem

how to make it work?


array('id' => 6, 'title' => 'Reference', 'content' => $this->renderPartial('viewName', null, true)),

thanks before

~Happy :)) Coding~

Can any one please give me the sample tutorial of how to use the dashboard extensions with sample code ?