PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/sally/core/lib/sly/Form/Widget/LinkBase.php

https://bitbucket.org/SallyCMS/trunk
PHP | 85 lines | 39 code | 11 blank | 35 comment | 3 complexity | e7075e2322ef0911326ceb5d5bd40d10 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (c) 2012, webvariants GbR, http://www.webvariants.de
  4. *
  5. * This file is released under the terms of the MIT license. You can find the
  6. * complete text in the attached LICENSE file or online at:
  7. *
  8. * http://www.opensource.org/licenses/mit-license.php
  9. */
  10. /**
  11. * Link widget
  12. *
  13. * This element will render a special widget that allows the user to select
  14. * one article. The article will be returned without any language information,
  15. * so only its ID is returned.
  16. * Selection will be performed in the so-called 'linkmap', a special popup for
  17. * browsing through the article structure.
  18. *
  19. * @ingroup form
  20. * @author Christoph
  21. */
  22. abstract class sly_Form_Widget_LinkBase extends sly_Form_ElementBase {
  23. protected $types = array();
  24. protected $categories = array();
  25. /**
  26. * @return sly_Form_Widget_LinkBase the widget itself
  27. */
  28. public function filterByCategories(array $cats, $recursive = false) {
  29. foreach ($cats as $cat) $this->filterByCategory($cat, $recursive);
  30. return $this;
  31. }
  32. /**
  33. * @return sly_Form_Widget_LinkBase the widget itself
  34. */
  35. public function filterByCategory($cat, $recursive = false) {
  36. $catID = $cat instanceof sly_Model_Category ? $cat->getId() : (int) $cat;
  37. if (!$recursive) {
  38. if (!in_array($catID, $this->categories)) {
  39. $this->categories[] = $catID;
  40. }
  41. }
  42. else {
  43. $serv = sly_Core::getContainer()->getCategoryService();
  44. $tree = $serv->findTree($catID);
  45. foreach ($tree as $cat) {
  46. $this->categories[] = $cat->getId();
  47. }
  48. $this->categories = array_unique($this->categories);
  49. }
  50. return $this;
  51. }
  52. /**
  53. * @return sly_Form_Widget_LinkBase the widget itself
  54. */
  55. public function filterByArticleTypes(array $types) {
  56. foreach ($types as $type) $this->types[] = $type;
  57. $this->types = array_unique($this->types);
  58. return $this;
  59. }
  60. /**
  61. * @return sly_Form_Widget_LinkBase the widget itself
  62. */
  63. public function clearCategoryFilter() {
  64. $this->categories = array();
  65. return $this;
  66. }
  67. /**
  68. * @return sly_Form_Widget_LinkBase the widget itself
  69. */
  70. public function clearArticleTypeFilter() {
  71. $this->types = array();
  72. return $this;
  73. }
  74. }