Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
more improvements in the plugin system
Browse files Browse the repository at this point in the history
ScoreBySubjectMatter plugin
  • Loading branch information
novazembla committed Sep 13, 2011
1 parent 61eb5c0 commit db0ff45
Show file tree
Hide file tree
Showing 25 changed files with 450 additions and 117 deletions.
Binary file modified documentation/mg_specifications_v0.5.doc
Binary file not shown.
1 change: 0 additions & 1 deletion www/css/yii/pager.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ul.yiiPager
border:0;
margin:0;
padding:0;
line-height:100%;
display:inline;
line-height: 20px;
}
Expand Down
3 changes: 0 additions & 3 deletions www/protected/components/MGJuiSliderInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ public function run()
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];

if ($this->admin)
$this->htmlOptions['disabled'] = 'disabled';

if($this->hasModel())
{
$attribute=$this->attribute;
Expand Down
20 changes: 13 additions & 7 deletions www/protected/data/fbvsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@
'play_once_and_move_on' => '0',
'play_once_and_move_on_url' => '',
'turns' => '4',
'score_new' => '2',
'score_match' => '1',
'score_expert' => '3',
'image_width' => '450',
'image_height' => '450',
),
Expand All @@ -160,9 +157,6 @@
'play_once_and_move_on' => '1',
'play_once_and_move_on_url' => 'http://www.metadatagames.com',
'turns' => '4',
'score_new' => '2',
'score_match' => '1',
'score_expert' => '3',
'image_width' => '450',
'image_height' => '450',
),
Expand All @@ -182,7 +176,19 @@
array (
'WordsToAvoid' =>
array (
'words_to_avoid_threshold' => 10,
'words_to_avoid_threshold' => '2',
),
),
'weighting' =>
array (
'ScoreBySubjectMatter' =>
array (
'score_new' => '2',
'score_match' => '1',
'score_new_expert' => '5',
'score_new_trusted' => '5',
'score_match_expert' => '4',
'score_match_trusted' => '4',
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions www/protected/models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class Image extends BaseImage
{
// xxx make use of last_access

public static function model($className=__CLASS__) {
return parent::model($className);
}
Expand Down
41 changes: 40 additions & 1 deletion www/protected/models/UserToSubjectMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public static function ensureRelationShips($user_id) {
}
}


/**
* List the subject matters for the user
*
Expand All @@ -120,4 +119,44 @@ public static function listForUser($user_id) {
return null;
}
}

/**
* List the subject matters values for the user filtered by images. This method returns only subject matters
* that belong to the image's image sets
*
* @param int $user_id The id of the user for whom the list should be generated
* @param array $image_ids list of images for which you would like to retrieve the related subject matters user values
* @return array null if no values or array of arrays [[image.id, usm.subject_matter_id, usm.interest, usm.expertise, usm.trust], ... ]
*/
public static function listForUserAndImages($user_id, $image_ids) {
$command = Yii::app()->db->createCommand()
->select('i.id as image_id, usm.subject_matter_id, usm.interest, usm.expertise, usm.trust')
->from('{{image}} i')
->rightJoin('{{image_set_to_image}} is2i', 'is2i.image_id=i.id')
->rightJoin('{{image_set_to_subject_matter}} is2sm', 'is2sm.image_set_id=is2i.image_set_id')
->rightJoin('{{user_to_subject_matter}} usm', 'usm.subject_matter_id=is2sm.subject_matter_id')
->where(array('and', 'usm.user_id=:userID', array( 'in', 'i.id', array_values($image_ids))), array('userID' => $user_id));
$command->distinct = true;
return $command->queryAll();
}

/**
* List the subject matters MAX(values) for the user filtered by images. This method returns only subject matters
* that belong to the image's image sets. It will only return one row per image.
*
* @param int $user_id The id of the user for whom the list should be generated
* @param array $image_ids list of images for which you would like to retrieve the related subject matters user values
* @return array null if no values or array of arrays [[image.id, usm.subject_matter_id, usm.interest, usm.expertise, usm.trust], ... ]
*/
public static function listMAXForUserAndImages($user_id, $image_ids) {
return Yii::app()->db->createCommand()
->select('i.id as image_id, MAX(usm.interest) as interest, MAX(usm.expertise) as expertise, MAX(usm.trust) as trust')
->from('{{image}} i')
->rightJoin('{{image_set_to_image}} is2i', 'is2i.image_id=i.id')
->rightJoin('{{image_set_to_subject_matter}} is2sm', 'is2sm.image_set_id=is2i.image_set_id')
->rightJoin('{{user_to_subject_matter}} usm', 'usm.subject_matter_id=is2sm.subject_matter_id')
->where(array('and', 'usm.user_id=:userID', array( 'in', 'i.id', array_values($image_ids))), array('userID' => $user_id))
->group('i.id')
->queryAll();
}
}
10 changes: 7 additions & 3 deletions www/protected/modules/admin/controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,18 @@ private function _batchProcess() {
$plugins = PluginsModule::getAccessiblePlugins("import");
if (count($plugins) > 0) {
foreach ($plugins as $plugin) {
$plugin->component->validate($firstModel, $errors);
if (method_exists($plugin->component, "validate")) {
$plugin->component->validate($firstModel, $errors);
}
}
}

if (count($errors) == 0) {
if (count($plugins) > 0) {
foreach ($plugins as $plugin) {
$plugin->component->process($images);
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "process")) {
$plugin->component->process($images);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion www/protected/modules/admin/views/import/uploadprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
echo $plugin->component->form($form);
if (method_exists($plugin->component, "form")) {
echo $plugin->component->form($form);
}
}
} catch (Exception $e) {}
}
Expand Down
2 changes: 2 additions & 0 deletions www/protected/modules/admin/views/user/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
$this->widget('zii.widgets.CListView', array(
'id' => 'user-tags-listview',
'dataProvider'=> Tag::model()->searchUserTags($model->id),
'pager' => array('cssFile' => Yii::app()->request->baseUrl . "/css/yii/pager.css"),
'itemView'=>'_viewTagListItem',
'sortableAttributes'=>array(
'tag' => Yii::t('app', 'Tag name'),
Expand All @@ -98,6 +99,7 @@
$this->widget('zii.widgets.CListView', array(
'id' => 'user-images-listview',
'dataProvider'=>Image::model()->searchUserImages($model->id),
'pager' => array('cssFile' => Yii::app()->request->baseUrl . "/css/yii/pager.css"),
'itemView'=>'_viewImageListItem',
'sortableAttributes'=>array(
'name' => Yii::t('app', 'Image name'),
Expand Down
9 changes: 0 additions & 9 deletions www/protected/modules/api/controllers/GamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function accessRules() {
* "play_once_and_move_on":"0",
* "play_once_and_move_on_url":"",
* "turns":"4",
* "score_new":"2",
* "score_match":"1",
* "score_expert":"3",
* "image_width":"450",
* "image_height":"450",
* "game_id":"1",
Expand Down Expand Up @@ -295,9 +292,6 @@ private function _playGet($game, $game_model, $game_engine) {

//we don't want to send certain data
unset($data['game']->game_id);
unset($data['game']->score_new);
unset($data['game']->score_match);
unset($data['game']->score_expert);
unset($data['game']->arcade_image);

$this->sendResponse($data);
Expand Down Expand Up @@ -360,9 +354,6 @@ private function _playPost($game, $game_model, $game_engine) {

//we don't want to send certain data
unset($data['game']->game_id);
unset($data['game']->score_new);
unset($data['game']->score_match);
unset($data['game']->score_expert);
unset($data['game']->arcade_image);
unset($data['game']->request);

Expand Down
8 changes: 4 additions & 4 deletions www/protected/modules/games/components/MGGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ protected function getLicenceInfo($licenceIDs) {
interface MGGameInterface
{
public function parseSubmission(&$game, &$game_model);
public function parseTags($game, &$game_model);
public function setWeights($game, &$game_model, $tags);
public function getTurn($game, &$game_model, $tags=array());
public function getScore($game, &$game_model, &$tags);
public function parseTags(&$game, &$game_model);
public function setWeights(&$game, &$game_model, $tags);
public function getTurn(&$game, &$game_model, $tags=array());
public function getScore(&$game, &$game_model, &$tags);
}
82 changes: 31 additions & 51 deletions www/protected/modules/games/components/ZenTagGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,26 @@ public function parseSubmission(&$game, &$game_model) {

$plugins = PluginsModule::getActivePlugins("dictionary");
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "parseSubmission")) {
$success = $success && $plugin->component->parseSubmission($game, $game_model);
}
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "parseSubmission")) {
$success = $success && $plugin->component->parseSubmission($game, $game_model);
}
} catch (Exception $e) {}
}
}

$plugins = PluginsModule::getActivePlugins("weighting");
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "parseSubmission")) {
$success = $success && $plugin->component->parseSubmission($game, $game_model);
}
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "parseSubmission")) {
$success = $success && $plugin->component->parseSubmission($game, $game_model);
}
} catch (Exception $e) {}
}
}

return $success;
}

public function getTurn($game, &$game_model, $tags=array()) {
public function getTurn(&$game, &$game_model, $tags=array()) {
$data = array();
if ($game->turn < $game->turns) {
$imageSets = $this->getImageSets($game, $game_model);
Expand Down Expand Up @@ -77,14 +73,12 @@ public function getTurn($game, &$game_model, $tags=array()) {

$plugins = PluginsModule::getActivePlugins("dictionary");
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "wordsToAvoid")) {
// this method gets all elements by reference. $data["wordstoavoid"] might be changed
$plugin->component->wordsToAvoid($data["wordstoavoid"], $used_images, $game, $game_model, $tags);
}
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "wordsToAvoid")) {
// this method gets all elements by reference. $data["wordstoavoid"] might be changed
$plugin->component->wordsToAvoid($data["wordstoavoid"], $used_images, $game, $game_model, $tags);
}
} catch (Exception $e) {}
}
}

} else
Expand All @@ -99,56 +93,42 @@ public function getTurn($game, &$game_model, $tags=array()) {
return $data;
}

public function setWeights($game, &$game_model, $tags) {
public function setWeights(&$game, &$game_model, $tags) {
$plugins = PluginsModule::getActivePlugins("dictionary");
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "setWeights")) {
$tags = $plugin->component->setWeights($game, $game_model, $tags);
}
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "setWeights")) {
$tags = $plugin->component->setWeights($game, $game_model, $tags);
}
} catch (Exception $e) {}
}
}

$plugins = PluginsModule::getActivePlugins("weighting");
if (count($plugins) > 0) {
try {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "setWeights")) {
$tags = $plugin->component->setWeights($game, $game_model, $tags);
}
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "setWeights")) {
$tags = $plugin->component->setWeights($game, $game_model, $tags);
}
} catch (Exception $e) {}
}
}
return $tags;
}

public function getScore($game, &$game_model, &$tags) {
public function getScore(&$game, &$game_model, &$tags) {
$score = 0;
foreach ($tags as $image_id => $image_tags) {
foreach ($image_tags as $tag => $tag_info) {
if ($tag_info["weight"] > 0) {
switch ($tag_info["type"]) {
case "new":
$tags[$image_id][$tag]["score"] = (int)$game->score_new;
$score = $score + (int)$game->score_new;
break;

case "match":
$tags[$image_id][$tag]["score"] = (int)$game->score_match;
$score = $score + (int)$game->score_match;
break;

//xxx get expert trust whatever scoring here
}

$plugins = PluginsModule::getActivePlugins("weighting");
if (count($plugins) > 0) {
foreach ($plugins as $plugin) {
if (method_exists($plugin->component, "score")) {
$score = $plugin->component->score($game, $game_model, $tags, $score);
}
}
}
return $score;
}

public function parseTags($game, &$game_model) {
public function parseTags(&$game, &$game_model) {
$data = array();
$image_ids = array();
foreach ($game->request->submissions as $submission) {
Expand Down
2 changes: 2 additions & 0 deletions www/protected/modules/games/controllers/ZenTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function actionUpdate() {
$model = $this->loadModel(array("unique_id" => "ZenTag"), 'ZenTag');
$model->fbvLoad();

// xxx here you need some solution do enable disable plugins for a game

$this->performAjaxValidation($model, 'zentag-form');
if (isset($_POST['ZenTag'])) {
$model->setAttributes($_POST['ZenTag']);
Expand Down
Loading

0 comments on commit db0ff45

Please sign in to comment.