function addRoles($parent_role = null) { $roles_table = new Roles(); //dd($roles_table->fetchImmediateChildren(2)->toArray()); // we start this recursive funtion by looking for roles with no parent. if (is_null($parent_role)) { $roles = $roles_table->fetchParentless(); } else { $roles = $roles_table->fetchImmediateChildren($parent_role); //dd($roles->toArray()); } foreach ($roles as $role) { // Add the role and specifiy that as the parent. On the first pass, this is null. if (!$this->hasRole($role->id)) { Bolts_Log::info("Adding role " . $role->shortname); $this->addRole(new Zend_Acl_Role($role->id), $parent_role); } if (count($roles_table->fetchImmediateChildren($role->id)) > 0) { $this->addRoles($role->id); } } }
function deleteAction() { $request = new Bolts_Request($this->getRequest()); $roles_table = new Roles(); if ($request->has('id')) { $id = $request->id; $role = $roles_table->fetchRow("id = " . $id); if (is_null($role)) { $this->_redirect('/bolts/role'); } } else { $this->_redirect('/bolts/role'); } if ($this->getRequest()->isPost() and $request->has("delete")) { $errors = array(); // can't be last admin if ((bool) $role->isadmin and $roles_table->getCountByWhereClause("isadmin = 1") == 1) { $errors[] = $this->_T("This is the only admin role. It cannot be deleted."); } // can't be guest if ((bool) $role->isguest) { $errors[] = $this->_T("This is the guest role. It cannot be deleted."); } // can't be default if ((bool) $role->isdefault) { $errors[] = $this->_T("This is the default role. It cannot be deleted."); } // can't have any users $userwhereclause = "role_id = " . $role->id; $users_table = new UsersRoles(); if ($users_table->getCountByWhereClause($userwhereclause) > 0) { $errors[] = $this->_T("This role cannot be deleted because there are users assigned to it."); } // can't have children $inherited_by = $roles_table->fetchImmediateChildren($role->id); if (count($inherited_by) > 0) { $error = $this->_T("This role is inherited by role(s) "); $firstpass = true; foreach ($inherited_by as $role_i) { if ($firstpass) { $firstpass = false; } else { $error .= ", "; } $error .= $role_i->shortname; } $error .= $this->_T(". It cannot be deleted."); $errors[] = $error; } if ($request->delete == "Yes") { if (count($errors) > 0) { $this->view->errors = $errors; } else { $roles_table->delete("id = " . $id); $this->view->success = $this->_T("Role deleted."); } } else { $this->_redirect("/bolts/role"); } } $this->view->role = $role->toArray(); }