public function executeSave(sfWebRequest $request) { $role = RolePeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($role); $perms = $request->getParameter('permissions'); if (!is_array($perms)) { $perms = array(); } # remove rights $c = new Criteria(); $c->add(RolePermissionPeer::ROLE_ID, $role->getId()); RolePermissionPeer::doDelete($c); # save new rights foreach ($perms as $perm) { $role_permission = new RolePermission(); $role_permission->setPermissionId($perm); $role_permission->setRoleId($role->getId()); $role_permission->save(); } return $this->renderText('Rights for \'' . $role->getTitle() . '\' have successfully saved!'); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = RolePermissionPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setRoleId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setPermissionId($arr[$keys[1]]); } }
/** * Retrieve object using using composite pkey values. * @param int $role_id @param int $permission_id * @param PropelPDO $con * @return RolePermission */ public static function retrieveByPK($role_id, $permission_id, PropelPDO $con = null) { $key = serialize(array((string) $role_id, (string) $permission_id)); if (null !== ($obj = RolePermissionPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(RolePermissionPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(RolePermissionPeer::DATABASE_NAME); $criteria->add(RolePermissionPeer::ROLE_ID, $role_id); $criteria->add(RolePermissionPeer::PERMISSION_ID, $permission_id); $v = RolePermissionPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }