Changeset 5971


Ignore:
Timestamp:
04/18/12 18:19:41 (12 years ago)
Author:
natan
Message:

Ticket #2633 - Implementação da limitação de numero de marcadores por usuario

Location:
trunk/prototype
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/api/controller.php

    r5908 r5971  
    532532                        case 'create': $return = $params['service']->create( $params['URI'], $params['properties']/*, $criteria*/ ); break; 
    533533 
    534                         case 'delete': $return = $params['service']->delete( $params['URI'], $params['properties']/*, $criteria*/ ); break; 
     534                        case 'delete': $return = $params['service']->delete( $params['URI'], $params['properties'], $params['criteria'] ); break; 
    535535 
    536536                        case 'deleteAll': $return = $params['service']->deleteAll( $params['URI'], $params['properties'], $params['criteria'] ); break; 
  • trunk/prototype/config/label.ini

    r5892 r5971  
    55addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 
    66 
     7[before.read] 
     8addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 
     9 
    710[before.delete] 
     11addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 
    812clearAllLabeledsOfLabel = modules/mail/interceptors/Helpers.php 
    913 
    1014[before.update] 
    11 verifyNameLabel = modules/mail/interceptors/Helpers.php 
     15validateLabel = modules/mail/interceptors/Helpers.php 
    1216 
    1317[before.create] 
    14 verifyNameLabel = modules/mail/interceptors/Helpers.php 
     18validateLabel = modules/mail/interceptors/Helpers.php 
    1519 
    1620[PostgreSQL.mapping] 
    17 id = id 
     21id = slot 
    1822uid = user_id 
    1923name = name 
  • trunk/prototype/modules/mail/interceptors/Helpers.php

    r5970 r5971  
    6868                } 
    6969        } 
    70          
    71         //label:before.create 
    72         public function verifyNameLabel(&$uri , &$params , &$criteria , $original){ 
    73                 $nameLabel = $params['name']; 
    74                 $Labels = Controller::find(array('concept' => 'label'), false, array('filter' => array('i=', 'name', $nameLabel) )); 
    75                 if($Labels){ 
    76                         Throw new Exception('Já existe um marcador com esse nome.'); 
    77                 } 
    78         } 
    7970                 
    8071        public static function in_arrayr($needle, $haystack) { 
     
    249240        }        
    250241 
     242        //label:before.create 
     243        public function validateLabel(&$uri , &$params , &$criteria , $original){ 
     244 
     245                if( !!Controller::find( array('concept' => 'label'), false, array('filter' => array('i=', 'name', $params['name'])) ) ) 
     246                { 
     247                    throw new Exception('Já existe um marcador com esse nome.'); 
     248                } 
     249 
     250                $used = Controller::service('PostgreSQL')->execSql( 'SELECT count(slot) as used from expressomail_label where user_id = '.Config::me('uidNumber'), true ); 
     251 
     252                if( $used['used'] === '0' ) 
     253                { 
     254                    $params['id'] = '1'; 
     255                    return; 
     256                } 
     257 
     258                $slot = Controller::service('PostgreSQL')->execSql( 'SELECT label.slot + 1 as id FROM expressomail_label as label, phpgw_config as config WHERE label.user_id = '.Config::me('uidNumber').' AND config.config_name = \'expressoMail_limit_labels\' AND label.slot <= config.config_value::integer AND ( SELECT count(slot) FROM expressomail_label WHERE slot = label.slot + 1 AND user_id = '.Config::me('uidNumber').' ) = 0 limit 1', true ); 
     259 
     260                if( empty( $slot ) ) 
     261                { 
     262                    throw new Exception('Nenhum slot disponivel.'); 
     263                } 
     264 
     265                $params['id'] = $slot['id']; 
     266        } 
    251267} 
    252268 
  • trunk/prototype/services/PostgreSQL.php

    r5933 r5971  
    1515        $justthese = self::parseJustthese($justthese, $map); 
    1616 
    17         return $this->execResultSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .' '.$criteria ); 
     17        return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .' '.$criteria ); 
    1818    } 
    1919 
     
    2222      $map =  Config::get($uri['concept'], 'PostgreSQL.mapping');    
    2323      $justthese = self::parseJustthese($justthese, $map); 
    24       $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE id = \''.addslashes( $uri['id'] ).'\'') : ' WHERE id = \''.addslashes( $uri['id'] ).'\''; 
     24      $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\''; 
    2525    
    26       return $this->execResultSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .$criteria , true ); 
     26      return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .$criteria , true ); 
    2727    } 
    2828         
     
    3333    } 
    3434 
    35     public function delete ( $uri, $justthese = false ){ 
    36             return $this->execSql('DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).' WHERE id = '.addslashes($uri['id'])); 
     35    public function delete ( $uri, $justthese = false, $criteria = false ){ 
     36            $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 
     37            if(!self::parseCriteria ( $criteria , $map)) return false; //Validador para não apagar tabela inteira 
     38            $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\''; 
     39            return $this->execSql('DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).$criteria); 
    3740    } 
    3841 
     
    4851 
    4952    public function create ( $uri,  $data ){     
    50             return $this->execResultSql( 'INSERT INTO '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseInsertData( $data , $uri['concept'] ), true ); 
    51     } 
    52  
    53     private function execSql( $sql ){ 
    54             if(!$this->con)     $this->open( $this->config ); 
     53            return $this->execSql( 'INSERT INTO '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseInsertData( $data , $uri['concept'] ), true ); 
     54    } 
     55 
     56    public function execSql( $sql, $unique = false ) 
     57    { 
     58            if(!$this->con) $this->open( $this->config ); 
    5559 
    5660            $rs = pg_query( $this->con, $sql ); 
    5761 
    58             if ( !$rs ){ 
    59                     $this->error = pg_last_error ( $this->con ); 
    60                     return false; 
    61             } 
    62  
    63             return $rs; 
    64     } 
    65          
     62            if( is_bool( $rs ) ) 
     63            { 
     64                if ( !$rs ) 
     65                  $this->error = pg_last_error ( $this->con ); 
     66 
     67                return( $rs ); 
     68            } 
     69 
     70            if( pg_num_rows( $rs ) <= 0 ) 
     71                return array(); 
     72 
     73            $return = array(); 
     74 
     75            while( $row = pg_fetch_assoc( $rs ) ) 
     76                $return[] = $row; 
     77 
     78            return( $unique ? $return[0] : $return ); 
     79    } 
     80 
     81    //@DEPRECATED 
    6682    public function execResultSql( $sql, $unique = false ){ 
    67             $rs = $this->execSql( $sql ); 
    68  
    69             if( $rs && $rs > 0 ) 
    70                 return self::parseSelectResult( $rs , $unique ); 
    71  
    72             return $rs; 
     83            return $this->execSql( $sql, $unique ); 
    7384    } 
    7485 
     
    146157            } 
    147158             
    148             return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING id'; 
     159            return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id'; 
    149160    } 
    150161         
     
    161172            return 'SET '.implode(',', $d); 
    162173    } 
    163          
    164     private static function parseSelectResult( $result , $unique = false){ 
    165              
    166             $return = array(); 
    167              
    168             if  (!$result) return false; 
    169             if (pg_num_rows($result) === 0) return $return; 
    170             else 
    171               while( $row = pg_fetch_assoc( $result )) 
    172                       $return[] = $row;  
    173              
    174             if($unique === true) return $return[0]; 
    175              
    176             return $return; 
    177     } 
    178          
     174 
    179175    private static function parseCriteria( $criteria  , &$map , $query = '' ){                
    180176         
Note: See TracChangeset for help on using the changeset viewer.