Esempio n. 1
0
 public function executeProcessNewOrgForm(sfWebRequest $request)
 {
     $f = $request->getParameter("organization");
     $p = Doctrine::getTable('Principal')->findOneByFedid($this->getUser()->getUsername());
     $o = new Organization();
     $o->setName($f["name"]);
     $o->setDescription($f["description"]);
     $o->setCreatedAt(date('Y-m-d H:i:s'));
     $o->save();
     $op = new OrganizationPrincipal();
     $op->setOrganization($o);
     $op->setPrincipal($p);
     $op->save();
     $i = new Invitation();
     $i->setEmail($p->getEmail());
     $i->setOrganization($o);
     $i->setUuid('1');
     $i->setCreatedAt(date('Y-m-d H:i:s'));
     $i->setAcceptAt(date('Y-m-d H:i:s'));
     $i->setCounter(1);
     $i->setInviter($p);
     $i->setPrincipal($p);
     $i->setStatus("accepted");
     $i->save();
     $r = new Role();
     $r->setName($f["role_name"]);
     $r->setOrganization($o);
     $r->setShoworder(0);
     $r->save();
     $o->setDefaultRoleId($r->getId());
     $o->save();
     $this->redirect("show/index?id=" . $o->getId());
 }
Esempio n. 2
0
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) $this->_identifier["id"];
     }
     $this->__load();
     return parent::getId();
 }
Esempio n. 3
0
 public function testNormalRole()
 {
     $role = new Role($this->normalRole->getId());
     $this->player_b->addRole($role->getId());
     $this->assertFalse($role->displayAsLeader());
     $this->assertFalse($role->isProtected());
     $this->assertEquals("Sample Normal Role", $role->getName());
     $this->assertNull($role->getDisplayIcon());
     $this->assertNull($role->getDisplayColor());
     $this->assertEquals("Sample Normal Role", $role->getDisplayName());
     $this->assertEquals(-1, $role->getDisplayOrder());
     $this->assertArrayContainsModel($role, Role::getRoles($this->player_b->getId()));
     $this->wipe($role);
 }
Esempio n. 4
0
 /**
  * @param bool $full
  *
  * @return Role|false
  */
 public function findSingle($full = false)
 {
     $result = parent::findSingle();
     if ($result) {
         $role = new Role($result);
         if ($full === true) {
             $repo = new PermissionRepository($this->db);
             $role->setPermissions($repo->where('role_id', '=', $role->getId())->order('name', 'ASC')->find());
         }
         return $role;
     } else {
         return false;
     }
 }
 /**
  * 
  * @param Role $role
  * @return int id of the Role inserted in base. False if it didn't work.
  */
 public static function flush($role)
 {
     $roleId = $role->getId();
     $roleVar = $role->getRoleName();
     if ($roleId > 0) {
         $sql = 'UPDATE role SET' . 'role_name = ? ' . 'WHERE id_role = ?';
         $params = array('si', &$roleVar, &$roleId);
     } else {
         $sql = 'INSERT INTO role (role_name) VALUES (?)';
         $params = array('s', &$roleVar);
     }
     $idInsert = BaseSingleton::insertOrEdit($sql, $params);
     if ($idInsert !== false && $roleId > 0) {
         $idInsert = $roleId;
     }
     return $idInsert;
 }
 /**
  * Set specific role as default role
  *
  * @param void
  * @return null
  */
 function set_as_default()
 {
     if ($this->request->isSubmitted()) {
         if ($this->active_role->isNew()) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         if ($this->active_role->getType() == ROLE_TYPE_PROJECT) {
             $this->httpError(HTTP_ERR_INVALID_PROPERTIES);
         }
         // if
         ConfigOptions::setValue('default_role', $this->active_role->getId());
         flash_success(':name role has been set as default', array('name' => $this->active_role->getName()));
         $this->redirectTo('admin_roles');
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
 public function getId()
 {
     $this->_load();
     return parent::getId();
 }
Esempio n. 8
0
 /**
  * Declares an association between this object and a Role object.
  *
  * @param      Role $v
  * @return     User The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setRole(Role $v = null)
 {
     if ($v === null) {
         $this->setRoleId(NULL);
     } else {
         $this->setRoleId($v->getId());
     }
     $this->aRole = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Role object, it will not be re-added.
     if ($v !== null) {
         $v->addUser($this);
     }
     return $this;
 }
Esempio n. 9
0
 public static function canAccessDevelopingPage(Role $role)
 {
     switch ($role->getId()) {
         case Role::ID_SYSTEM_ADMIN:
             return true;
     }
     return false;
 }
Esempio n. 10
0
 /**
  * Convenience method to construct a new instance. 
  * 
  * @param \User $callingUser {@link \User} who creates/updates this record.
  * @param \Role $role The target {@link \Role} 
  * @param string $newStatus
  * @return \self
  */
 public static function construct(\User $callingUser, \Role $role, $newStatus)
 {
     $rar = new self($callingUser->getId(), $callingUser->getFullName(), $role->getId(), $role->getStatus(), $newStatus, $role->getRoleType()->getId(), $role->getRoleType()->getName(), $role->getOwnedEntity()->getId(), $role->getOwnedEntity()->getType(), $role->getUser()->getId(), $role->getUser()->getFullName());
     return $rar;
 }
Esempio n. 11
0
 public function testRemoveGroupRoleActionIsProtected()
 {
     $this->logIn($this->john);
     $this->client->request('GET', "/api/groups/{$this->groupOrga->getId()}/roles/{$this->teacherRole->getId()}/remove.json");
     $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
 }
 /**
  * Return number of users using a specific role
  *
  * @param Role $role
  * @return integer
  */
 function countByRole($role)
 {
     return ProjectUsers::count(array('role_id = ?', $role->getId()));
 }
Esempio n. 13
0
 public static function hasRole(Role $role, $targetObject, $user = null)
 {
     $retval = false;
     $db = AbstractDb::getObject();
     $object_class = get_class($targetObject);
     $table = strtolower($object_class) . '_stakeholders';
     $object_id = $db->escapeString($targetObject->getId());
     $roleIdStr = $db->escapeString($role->getId());
     if (!$user) {
         $user = User::getCurrentUser();
     }
     if ($user) {
         $sql = "SELECT * FROM {$table} WHERE object_id = '{$object_id}' AND user_id='{$user->getId()}' AND role_id = '{$roleIdStr}';";
         $rows = null;
         $db->execSql($sql, $rows, false);
         if ($rows) {
             $retval = true;
         }
     }
     return $retval;
 }
Esempio n. 14
0
 /**
  * @see Form::execute()
  */
 function execute($request)
 {
     $userGroupId = $this->getUserGroupId();
     $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
     // Check if we are editing an existing user group or creating another one.
     if ($userGroupId == null) {
         $userGroup = $userGroupDao->newDataObject();
         $role = new Role($this->getData('roleId'));
         $userGroup->setRoleId($role->getId());
         $userGroup->setContextId($this->getPressId());
         $userGroup->setPath($role->getPath());
         $userGroup->setDefault(false);
         $userGroup = $this->_setUserGroupLocaleFields($userGroup, $request);
         $userGroupId = $userGroupDao->insertUserGroup($userGroup);
     } else {
         $userGroup = $userGroupDao->getById($userGroupId);
         $userGroup = $this->_setUserGroupLocaleFields($userGroup, $request);
         $userGroupDao->updateLocaleFields($userGroup);
     }
     // After we have created/edited the user group, we assign/update its stages.
     if ($this->getData('assignedStages')) {
         $this->_setOnDbUserGroupStageAssignment($userGroupId);
     }
 }
Esempio n. 15
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Role $value A Role object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Role $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Esempio n. 16
0
 /**
  * Return id property. (readonly)
  *
  * @author KnowledgeTree Team
  * @access public
  * @return string
  */
 public function getId()
 {
     return $this->role->getId();
 }
Esempio n. 17
0
 /**
  * Declares an association between this object and a Role object.
  *
  * @param      Role $v
  * @return     TeamNote The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setRole(Role $v = null)
 {
     if ($v === null) {
         $this->setRoleId(NULL);
     } else {
         $this->setRoleId($v->getId());
     }
     $this->aRole = $v;
     // Add binding for other direction of this 1:1 relationship.
     if ($v !== null) {
         $v->setTeamNote($this);
     }
     return $this;
 }
Esempio n. 18
0
    /**
    * Function adds a role to database
    *
    * @param sfWebRequest $request
    * @return <type>
    */
    public function executeAddRole(sfWebRequest $request) {
        $data = $request->getPostParameters();
        if(count($data) > 2) { // some rights are set
            unset($data['userrole_title_name']);
            unset($data['hiddenfield']);
            $values = array_keys($data);

            $roleObj = new Role();
            $roleObj->setDescription($request->getParameter('userrole_title_name'));
            $roleObj->save();
            $id = $roleObj->getId();

            foreach($values as $item) {
                $rolecredObj = new CredentialRole();
                $rolecredObj->setRoleId($id);
                $rolecredObj->setCredentialId($item);
                $rolecredObj->save();
            }
        }
        else { // Only Userrole is written in textfield, nothing else
            $obj = new Role();
            $obj->setDescription($request->getParameter('userrole_title_name'));
            $obj->save();
        }
        $this->renderText('{success:true}');
        return sfView::NONE;
    }