diff options
author | Georg Ehrke <ownclouddev@georgswebsite.de> | 2012-02-22 10:20:58 +0100 |
---|---|---|
committer | Georg Ehrke <ownclouddev@georgswebsite.de> | 2012-02-22 10:20:58 +0100 |
commit | d20b8399c395605da8a5c908c21963f1f4bdca97 (patch) | |
tree | 847c2a95a872a252d406c5837a3c9994ec0abb67 /apps/calendar/lib | |
parent | 3d8d6d718b65a972648ce7678cda13b2e1117272 (diff) | |
download | nextcloud-server-d20b8399c395605da8a5c908c21963f1f4bdca97.tar.gz nextcloud-server-d20b8399c395605da8a5c908c21963f1f4bdca97.zip |
clean up sql commands in OC_Calendar_Share
Diffstat (limited to 'apps/calendar/lib')
-rw-r--r-- | apps/calendar/lib/share.php | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/apps/calendar/lib/share.php b/apps/calendar/lib/share.php index be2b440c647..621ff8ce217 100644 --- a/apps/calendar/lib/share.php +++ b/apps/calendar/lib/share.php @@ -18,24 +18,10 @@ class OC_Calendar_Share{ * @return: (array) $return - information about calendars */ public static function allSharedwithuser($userid, $type, $active=null, $permission=null){ - $group_where = ''; - $groups = OC_Group::getUserGroups($userid); - $i = 0; - foreach($groups as $group){ - if($i == 0){ - $group_where = 'OR ('; - }else{ - $group_where .= ' OR '; - } - $group_where .= ' (share = \'' . $group . '\' AND sharetype = \'group\') '; - $i++; - } - $permission_where = ''; - if(!is_null($permission)){ - $permission_where = 'AND permissions = '; - $permission_where .= ($permission=='rw')?'1':'0'; - } - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = \'user\') ' . $group_where . ') AND owner <> ? ' . $permission_where . ' ' . ((!is_null($active) && $active)?' AND active = 1)':')')); + $group_where = self::group_sql(OC_Group::getUserGroups($userid)); + $permission_where = self::permission_sql($permission); + $active_where = self::active_sql($active); + $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') AND owner <> ? ' . $permission_where . ' ' . $active_where . ')'); $result = $stmt->execute(array($userid, $userid)); $return = array(); while( $row = $result->fetchRow()){ @@ -157,7 +143,7 @@ class OC_Calendar_Share{ * @param: (string) $type - use const self::CALENDAR or self::EVENT * @return (bool) */ - private static function is_already_shared($owner, $share, $sharetype, $id, $type){ + public static function is_already_shared($owner, $share, $sharetype, $id, $type){ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE owner = ? AND share = ? AND sharetype = ? AND ' . $type . 'id = ?'); $result = $stmt->execute(array($owner, $share, $sharetype, $id)); if($result->numRows() > 0){ @@ -165,4 +151,34 @@ class OC_Calendar_Share{ } return false; } + private static function group_sql($groups){ + $group_where = ''; + $i = 0; + foreach($groups as $group){ + if($i == 0){ + $group_where = 'OR ('; + }else{ + $group_where .= ' OR '; + } + $group_where .= ' (share = "' . $group . '" AND sharetype = "group") '; + $i++; + } + return $group_where; + } + private static function permission_sql($permission = null){ + $permission_where = ''; + if(!is_null($permission)){ + $permission_where = 'AND permissions = '; + $permission_where .= ($permission=='rw')?'1':'0'; + } + return $permission_where; + } + private static function active_sql($active = null){ + $active_where = ''; + if(!is_null($active)){ + $active_where = 'AND active = '; + $active_where .= (!is_null($active) && $active)?'1':'0'; + } + return $active_where; + } }
\ No newline at end of file |