Yii extension (module) for 'star ranking' content on a Yii based webapp/site
This module uses internally Yii's built in CStarRating to render the actual rating UI but this UI can be replaced with whatever you prefer.
`average_rank` tinyint(2) DEFAULT NULL
class MyClass extends PcBaseArModel { /* * ... * @property float $average_rank * ... */ public function rules() { return array ( //... array('average_rank', 'numerical', 'min' => 1, 'max' => 10), //... ); } public function attributeLabels() { return array( //... 'average_rank' => Yii::t("MyModule.forms", 'Average Rank'), ); }
// autoloading model and component classes 'import' => array( //... // Star rank module 'application.modules.PcStarRank.*', 'application.modules.PcStarRank.models.*', 'application.modules.PcStarRank.controllers.*', 'application.modules.PcStarRank.components.*', 'application.modules.PcStarRank.extensions.PcStarRankWidget.*', //... ), //... 'modules' => array( //... 'starRank' => array( 'class' => 'application.modules.PcStarRank.PcStarRankModule' ), //... ),
$this->widget('PcStarRankWidget', array('modelId' => $model->id, 'modelClassName' => get_class($model)));
The following notes are meant for developers:
Further room for development, and its only notes I've quickly pulled out. Feel free to submit more...:
alter table rankings change `average_score` `average_score` tinyint(2) not null; alter table ranking_votes change `score_ranked` `score_ranked` tinyint(2) not null; /* !! and do the same for any rank-able table, for its 'average_rank' column!! */
Total 3 comments
Yes, i am using yii-user extension with table 'tbl_users', i adjusted the foreign key constraint in 'rankings_votes' table only. Should i change something else? Actually i made some progess since my last post and this message "Sorry - only registered, non-blocked users are allowed to rank content. Please register first. " is not showing anymore when i am logged in. The problem now is, when a user clicks on the rating widget only 'rankings' table is affected (although 'average_score' field stays zero) and the layout of the application gets broken :S (weird.. i dont know why..)
What do u think the problem could be? I suspect it is something related to the 2 functions: getCreatorRelationName() & getCreatorUserId($id).. is that possible?
Hi,
It's been a while since I maintained this early extension of mine. Lets see...:
Hello, Thanks for this nice module. I was trying the module but it is always giving me an alert that am not logged in, eventhough i am. "Sorry - only registered, non-blocked users are allowed to rank content. Please register first. " What would the problem be?
Leave a comment
Please login to leave your comment.