PermissionsTablePeer.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class PermissionsTablePeer extends BasePermissionsTablePeer
  3. {
  4. /* by default returns only links which are enabled (set to 'on') */
  5. public static function getLinksForGids($gids,$mode='on')
  6. {
  7. /*$c = new Criteria();
  8. $c->add(PermissionsTablePeer::GID, $gid);
  9. $c->add(PermissionsTablePeer::MODE, $mode);
  10. $permissions = PermissionsTablePeer::doSelect($c);*/
  11. $connection = Propel::getConnection();
  12. $subquery = '';
  13. $n = count($gids)-1; $i = 0;
  14. while ($i<$n)
  15. {
  16. $subquery .= ' '.PermissionsTablePeer::GID.'=\''.$gids[$i].'\' OR ';
  17. $i++;
  18. }
  19. $subquery .= ' '.PermissionsTablePeer::GID.'=\''.$gids[$n].'\'';
  20. $query = 'SELECT %s, %s from %s WHERE %s=\''.$mode.'\' AND ( '.$subquery.' )';
  21. $query = sprintf($query, PermissionsTablePeer::ID, PermissionsTablePeer::LINK_ID,PermissionsTablePeer::TABLE_NAME, PermissionsTablePeer::MODE);
  22. $statement = $connection->prepare($query);
  23. $statement->execute();
  24. $links = array(); $i = 0;
  25. while ($permission = $statement->fetch(PDO::FETCH_NUM))
  26. {
  27. $links[$i] = LinksTablePeer::retrieveByPk($permission[1]); $i++;
  28. }
  29. return $links;
  30. }
  31. /* used in security checking */
  32. public static function getGidsForLink($link)
  33. {
  34. // $c = new Criteria();
  35. // $c->add(PermissionsTablePeer::LINK_ID,$link);
  36. // $permissions = PermissionsTablePeer::doSelect($c);
  37. $connection = Propel::getConnection();
  38. // $query = 'SELECT DISTINCT %s FROM %s WHERE %s = \'security\' and %s = '.$link;
  39. // $query = sprintf($query, PermissionsTablePeer::GID, PermissionsTablePeer::TABLE_NAME, PermissionsTablePeer::MODE, PermissionsTablePeer::LINK_ID);
  40. $query = 'SELECT DISTINCT %s FROM %s WHERE %s = '.$link;
  41. $query = sprintf($query, PermissionsTablePeer::GID, PermissionsTablePeer::TABLE_NAME, PermissionsTablePeer::LINK_ID);
  42. $statement = $connection->prepare($query);
  43. $statement->execute();
  44. $gids = array();
  45. while ($row = $statement->fetch(PDO::FETCH_NUM))
  46. {
  47. $gids[$row[0]] = $row[0];
  48. }
  49. return $gids;
  50. }
  51. /* returns all diferent gids thar are present in the permissions rules except group www = administration group for web-interface */
  52. public static function getGids()
  53. {
  54. $connection = Propel::getConnection();
  55. $query = 'SELECT DISTINCT %s FROM %s';
  56. $query = sprintf($query, PermissionsTablePeer::GID, PermissionsTablePeer::TABLE_NAME);
  57. $statement = $connection->prepare($query);
  58. $statement->execute();
  59. $gids = array();
  60. while ($row = $statement->fetch(PDO::FETCH_NUM))
  61. {
  62. if ($row[0] != 'www')
  63. $gids[$row[0]] = $row[0];
  64. }
  65. return $gids;
  66. }
  67. public static function getModes()
  68. {
  69. return self::$modes;
  70. }
  71. private static $modes = array('on', 'security', 'off');
  72. }