Cheetah
All Classes Namespaces Files Functions Variables Pages
ChStoreTemplate.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbTwigTemplate');
9 
10 /*
11  * Store module View
12  */
14 {
15  var $_iPageIndex = 500;
16 
20  function __construct(&$oConfig, &$oDb)
21  {
22  parent::__construct($oConfig, $oDb);
23  }
24 
25  function unit ($aData, $sTemplateName, &$oVotingView, $isShort = false)
26  {
27  if (null == $this->_oMain)
28  $this->_oMain = ChWsbModule::getInstance('ChStoreModule');
29 
30  if (!$this->_oMain->isAllowedView ($aData)) {
31  $aVars = array ('extra_css_class' => 'ch_store_unit');
32  return $this->parseHtmlByName('twig_unit_private', $aVars);
33  }
34 
35  $sImage = '';
36  if ($aData['thumb']) {
37  $a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
38  $aImage = ChWsbService::call('photos', 'get_image', array($a, 'browse'), 'Search');
39  $sImage = $aImage['no_image'] ? '' : $aImage['file'];
40  }
41 
42  $aVars = array (
43  'id' => $aData['id'],
44  'thumb_url' => $sImage ? $sImage : $this->getImageUrl('no-image-thumb.png'),
45  'product_url' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
46  'product_title' => $aData['title'],
47  'price_range' => $this->_oMain->_formatPriceRange($aData),
48  'snippet_text' => $this->_oMain->_formatSnippetText($aData, 500),
49  'ch_if:full' => array (
50  'condition' => !$isShort,
51  'content' => array (
52  'created' => defineTimeInterval($aData['created']),
53  'author' => $aData['author_id'] ? getNickName($aData['author_id']) : _t('_ch_store_admin'),
54  'author_url' => $aData['author_id'] ? getProfileLink($aData['author_id']) : 'javascript:void(0);',
55  'rate' => $oVotingView ? $oVotingView->getJustVotingElement(0, $aData['id'], $aData['rate']) : '&#160;',
56  ),
57  ),
58  );
59 
60  return $this->parseHtmlByName($sTemplateName, $aVars);
61  }
62 
63  // ======================= ppage compose block functions
64 
65  function blockDesc (&$aDataEntry)
66  {
67  $aVars = array (
68  'description' => $aDataEntry['desc'],
69  );
70  return $this->parseHtmlByName('block_description', $aVars);
71  }
72 
73  function blockFiles (&$aData)
74  {
75  $iEntryId = $aData['id'];
76  $aReadyMedia = array ();
77  if ($iEntryId)
78  $aReadyMedia = $GLOBALS['oChStoreModule']->_oDb->getFiles($iEntryId, true);
79 
80  if (!$aReadyMedia)
81  return '';
82 
83  $aVars = array (
84  'ch_repeat:files' => array (),
85  );
86 
87  ch_import('ChWsbPayments');
88  $oPayment = ChWsbPayments::getInstance();
89 
90  $sCurrencySign = getParam('pmt_default_currency_sign');
91  foreach ($aReadyMedia as $r) {
92 
93  $iMediaId = $r['media_id'];
94 
95  $a = ChWsbService::call('files', 'get_file_array', array($iMediaId), 'Search');
96  if (!$a['date'])
97  continue;
98 
99  ch_import('ChTemplFormView');
100  $oForm = new ChTemplFormView(array());
101 
102  $aInputBtnDownload = array (
103  'type' => 'submit',
104  'name' => 'ch_store_download',
105  'value' => _t ('_ch_store_download'),
106  'attrs' => array(
107  'onclick' => "window.open ('" . CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . "download/{$r['id']}','_self');",
108  ),
109  );
110 
111  $aVars['ch_repeat:files'][] = array (
112  'id' => $iMediaId,
113  'title' => $a['title'],
114  'icon' => $a['file'],
115  'price' => $sCurrencySign . ' ' . $r['price'],
116  'for_group' => sprintf(_t('_ch_store_for_group'), $GLOBALS['oChStoreModule']->getGroupName($r['allow_purchase_to'])),
117  'date' => defineTimeInterval($a['date']),
118  'ch_if:purchase' => array (
119  'condition' => $GLOBALS['oChStoreModule']->isAllowedPurchase($r),
120  'content' => array (
121  'btn_purchase' => $oPayment->getAddToCartLink($r['author_id'], $this->_oConfig->getId(), $r['id'], 1),
122  ),
123  ),
124  'ch_if:download' => array (
125  'condition' => $GLOBALS['oChStoreModule']->isAllowedDownload($r),
126  'content' => array (
127  'btn_download' => $oForm->genInputButton ($aInputBtnDownload),
128  ),
129  ),
130  );
131  }
132 
133  if (!$aVars['ch_repeat:files'])
134  return '';
135 
136  return $this->parseHtmlByName('block_files', $aVars);
137  }
138 
139  function blockFields (&$aDataEntry)
140  {
141  $sRet = '<table class="ch_store_fields">';
142  ch_store_import ('FormAdd');
143  $oForm = new ChStoreFormAdd ($GLOBALS['oChStoreModule'], getLoggedId());
144  foreach ($oForm->aInputs as $k => $a) {
145  if (!isset($a['display'])) continue;
146  $sRet .= '<tr><td class="ch_store_field_name ch-def-font-grayed ch-def-padding-sec-right" valign="top">' . $a['caption'] . '</td><td class="ch_store_field_value">';
147  if (is_string($a['display']) && is_callable(array($this, $a['display'])))
148  $sRet .= call_user_func_array(array($this, $a['display']), array($aDataEntry[$k]));
149  else
150  $sRet .= $aDataEntry[$k];
151  $sRet .= '</td></tr>';
152  }
153  $sRet .= '</table>';
154  return $sRet;
155  }
156 }
ChTemplFormView
Definition: ChTemplFormView.php:11
ChStoreTemplate\unit
unit($aData, $sTemplateName, &$oVotingView, $isShort=false)
Definition: ChStoreTemplate.php:25
ChWsbModule\getInstance
static getInstance($sClassName)
Definition: ChWsbModule.php:89
ChWsbTwigTemplate
Definition: ChWsbTwigTemplate.php:14
defineTimeInterval
defineTimeInterval($iTime, $bAutoDateConvert=true, $bShort=false)
Definition: utils.inc.php:831
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChStoreFormAdd
Definition: ChStoreFormAdd.php:12
php
ch_store_import
ch_store_import($sClassPostfix, $aModuleOverwright=array())
Definition: ChStoreModule.php:8
$oForm
$oForm
Definition: host_tools.php:42
ChStoreTemplate
Definition: ChStoreTemplate.php:14
ChWsbPayments\getInstance
static getInstance()
Definition: ChWsbPayments.php:31
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbTemplate\getImageUrl
getImageUrl($sName, $sCheckIn=CH_WSB_TEMPLATE_CHECK_IN_BOTH)
Definition: ChWsbTemplate.php:595
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
ChStoreTemplate\$_iPageIndex
$_iPageIndex
Definition: ChStoreTemplate.php:15
ChStoreTemplate\blockFiles
blockFiles(&$aData)
Definition: ChStoreTemplate.php:73
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
ChStoreTemplate\blockDesc
blockDesc(&$aDataEntry)
Definition: ChStoreTemplate.php:65
$oDb
global $oDb
Definition: db.inc.php:39
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
$aVars
$aVars
Definition: license.php:101
ChWsbTwigTemplate\parseHtmlByName
parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml=null, $sCheckIn=CH_WSB_TEMPLATE_CHECK_IN_BOTH)
Definition: ChWsbTwigTemplate.php:42
ChStoreTemplate\blockFields
blockFields(&$aDataEntry)
Definition: ChStoreTemplate.php:139
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChStoreTemplate\__construct
__construct(&$oConfig, &$oDb)
Definition: ChStoreTemplate.php:20
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10