PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/Ecart/Admin/Model/Acl/Resource.php

https://code.google.com/p/ecartcommerce/
PHP | 98 lines | 38 code | 5 blank | 55 comment | 3 complexity | 10ab58c916edb421929ab58efd8ebced MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Ecart
  4. *
  5. * This file is part of Ecart.
  6. *
  7. * Ecart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ecart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Ecart
  21. * @package Ecart_Admin
  22. * @copyright Copyright 2008-2009 E-Cart LLC
  23. * @license GNU Public License V3.0
  24. */
  25. /**
  26. *
  27. * @category Ecart
  28. * @package Ecart_Admin
  29. * @subpackage Model
  30. * @author Ecart Core Team <core@ecartcommerce.com>
  31. */
  32. class Ecart_Admin_Model_Acl_Resource extends Ecart_Db_Table
  33. {
  34. protected $_name = 'admin_acl_resource';
  35. /**
  36. * Get resource tree
  37. *
  38. * @return array
  39. */
  40. public function getTree()
  41. {
  42. $tree = array();
  43. foreach ($this->fetchAll(null, 'resource_id') as $resource) {
  44. /*if (($pos = strrpos($resource->resource_id, '_')) !== false) {
  45. $parentId = substr($resource->resource_id, 0, $pos);
  46. } else*/if(($pos = strrpos($resource->resource_id, '/')) !== false){
  47. $parentId = substr($resource->resource_id, 0, $pos);
  48. } else {
  49. $parentId = '';
  50. }
  51. $tree[$parentId][$resource->resource_id] = $resource->title;
  52. }
  53. return $tree;
  54. }
  55. /**
  56. * Add resource
  57. *
  58. * @param string $resource
  59. * @param string $title[optional]
  60. * @return Ecart_Admin_Model_Acl_Resource Provides fluent interface
  61. */
  62. public function add($resource, $title = null)
  63. {
  64. if (null === $title) {
  65. $title = $resource;
  66. }
  67. //$resource = str_replace('_', '/', $resource);
  68. if ($this->select('id')->where('resource_id = ?', $resource)->fetchOne()) {
  69. //Ecart::message()->addWarning(
  70. // Ecart::translate('admin')->__(
  71. // "Resource %s already exist", $resource
  72. // )
  73. //);
  74. return $this;
  75. }
  76. $row = $this->createRow(array(
  77. 'resource_id' => $resource,
  78. 'title' => $title
  79. ));
  80. $row->save();
  81. return $this;
  82. }
  83. /**
  84. *
  85. * @param string $resource
  86. * @return Ecart_Admin_Model_Acl_Resource Provides fluent interface
  87. */
  88. public function remove($resource)
  89. {
  90. $this->delete("resource_id LIKE '{$resource}%'");
  91. return $this;
  92. }
  93. }