Advertisement
vanchelo

msGetGallery

Oct 17th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2. if (!isset($modx->miniShop) || !is_object($modx->miniShop)) {
  3.     $modx->miniShop = $modx->getService('minishop','miniShop', $modx->getOption('core_path').'components/minishop/model/minishop/', $scriptProperties);
  4.     if (!($modx->miniShop instanceof miniShop)) return '';
  5. }
  6.  
  7. $id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id'));
  8.  
  9. // if (!$modx->getCount('modResource', $id)) {return $modx->lexicon('ms.goods.err_nf');}
  10.  
  11. $arr = array();
  12. $q = $modx->newQuery('ModGallery');
  13. $q->select(array('id','gid','name','description','file','fileorder'));
  14. $q->andCondition(array('gid' => $id, 'wid' => $_SESSION['minishop']['warehouse']), '', 0);
  15. if ($onlyImg) {
  16.     $extensions = explode(',',$modx->getOption('upload_images'));
  17.     $tmp = array();
  18.     foreach ($extensions as $v) {
  19.         $q->orCondition(array('file:LIKE' => '%.'.$v), '', 1);
  20.     }
  21. }
  22.  
  23. if ($q->prepare() && $q->stmt->execute()) {
  24.     $total = $q->stmt->rowCount();
  25. }
  26.  
  27. if ($total == 0) return;
  28.  
  29. $modx->setPlaceholder($totalVar, $total);
  30.  
  31. $q->sortby($sortby,$sortdir);
  32. if (!empty($limit)) {
  33.     $q->limit($limit,$offset);
  34. }
  35.  
  36. if ($q->prepare() && $q->stmt->execute()) {
  37.     $gallery = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
  38. }
  39.  
  40. $result = array();
  41. foreach ($gallery as $v) {
  42.     if (!$res = $modx->getChunk($tpl, $v)) {
  43.         $res = '<pre>'.(print_r($v, true)).'</pre>';
  44.     }
  45.     $result[] = $res;
  46. }
  47.  
  48. return implode($outputSeparator, $result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement