All Data Structures Functions Variables Pages
GameRewardRedeemSummaryListViewColumnAdapter.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  const REDEEM_REWARD_LINK_PREFIX = 'redeem-reward-link';
40 
41  public function renderGridViewData()
42  {
43  $className = get_class($this);
44  $value = $className . '::resolveSummary($data, ' . $this->view->getAvailableCoinsForCurrentUser() . ')';
45  return array(
46  'name' => null,
47  'value' => $value,
48  'type' => 'raw',
49  );
50  }
51 
57  public static function resolveSummary(GameReward $gameReward, $availableCoins)
58  {
59  assert('is_int($availableCoins)');
60  $content = ZurmoHtml::tag('h4', array('class' => 'reward-name'), strval($gameReward));
61  if ($gameReward->description != null)
62  {
63  $content .= ZurmoHtml::tag('p', array('class' => 'reward-description'), $gameReward->description);
64  }
65  $content .= ZurmoHtml::tag('span', array('class' => 'reward-cost'), $gameReward->cost . ' x ');
66  $content .= ZurmoHtml::tag('span', array(),
67  ' - ' . $gameReward->quantity . ' ' . Zurmo::t('Core', 'Available') .
68  ' ' . static::renderExpirationDateTimeContent($gameReward));
69  $content .= static::renderRedeemLink($gameReward, $availableCoins);
70  return $content;
71  }
72 
73  protected static function renderExpirationDateTimeContent(GameReward $gameReward)
74  {
75  if (!DateTimeUtil::isDateTimeStringNull($gameReward->expirationDateTime))
76  {
77  $content = Zurmo::t('ZurmoModule', 'Until') . ' ';
78  return $content . DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($gameReward->expirationDateTime);
79  }
80  }
81 
82  protected static function renderRedeemLink(GameReward $gameReward, $availableCoins)
83  {
84  assert('is_int($availableCoins)');
85  $url = Yii::app()->createUrl('gameRewards/default/redeemReward', array('id' => $gameReward->id));
86  $label = Zurmo::t('ZurmoModule', 'Redeem');
87  $aContent = ZurmoHtml::wrapLink($label);
88  // Begin Not Coding Standard
89  return ZurmoHtml::ajaxLink($aContent, $url,
90  array('type' => 'GET',
91  'dataType' => 'json',
92  'success' => 'function(data){
93  $("#FlashMessageBar").jnotifyAddMessage({
94  text: data.message,
95  permanent: false,
96  });
97  $("#GameRewardsRedeemListView").each(function(){
98  $(this).find(".pager").find(".refresh").find("a").click();
99  });
100  }'
101  ),
102  self::resolveHtmlOptionsForRedeemLink($gameReward, $availableCoins));
103  // End Not Coding Standard
104  }
105 
106  protected static function resolveHtmlOptionsForRedeemLink(GameReward $gameReward, $availableCoins)
107  {
108  assert('is_int($availableCoins)');
109  $htmlOptions = array();
110  $disabledClass = null;
111  $disabled = false;
112  if ($gameReward->cost > $availableCoins || $gameReward->quantity <= 0)
113  {
114  $disabledClass = ' disabled';
115  $disabled = true;
116  }
117  $id = static::getRedeemRewardLinkId($gameReward->id);
118  $htmlOptions['id'] = $id;
119  $htmlOptions['name'] = $id;
120  $htmlOptions['class'] = 'attachLoading z-button reward-redeem-link' . $disabledClass;
121  $htmlOptions['namespace'] = 'redeem';
122  if ($disabled)
123  {
124  $htmlOptions['onclick'] = 'js:return false;';
125  }
126  else
127  {
128  $htmlOptions['onclick'] = 'js:$(this).addClass("loading").addClass("loading-ajax-submit");
129  $(this).makeOrRemoveLoadingSpinner(true, "#" + $(this).attr("id"));';
130  }
131  return $htmlOptions;
132  }
133 
134  protected static function getRedeemRewardLinkId($gameRewardId)
135  {
136  return self::REDEEM_REWARD_LINK_PREFIX . '-' . $gameRewardId;
137  }
138  }
139 ?>
static ajaxLink($text, $url, $ajaxOptions=array(), $htmlOptions=array())
Definition: ZurmoHtml.php:328
static resolveSummary(GameReward $gameReward, $availableCoins)
static wrapLink($label)
Definition: ZurmoHtml.php:666
Generated on Sun May 31 2020 07:10:32