public static function renderCollectionContent(User $user, GameCollection $collection) { $gameCollectionRules = GameCollectionRulesFactory::createByType($collection->type); $collectionImageUrl = Yii::app()->themeManager->baseUrl . '/default/images/collections/' . $gameCollectionRules::getType() . '/' . $gameCollectionRules::makeLargeCollectionImageName(); $collectionBadgeImage = static::resolveLazyLoadImage($collectionImageUrl); $content = ZurmoHtml::tag('div', array('class' => 'collection-badge'), $collectionBadgeImage); $content .= ZurmoHtml::tag('h3', array(), $gameCollectionRules->getCollectionLabel() . ' ' . Zurmo::t('GamificationModule', 'Collection')); $content .= static::renderCollectionItemsContent($user, $collection, $gameCollectionRules); $content = ZurmoHtml::tag('div', array(), $content); if ($collection->canRedeem() && $user->id == Yii::app()->user->userModel->id) { $extraClass = ' redeemable'; } else { $extraClass = null; } return ZurmoHtml::tag('div', array('id' => static::getCollectionContainerId($collection->id), 'class' => 'gd-collection-panel clearfix' . $extraClass), $content); }
public function actionRedeemCollection($id) { $gameCollection = GameCollection::getById((int) $id); if ($gameCollection->person->getClassId('Item') != Yii::app()->user->userModel->getClassId('Item')) { throw new NotSupportedException(); } if ($gameCollection->redeem()) { $gameCollectionRules = GameCollectionRulesFactory::createByType($gameCollection->type); $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel); $gameCoin->addValue($gameCollectionRules::getCoinRedemptionValue()); $saved = $gameCoin->save(); if (!$saved) { throw new FailedToSaveModelException(); } } echo UserGameDashboardView::renderCollectionContent(Yii::app()->user->userModel, $gameCollection); }
protected static function renderGetNewCollectionItemNotification() { $collectionAndItemKey = Yii::app()->gameHelper->resolveNewCollectionItems(); if (null != $collectionAndItemKey) { $claimCollectionItemUrl = Yii::app()->createUrl('gamification/default/claimCollectionItem', array('key' => $collectionAndItemKey[1], 'typeKey' => $collectionAndItemKey[2])); $gameCollectionRules = GameCollectionRulesFactory::createByType($collectionAndItemKey[0]->type); $collectionItemTypesAndLabels = $gameCollectionRules::getItemTypesAndLabels(); $claimRewardLink = ZurmoHtml::ajaxLink(Zurmo::t('GamificationModule', 'Get this item'), $claimCollectionItemUrl, array(), array('id' => static::CLAIM_ITEM_LINK_ID, 'class' => 'mini-button')); $closeLink = ZurmoHtml::link(Zurmo::t('Core', 'Close'), '#', array('id' => 'close-game-notification-link')); $collectionItemImagePath = $gameCollectionRules::makeMediumCOllectionItemImagePath($collectionAndItemKey[1]); $outerContent = ZurmoHtml::tag('h5', array(), Zurmo::t('Core', 'Congratulations!')); $content = ZurmoHtml::tag('span', array('class' => 'collection-item-image'), ZurmoHtml::image($collectionItemImagePath)); $content .= Zurmo::t('GamificationModule', 'You discovered the {name}', array('{name}' => $collectionItemTypesAndLabels[$collectionAndItemKey[1]])); $content .= '<br/>'; $content .= Zurmo::t('GamificationModule', '{claimLink} or {closeLink}', array('{claimLink}' => $claimRewardLink, '{closeLink}' => $closeLink)); $content = $outerContent . ZurmoHtml::tag('p', array(), $content); $content = ZurmoHtml::tag('div', array('id' => 'game-notification'), $content); $content .= static::renderAudioContent(); return $content; } }
/** * Given an Item (Either User or Person), try to find an existing model for each type. If the model does * not exist, create it and populate the Item and type. @return models found or created indexed by type. * @param Item $person * @param $collectionTypes * @return array * @throws FailedToSaveModelException */ public static function resolvePersonAndAvailableTypes(Item $person, $collectionTypes) { assert('$person->id > 0'); assert('$person instanceof Contact || $person instanceof User'); assert('is_array($collectionTypes)'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item'))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameCollection'); $where = RedBeanModelDataProvider::makeWhere('GameCollection', $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, null, $where, null); $modelsByType = array(); foreach ($collectionTypes as $type) { $modelFound = false; foreach ($models as $model) { if ($model->type == $type) { $modelsByType[$type] = $model; $modelFound = true; break; } } if (!$modelFound) { $gameCollectionRules = GameCollectionRulesFactory::createByType($type); $gameCollection = new GameCollection(); $gameCollection->type = $type; $gameCollection->person = $person; $gameCollection->serializedData = serialize($gameCollectionRules::makeDefaultData()); $saved = $gameCollection->save(); if (!$saved) { throw new FailedToSaveModelException(); } $modelsByType[$type] = $gameCollection; } } return $modelsByType; }