PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/model/modx/mysql/modtemplate.class.php

https://github.com/modxcms/revolution
PHP | 40 lines | 31 code | 1 blank | 8 comment | 0 complexity | 7cdaf3a3a4fe1da3bee2edc8de178d29 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. include_once (strtr(realpath(dirname(__FILE__)), '\\', '/') . '/../modtemplate.class.php');
  11. /**
  12. * @package modx
  13. * @subpackage mysql
  14. */
  15. class modTemplate_mysql extends modTemplate {
  16. public static function listTemplateVars(modTemplate &$template, array $sort = array('name' => 'ASC'), $limit = 0, $offset = 0,array $conditions = array()) {
  17. $result = array('collection' => array(), 'total' => 0);
  18. $c = $template->xpdo->newQuery('modTemplateVar');
  19. $result['total'] = $template->xpdo->getCount('modTemplateVar',$c);
  20. $c->select($template->xpdo->getSelectColumns('modTemplateVar','modTemplateVar'));
  21. $c->leftJoin('modTemplateVarTemplate','modTemplateVarTemplate', array(
  22. "modTemplateVarTemplate.tmplvarid = modTemplateVar.id",
  23. 'modTemplateVarTemplate.templateid' => $template->get('id')
  24. ));
  25. $c->leftJoin('modCategory','Category');
  26. if (!empty($conditions)) { $c->where($conditions); }
  27. $c->select(array(
  28. "IF(ISNULL(modTemplateVarTemplate.tmplvarid),0,1) AS access",
  29. "IF(ISNULL(modTemplateVarTemplate.rank),0,modTemplateVarTemplate.rank) AS tv_rank",
  30. 'category_name' => 'Category.category',
  31. ));
  32. foreach ($sort as $sortKey => $sortDir) {
  33. $c->sortby($sortKey, $sortDir);
  34. }
  35. if ($limit > 0) $c->limit($limit, $offset);
  36. $result['collection'] = $template->xpdo->getCollection('modTemplateVar',$c);
  37. return $result;
  38. }
  39. }