public function savesfGuardGroupPermissionList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['sf_guard_group_permission_list'])) { // somebody has unset this widget return; } if (null === $con) { $con = $this->getConnection(); } $c = new Criteria(); $c->add(sfGuardGroupPermissionPeer::PERMISSION_ID, $this->object->getPrimaryKey()); sfGuardGroupPermissionPeer::doDelete($c, $con); $values = $this->getValue('sf_guard_group_permission_list'); if (is_array($values)) { foreach ($values as $value) { $obj = new sfGuardGroupPermission(); $obj->setPermissionId($this->object->getPrimaryKey()); $obj->setGroupId($value); $obj->save(); } } }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = sfGuardGroupPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related sfGuardGroupPermission objects $criteria = new Criteria(sfGuardGroupPermissionPeer::DATABASE_NAME); $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $obj->getId()); $affectedRows += sfGuardGroupPermissionPeer::doDelete($criteria, $con); // delete related sfGuardUserGroup objects $criteria = new Criteria(sfGuardUserGroupPeer::DATABASE_NAME); $criteria->add(sfGuardUserGroupPeer::GROUP_ID, $obj->getId()); $affectedRows += sfGuardUserGroupPeer::doDelete($criteria, $con); } return $affectedRows; }
/** * 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 = sfGuardGroupPermissionPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setGroupId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setPermissionId($arr[$keys[1]]); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this sfGuardGroup is new, it will return * an empty collection; or if this sfGuardGroup has previously * been saved, it will retrieve related sfGuardGroupPermissions from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in sfGuardGroup. */ public function getsfGuardGroupPermissionsJoinsfGuardPermission($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(sfGuardGroupPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collsfGuardGroupPermissions === null) { if ($this->isNew()) { $this->collsfGuardGroupPermissions = array(); } else { $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $this->id); $this->collsfGuardGroupPermissions = sfGuardGroupPermissionPeer::doSelectJoinsfGuardPermission($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $this->id); if (!isset($this->lastsfGuardGroupPermissionCriteria) || !$this->lastsfGuardGroupPermissionCriteria->equals($criteria)) { $this->collsfGuardGroupPermissions = sfGuardGroupPermissionPeer::doSelectJoinsfGuardPermission($criteria, $con, $join_behavior); } } $this->lastsfGuardGroupPermissionCriteria = $criteria; return $this->collsfGuardGroupPermissions; }
/** * Check if a group has a permission given to thier ids * @param Int $group_id * @return Boolean */ public static function groupHasPermission($group_id, $permission_id) { return sfGuardGroupPermissionPeer::retrieveByPK($group_id, $permission_id) ? true : false; }
/** * Retrieve object using using composite pkey values. * @param int $group_id * @param int $permission_id * @param PropelPDO $con * @return sfGuardGroupPermission */ public static function retrieveByPK($group_id, $permission_id, PropelPDO $con = null) { $key = serialize(array((string) $group_id, (string) $permission_id)); if (null !== ($obj = sfGuardGroupPermissionPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(sfGuardGroupPermissionPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(sfGuardGroupPermissionPeer::DATABASE_NAME); $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $group_id); $criteria->add(sfGuardGroupPermissionPeer::PERMISSION_ID, $permission_id); $v = sfGuardGroupPermissionPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
public function executePermissions(sfWebRequest $request) { $module = 'sfGuardUser'; if (!in_array($module, array_keys(sfPlop::getSafePluginModules()))) { $this->redirect('@sf_plop_dashboard'); } if ($request->isMethod(sfRequest::POST)) { if ($request->isXmlHttpRequest()) { $this->setTemplate('ajaxPermissions'); $this->setLayout(false); } $group_id = $request->getParameter('g'); $user_id = $request->getParameter('u'); $permission_id = $request->getParameter('p'); if ($group_id) { $group_exists = sfPlopGuard::groupExists($group_id); if (!$group_exists && $request->isXmlHttpRequest()) { return sfView::ERROR; } else { if (!$group_exists) { $this->redirect('@sf_plop_dashboard_permissions'); } } } if ($user_id) { $user_exists = sfPlopGuard::userExists($user_id); if (!$user_exists && $request->isXmlHttpRequest()) { return sfView::ERROR; } else { if (!$user_exists) { $this->redirect('@sf_plop_dashboard_permissions'); } } } if (isset($group_exists) && isset($user_exists)) { $user_group = sfGuardUserGroupPeer::retrieveByPK($user_id, $group_id); if ($user_group) { $user_group->delete(); } else { $user_group = new sfGuardUsergroup(); $user_group->setUserId($user_id); $user_group->setGroupId($group_id); $user_group->save(); $this->getResponse()->setStatusCode(201); } } if ($permission_id) { if ($permission_id == 'super') { if (!sfPlopGuard::isLastSuperAdminUser($user_id)) { $user = sfGuardUserPeer::retrieveByPK($user_id); if ($user->getIsSuperAdmin()) { $user->setIsSuperAdmin(false); } else { $user->setIsSuperAdmin(true); } $user->save(); } else { $this->getResponse()->setStatusCode(202); return sfView::ERROR; } } else { if (!is_int($permission_id)) { $permission_exists = sfPlopGuard::permissionExists($permission_id); if (!$permission_exists) { $modules = sfPlop::getSafePluginModules(); if ($request->isXmlHttpRequest() && !isset($modules[$permission_id])) { return sfView::ERROR; } elseif (!isset($modules[$permission_id])) { $this->redirect('@sf_plop_dashboard_permissions'); } else { $module = $modules[$permission_id]; } $permission = new sfGuardPermission(); $permission->setName($permission_id); $permission->setDescription($module['name']); $permission->save(); $permission_id = $permission->getId(); $this->getResponse()->setStatusCode(201); } else { $permission_id = sfPlopGuard::getPermission($permission_id)->getId(); } } else { $permission_exists = sfPlopGuard::permissionExists($permission_id); if (!$permission_exists && $request->isXmlHttpRequest()) { return sfView::ERROR; } else { if (!$permission_exists) { $this->redirect('@sf_plop_dashboard_permissions'); } } } if (isset($user_exists)) { $user_permission = sfGuardUserPermissionPeer::retrieveByPK($user_id, $permission_id); if ($user_permission) { $user_permission->delete(); } else { $user_permission = new sfGuardUserPermission(); $user_permission->setUserId($user_id); $user_permission->setPermissionId($permission_id); $user_permission->save(); $this->getResponse()->setStatusCode(201); } } elseif (isset($group_exists)) { $group_permission = sfGuardGroupPermissionPeer::retrieveByPK($group_id, $permission_id); if ($group_permission) { $group_permission->delete(); } else { $group_permission = new sfGuardGroupPermission(); $group_permission->setGroupId($group_id); $group_permission->setPermissionId($permission_id); $group_permission->save(); $this->getResponse()->setStatusCode(201); } } } } if (!$request->isXmlHttpRequest()) { $this->redirect('@sf_plop_dashboard_permissions'); } } $this->groups = sfPlopGuard::getAllGroups(); $this->users = sfPlopGuard::getAllUsers(); $this->permissions = sfPlopGuard::getAllPermissions(); }
public function getsfGuardGroupPermissionsJoinsfGuardPermission($criteria = null, $con = null) { include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardGroupPermissionPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collsfGuardGroupPermissions === null) { if ($this->isNew()) { $this->collsfGuardGroupPermissions = array(); } else { $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $this->getId()); $this->collsfGuardGroupPermissions = sfGuardGroupPermissionPeer::doSelectJoinsfGuardPermission($criteria, $con); } } else { $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $this->getId()); if (!isset($this->lastsfGuardGroupPermissionCriteria) || !$this->lastsfGuardGroupPermissionCriteria->equals($criteria)) { $this->collsfGuardGroupPermissions = sfGuardGroupPermissionPeer::doSelectJoinsfGuardPermission($criteria, $con); } } $this->lastsfGuardGroupPermissionCriteria = $criteria; return $this->collsfGuardGroupPermissions; }
public static function retrieveByPK($group_id, $permission_id, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $criteria = new Criteria(); $criteria->add(sfGuardGroupPermissionPeer::GROUP_ID, $group_id); $criteria->add(sfGuardGroupPermissionPeer::PERMISSION_ID, $permission_id); $v = sfGuardGroupPermissionPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * 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 sfGuardGroupPermission A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { $sql = 'SELECT `GROUP_ID`, `PERMISSION_ID` FROM `sf_guard_group_permission` WHERE `GROUP_ID` = :p0 AND `PERMISSION_ID` = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); $stmt->bindValue(':p1', $key[1], 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 sfGuardGroupPermission(); $obj->hydrate($row); sfGuardGroupPermissionPeer::addInstanceToPool($obj, serialize(array((string) $row[0], (string) $row[1]))); } $stmt->closeCursor(); return $obj; }
/** * Find object by primary key * <code> * $obj = $c->findPk(array(12, 34), $con); * </code> * @param array[$group_id, $permission_id] $key Primary key to use for the query * @param PropelPDO $con an optional connection object * * @return sfGuardGroupPermission|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if (null !== ($obj = sfGuardGroupPermissionPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1])))) && $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); } }