/** * Get the associated sfGuardPermission object * * @param PropelPDO Optional Connection object. * @return sfGuardPermission The associated sfGuardPermission object. * @throws PropelException */ public function getsfGuardPermission(PropelPDO $con = null) { if ($this->asfGuardPermission === null && $this->permission_id !== null) { $this->asfGuardPermission = sfGuardPermissionPeer::retrieveByPk($this->permission_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->asfGuardPermission->addsfGuardUserPermissions($this); */ } return $this->asfGuardPermission; }
public function addPermissionByName($name, $con = null) { $permission = sfGuardPermissionPeer::retrieveByName($name); if (!$permission) { throw new Exception(sprintf('The permission "%s" does not exist.', $name)); } $up = new sfGuardUserPermission(); $up->setsfGuardUser($this); $up->setPermissionId($permission->getId()); $up->save($con); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(sfGuardPermissionPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(sfGuardPermissionPeer::DATABASE_NAME); $criteria->add(sfGuardPermissionPeer::ID, $pks, Criteria::IN); $objs = sfGuardPermissionPeer::doSelect($criteria, $con); } return $objs; }
public function getsfGuardPermission($con = null) { if ($this->asfGuardPermission === null && $this->permission_id !== null) { include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardPermissionPeer.php'; $this->asfGuardPermission = sfGuardPermissionPeer::retrieveByPK($this->permission_id, $con); } return $this->asfGuardPermission; }
/** * Get the associated sfGuardPermission object * * @param PropelPDO Optional Connection object. * @return sfGuardPermission The associated sfGuardPermission object. * @throws PropelException */ public function getsfGuardPermission(PropelPDO $con = null) { if ($this->asfGuardPermission === null && $this->permission_id !== null) { $c = new Criteria(sfGuardPermissionPeer::DATABASE_NAME); $c->add(sfGuardPermissionPeer::ID, $this->permission_id); $this->asfGuardPermission = sfGuardPermissionPeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->asfGuardPermission->addsfGuardGroupPermissions($this); */ } return $this->asfGuardPermission; }
/** * Selects a collection of sfGuardUserPermission objects pre-filled with all related objects except sfGuardUser. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of sfGuardUserPermission objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptsfGuardUser(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } sfGuardUserPermissionPeer::addSelectColumns($criteria); $startcol2 = sfGuardUserPermissionPeer::NUM_COLUMNS - sfGuardUserPermissionPeer::NUM_LAZY_LOAD_COLUMNS; sfGuardPermissionPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (sfGuardPermissionPeer::NUM_COLUMNS - sfGuardPermissionPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(sfGuardUserPermissionPeer::PERMISSION_ID, sfGuardPermissionPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BasesfGuardUserPermissionPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = sfGuardUserPermissionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = sfGuardUserPermissionPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = sfGuardUserPermissionPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); sfGuardUserPermissionPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined sfGuardPermission rows $key2 = sfGuardPermissionPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = sfGuardPermissionPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = sfGuardPermissionPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); sfGuardPermissionPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (sfGuardUserPermission) to the collection in $obj2 (sfGuardPermission) $obj2->addsfGuardUserPermission($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function executeEditWin(sfWebRequest $request) { $this->sf_guard_permission = sfGuardPermissionPeer::retrieveByPK($request->getParameter('id')); $this->form = $this->configuration->getForm($this->sf_guard_permission); //die ('$request->getParameter(id): '.$request->getParameter('id')); }
/** * Get a permission given to an id or a name. * @param Mixed $permission * @return Boolean */ public static function getPermission($permission) { $return = sfGuardPermissionPeer::retrieveByPK($permission); if (!$return) { $return = sfGuardPermissionPeer::retrieveByName($permission); } return $return; }
/** * 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 = sfGuardPermissionPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return sfGuardPermission A model object, or null if the key is not found * @throws PropelException */ protected function findPkSimple($key, $con) { $sql = 'SELECT `ID`, `NAME`, `DESCRIPTION` FROM `sf_guard_permission` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new sfGuardPermission(); $obj->hydrate($row); sfGuardPermissionPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
public function grantProjectGroupPermission($group_name, $permission_name) { $permission = sfGuardPermissionPeer::retrieveByName($this->getUuid() . '-' . $permission_name); $group = sfGuardGroupPeer::retrieveByName($this->getUuid() . '-' . $group_name); if ($permission == null) { sfContext::getInstance()->getLogger()->info('permission not found: [' . $this->getUuid() . $permission_name . ']'); return false; } elseif ($group == null) { sfContext::getInstance()->getLogger()->info('group not found: [' . $this->getUuid() . $group_name . ']'); return false; } // TODO: make sure that the group permission name does not already exist $groupPermission = new sfGuardGroupPermission(); $groupPermission->setGroupId($group->getPrimaryKey()); $groupPermission->setPermissionId($permission->getId()); $groupPermission->save(); sfContext::getInstance()->getLogger()->info('group permission saved: [' . $this->getUuid() . $group_name . ']:[' . $this->getUuid() . $permission_name . ']'); }
public static function doSelectJoinAllExceptsfGuardGroup(Criteria $c, $con = null) { $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } sfGuardGroupPermissionPeer::addSelectColumns($c); $startcol2 = sfGuardGroupPermissionPeer::NUM_COLUMNS - sfGuardGroupPermissionPeer::NUM_LAZY_LOAD_COLUMNS + 1; sfGuardPermissionPeer::addSelectColumns($c); $startcol3 = $startcol2 + sfGuardPermissionPeer::NUM_COLUMNS; $c->addJoin(sfGuardGroupPermissionPeer::PERMISSION_ID, sfGuardPermissionPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = sfGuardGroupPermissionPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = sfGuardPermissionPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getsfGuardPermission(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addsfGuardGroupPermission($obj1); break; } } if ($newObject) { $obj2->initsfGuardGroupPermissions(); $obj2->addsfGuardGroupPermission($obj1); } $results[] = $obj1; } return $results; }
protected function addSortCriteria($criteria) { if ($this->getRequestParameter('sort') == '') { return; } $column = sfGuardPermissionPeer::translateFieldName(sfInflector::camelize($this->getRequestParameter('sort')), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); if ('asc' == strtolower($this->getRequestParameter('dir'))) { $criteria->addAscendingOrderByColumn($column); } else { $criteria->addDescendingOrderByColumn($column); } }
public function configure() { unset($this['sf_guard_user_group_list']); $this->setWidget('sf_guard_group_permission_list', new sfWidgetFormSelectDoubleList(array('choices' => sfGuardPermissionPeer::getChoices(), 'label_unassociated' => 'No seleccionados', 'label_associated' => 'Seleccionados', 'associate' => '<img src="../../../sfFormExtraPlugin/images/next.png" alt="Seleccionar" />', 'unassociate' => '<img src="../../../sfFormExtraPlugin/images/previous.png" alt="Deseleccionar" />'))); $this->widgetSchema['sf_guard_group_permission_list']->setLabel('Permissions'); }
/** * Find object by primary key * Use instance pooling to avoid a database query if the object exists * <code> * $obj = $c->findPk(12, $con); * </code> * @param mixed $key Primary key to use for the query * @param PropelPDO $con an optional connection object * * @return sfGuardPermission|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if (null !== ($obj = sfGuardPermissionPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) { // the object is alredy in the instance pool return $obj; } else { // the object has not been requested yet, or the formatter is not an object formatter $criteria = $this->isKeepQuery() ? clone $this : $this; $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con); return $criteria->getFormatter()->init($criteria)->formatOne($stmt); } }
public function executeChangeRole($request) { $this->form = new ChangeRoleForm(array(), array('actual_user' => $this->getUser())); $values = $request->getParameter($this->form->getName()); if (isset($values['roles']) && !empty($values['roles'])) { $this->getUser()->clearCredentials(); $new_login_role = sfGuardGroupPeer::retrieveByPK($values['roles']); $this->getUser()->setLoginRole($new_login_role->getName()); //die(var_dump($this->getUser()->getAttribute('login_role'))); $this->getUser()->addCredentials(sfGuardPermissionPeer::retrieveAllCredentialsForARole(sfGuardGroupPeer::retrieveByName($this->getUser()->getLoginRole()))); } return $this->redirect("mainBackend/index"); }