/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aUser) { $this->aUser->removeUserRole($this); } if (null !== $this->aRole) { $this->aRole->removeUserRole($this); } $this->user_id = null; $this->role_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aRole) { $this->aRole->removeRolePermission($this); } if (null !== $this->aPermission) { $this->aPermission->removeRolePermission($this); } $this->role_id = null; $this->permission_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Exclude object from result * * @param ChildRole $role Object to remove from the list of results * * @return $this|ChildRoleQuery The current query, for fluid interface */ public function prune($role = null) { if ($role) { $this->addUsingAlias(RoleTableMap::COL_ID, $role->getId(), Criteria::NOT_EQUAL); } return $this; }
$config = array("db-engine" => "mysql", "db-user" => "root", "db-password" => "sample", "db-host" => "127.0.0.1", "db-name" => "cerberus"); $loader = (include $rootDir . "/vendor/autoload.php"); try { $cerberus = \Alchemy\Component\Cerberus\Cerberus::getInstance(); //$cerberus->setLocale(array("lang" => "es_ES")); $cerberus->init($config); if (!$cerberus->userExists("admin")) { $user = new Cerberus\Model\User(); $user->setUsername("admin"); $user->setPassword("example-password"); $user->save(); echo "User created: " . $user->getUsername() . "<br/>"; } $user = $cerberus->getUser("admin"); if (!$cerberus->roleExists("SYS-ADMIN")) { $role = new Cerberus\Model\Role(); $role->setName("SYS-ADMIN"); $role->save(); echo "Role created: " . $role->getName() . "<br/>"; } $role = $cerberus->getRole("SYS-ADMIN"); $user->addRole($role); $user->save(); // setting permissions if (!$cerberus->permissionExists("users-view")) { $permission = new Cerberus\Model\Permission(); $permission->setName("users-view"); $permission->save(); echo "Permission created: " . $permission->getName() . "<br/>"; } if (!$cerberus->permissionExists("users-edit")) {
/** * Filter the query by a related \Alchemy\Component\Cerberus\Model\Role object * * @param \Alchemy\Component\Cerberus\Model\Role|ObjectCollection $role The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildUserRoleQuery The current query, for fluid interface */ public function filterByRole($role, $comparison = null) { if ($role instanceof \Alchemy\Component\Cerberus\Model\Role) { return $this->addUsingAlias(UserRoleTableMap::COL_ROLE_ID, $role->getId(), $comparison); } elseif ($role instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(UserRoleTableMap::COL_ROLE_ID, $role->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByRole() only accepts arguments of type \\Alchemy\\Component\\Cerberus\\Model\\Role or Collection'); } }