Saving Checkboxlist Data And Retrieving User's Last Active Checkboxes When Creating New Record?

I have a Product model with a ‘categories’ column. This column should be able to contain data from a Checkboxlist.

Whenever a user creates a new Product I want the form to display the ‘categories’ Checkbox, with the items set as active from the user’s last created Product.

So for instance: the ‘categories’ Checkboxlist contains items ‘Movies’ and ‘Music’. When the user checks ‘Movies’ and creates the Product, the next time the user goes to create a Product, ‘Movies’ is already selected (because it saves the selection from the user’s previous product creation).

I believe these are the most effective steps to code in order to achieve this goal:

[list=1]

[*]When Product is created: checked items are saved to ‘categories’ column in Product Model & a ‘categories’ column in the User’s ‘Profile’ model

[*]User’s last saved categories (‘categories’ column in Profile model) should be retrieved at the Product’s Create form.

Code in Product model’s _form view:


<?php echo $form->checkBoxList($model, 'categories', array('movies'=>'Movies','music'=>'Music')); ?>

(I’m unsure as to where to set an array for active values)

[/list]

I’ll need to convert the Array of the selected Checkboxes to a string using explode(",", $model->categories) so I can put it inside the ‘categories’ columns of the ‘Product’ and ‘Profile’ models by using the ProductController’s actionCreate function.

Then to set the user’s last selected Checkboxlist items as active in the Product _form view I need to convert the $model->categories data back to an array by imploding the column ie implode(",", $user->categories).

How would you code this in Yii?