- Timestamp:
- 04/18/12 18:19:41 (12 years ago)
- Location:
- trunk/prototype
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/api/controller.php
r5908 r5971 532 532 case 'create': $return = $params['service']->create( $params['URI'], $params['properties']/*, $criteria*/ ); break; 533 533 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; 535 535 536 536 case 'deleteAll': $return = $params['service']->deleteAll( $params['URI'], $params['properties'], $params['criteria'] ); break; -
trunk/prototype/config/label.ini
r5892 r5971 5 5 addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 6 6 7 [before.read] 8 addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 9 7 10 [before.delete] 11 addVerifyOwnerFilter = modules/mail/interceptors/LabelSecure.php 8 12 clearAllLabeledsOfLabel = modules/mail/interceptors/Helpers.php 9 13 10 14 [before.update] 11 v erifyNameLabel = modules/mail/interceptors/Helpers.php15 validateLabel = modules/mail/interceptors/Helpers.php 12 16 13 17 [before.create] 14 v erifyNameLabel = modules/mail/interceptors/Helpers.php18 validateLabel = modules/mail/interceptors/Helpers.php 15 19 16 20 [PostgreSQL.mapping] 17 id = id21 id = slot 18 22 uid = user_id 19 23 name = name -
trunk/prototype/modules/mail/interceptors/Helpers.php
r5970 r5971 68 68 } 69 69 } 70 71 //label:before.create72 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 }79 70 80 71 public static function in_arrayr($needle, $haystack) { … … 249 240 } 250 241 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 } 251 267 } 252 268 -
trunk/prototype/services/PostgreSQL.php
r5933 r5971 15 15 $justthese = self::parseJustthese($justthese, $map); 16 16 17 return $this->exec ResultSql( '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 ); 18 18 } 19 19 … … 22 22 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 23 23 $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'] ).'\''; 25 25 26 return $this->exec ResultSql( '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 ); 27 27 } 28 28 … … 33 33 } 34 34 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); 37 40 } 38 41 … … 48 51 49 52 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 ); 55 59 56 60 $rs = pg_query( $this->con, $sql ); 57 61 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 66 82 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 ); 73 84 } 74 85 … … 146 157 } 147 158 148 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING id';159 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id'; 149 160 } 150 161 … … 161 172 return 'SET '.implode(',', $d); 162 173 } 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 179 175 private static function parseCriteria( $criteria , &$map , $query = '' ){ 180 176
Note: See TracChangeset
for help on using the changeset viewer.