示例#1
0
 /**
  * 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);
 }
示例#2
0
<?php

use Alchemy\Component\Cerberus;
$rootDir = realpath(__DIR__ . "/../../");
$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");
示例#3
0
 /**
  * Exclude object from result
  *
  * @param   ChildUser $user Object to remove from the list of results
  *
  * @return $this|ChildUserQuery The current query, for fluid interface
  */
 public function prune($user = null)
 {
     if ($user) {
         $this->addUsingAlias(UserTableMap::COL_ID, $user->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
示例#4
0
 /**
  * Filter the query by a related \Alchemy\Component\Cerberus\Model\User object
  *
  * @param \Alchemy\Component\Cerberus\Model\User|ObjectCollection $user 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 filterByUser($user, $comparison = null)
 {
     if ($user instanceof \Alchemy\Component\Cerberus\Model\User) {
         return $this->addUsingAlias(UserRoleTableMap::COL_USER_ID, $user->getId(), $comparison);
     } elseif ($user instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(UserRoleTableMap::COL_USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type \\Alchemy\\Component\\Cerberus\\Model\\User or Collection');
     }
 }