/app/code/Ecart/Admin/Model/Acl/Resource.php
PHP | 98 lines | 38 code | 5 blank | 55 comment | 3 complexity | 10ab58c916edb421929ab58efd8ebced MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
- <?php
- /**
- * Ecart
- *
- * This file is part of Ecart.
- *
- * Ecart is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Ecart is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Ecart
- * @package Ecart_Admin
- * @copyright Copyright 2008-2009 E-Cart LLC
- * @license GNU Public License V3.0
- */
- /**
- *
- * @category Ecart
- * @package Ecart_Admin
- * @subpackage Model
- * @author Ecart Core Team <core@ecartcommerce.com>
- */
- class Ecart_Admin_Model_Acl_Resource extends Ecart_Db_Table
- {
- protected $_name = 'admin_acl_resource';
-
- /**
- * Get resource tree
- *
- * @return array
- */
- public function getTree()
- {
- $tree = array();
- foreach ($this->fetchAll(null, 'resource_id') as $resource) {
- /*if (($pos = strrpos($resource->resource_id, '_')) !== false) {
- $parentId = substr($resource->resource_id, 0, $pos);
- } else*/if(($pos = strrpos($resource->resource_id, '/')) !== false){
- $parentId = substr($resource->resource_id, 0, $pos);
- } else {
- $parentId = '';
- }
- $tree[$parentId][$resource->resource_id] = $resource->title;
- }
- return $tree;
- }
-
- /**
- * Add resource
- *
- * @param string $resource
- * @param string $title[optional]
- * @return Ecart_Admin_Model_Acl_Resource Provides fluent interface
- */
- public function add($resource, $title = null)
- {
- if (null === $title) {
- $title = $resource;
- }
- //$resource = str_replace('_', '/', $resource);
-
- if ($this->select('id')->where('resource_id = ?', $resource)->fetchOne()) {
- //Ecart::message()->addWarning(
- // Ecart::translate('admin')->__(
- // "Resource %s already exist", $resource
- // )
- //);
- return $this;
- }
- $row = $this->createRow(array(
- 'resource_id' => $resource,
- 'title' => $title
- ));
- $row->save();
-
- return $this;
- }
- /**
- *
- * @param string $resource
- * @return Ecart_Admin_Model_Acl_Resource Provides fluent interface
- */
- public function remove($resource)
- {
- $this->delete("resource_id LIKE '{$resource}%'");
- return $this;
- }
- }