Passed
Push — 17.1 ( 6ec951...0f0060 )
by Ralf
09:52
created
api/src/Contacts/Sql.php 1 patch
Braces   +144 added lines, -37 removed lines patch added patch discarded remove patch
@@ -112,11 +112,20 @@  discard block
 block discarded – undo
112 112
 		$filter = is_array($param['col_filter']) ? $param['col_filter'] : array();
113 113
 		$join = '';
114 114
 		$op = 'OR';
115
-		if (isset($param['op']) && !empty($param['op'])) $op = $param['op'];
115
+		if (isset($param['op']) && !empty($param['op']))
116
+		{
117
+			$op = $param['op'];
118
+		}
116 119
 		$advanced_search = false;
117
-		if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true;
120
+		if (isset($param['advanced_search']) && !empty($param['advanced_search']))
121
+		{
122
+			$advanced_search = true;
123
+		}
118 124
 		$wildcard ='%';
119
-		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:'');
125
+		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard'])))
126
+		{
127
+			$wildcard = ($param['wildcard']?$param['wildcard']:'');
128
+		}
120 129
 
121 130
 		// fix cat_id filter to search in comma-separated multiple cats and return subcats
122 131
 		if ($filter['cat_id'])
@@ -134,7 +143,11 @@  discard block
 block discarded – undo
134 143
 			// we have no private grants in addressbook at the moment, they have then to be added here too
135 144
 			if ($param['owner'])
136 145
 			{
137
-				if (!$this->grants[(int) $filter['owner']]) return false;	// we have no access to that addressbook
146
+				if (!$this->grants[(int) $filter['owner']])
147
+				{
148
+					return false;
149
+				}
150
+				// we have no access to that addressbook
138 151
 
139 152
 				$filter['owner'] = $param['owner'];
140 153
 				$filter['private'] = 0;
@@ -223,7 +236,10 @@  discard block
 block discarded – undo
223 236
 		$rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/,
224 237
 			array($param['start'],$param['num_rows']),$filter,$join);
225 238
 
226
-		if (!$rows) return false;
239
+		if (!$rows)
240
+		{
241
+			return false;
242
+		}
227 243
 
228 244
 		// query the values for *_count == 1, to display them instead
229 245
 		$filter['org_name'] = $orgs = array();
@@ -298,11 +314,20 @@  discard block
 block discarded – undo
298 314
 		$join = 'JOIN ' . $this->table_name . ' AS a2 ON ';
299 315
 		$filter = $param['col_filter'];
300 316
 		$op = 'OR';
301
-		if (isset($param['op']) && !empty($param['op'])) $op = $param['op'];
317
+		if (isset($param['op']) && !empty($param['op']))
318
+		{
319
+			$op = $param['op'];
320
+		}
302 321
 		$advanced_search = false;
303
-		if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true;
322
+		if (isset($param['advanced_search']) && !empty($param['advanced_search']))
323
+		{
324
+			$advanced_search = true;
325
+		}
304 326
 		$wildcard ='%';
305
-		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:'');
327
+		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard'])))
328
+		{
329
+			$wildcard = ($param['wildcard']?$param['wildcard']:'');
330
+		}
306 331
 
307 332
 		// fix cat_id filter to search in comma-separated multiple cats and return subcats
308 333
 		if ($param['cat_id'])
@@ -333,7 +358,11 @@  discard block
 block discarded – undo
333 358
 			// we have no private grants in addressbook at the moment, they have then to be added here too
334 359
 			if (array_key_exists('owner', $param))
335 360
 			{
336
-				if (!$this->grants[(int) $param['owner']]) return false;	// we have no access to that addressbook
361
+				if (!$this->grants[(int) $param['owner']])
362
+				{
363
+					return false;
364
+				}
365
+				// we have no access to that addressbook
337 366
 
338 367
 				$filter[$this->table_name.'.contact_owner'] = $param['owner'];
339 368
 				$filter[$this->table_name.'.private'] = 0;
@@ -473,7 +502,10 @@  discard block
 block discarded – undo
473 502
 	 */
474 503
 	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false)
475 504
 	{
476
-		if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n";
505
+		if ((int) $this->debug >= 4)
506
+		{
507
+			echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n";
508
+		}
477 509
 		//error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')");
478 510
 
479 511
 		$owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null);
@@ -522,7 +554,10 @@  discard block
 block discarded – undo
522 554
 				// no grants for selected owner/addressbook
523 555
 				if (!array_intersect((array)$filter['owner'],array_keys($this->grants)))
524 556
 				{
525
-					if (!isset($groupmember_sql)) return false;
557
+					if (!isset($groupmember_sql))
558
+					{
559
+						return false;
560
+					}
526 561
 					$filter[] = substr($groupmember_sql,4);
527 562
 					unset($filter['owner']);
528 563
 				}
@@ -574,13 +609,16 @@  discard block
 block discarded – undo
574 609
 				$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER);
575 610
 			}
576 611
 		}
577
-		if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by))	// search also adds a join for custom fields!
612
+		if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by))
613
+		{
614
+			// search also adds a join for custom fields!
578 615
 		{
579 616
 			switch(gettype($only_keys))
580 617
 			{
581 618
 				case 'boolean':
582 619
 					// Correctly handled by parent class
583 620
 					break;
621
+		}
584 622
 				case 'string':
585 623
 					$only_keys = explode(',',$only_keys);
586 624
 					// fall through
@@ -590,13 +628,23 @@  discard block
 block discarded – undo
590 628
 			if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui",
591 629
 				$order_by, $all_matches, PREG_SET_ORDER))
592 630
 			{
593
-				if (!is_array($extra_cols))	$extra_cols = $extra_cols ? explode(',',$extra_cols) : array();
631
+				if (!is_array($extra_cols))
632
+				{
633
+					$extra_cols = $extra_cols ? explode(',',$extra_cols) : array();
634
+				}
594 635
 				foreach($all_matches as $matches)
595 636
 				{
596 637
 					$table = '';
597 638
 					$column = $matches[1];
598
-					if ($column[0] == '#') continue;	// order by custom field is handeled in so_sql_cf anyway
599
-					if (($key = array_search($column, $this->db_cols)) !== false) $column = $key;
639
+					if ($column[0] == '#')
640
+					{
641
+						continue;
642
+					}
643
+					// order by custom field is handeled in so_sql_cf anyway
644
+					if (($key = array_search($column, $this->db_cols)) !== false)
645
+					{
646
+						$column = $key;
647
+					}
600 648
 					if (strpos($column,'.') === false)
601 649
 					{
602 650
 						$table = $column == $this->extra_value ? $this->extra_table : $this->table_name;
@@ -611,10 +659,13 @@  discard block
 block discarded – undo
611 659
 					}
612 660
 					$extra_cols[] = $table.$column.' '.$matches[2];
613 661
 					//_debug_array($matches);
614
-					if (!empty($order_by) && $table) // postgres requires explizit order by
662
+					if (!empty($order_by) && $table)
663
+					{
664
+						// postgres requires explizit order by
615 665
 					{
616 666
 						$order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by);
617 667
 					}
668
+					}
618 669
 				}
619 670
 				//_debug_array($order_by); _debug_array($extra_cols);
620 671
 			}
@@ -640,7 +691,11 @@  discard block
 block discarded – undo
640 691
 		}
641 692
 		$rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
642 693
 
643
-		if ($start === false) $this->total = is_array($rows) ? count($rows) : 0;	// so_sql sets total only for $start !== false!
694
+		if ($start === false)
695
+		{
696
+			$this->total = is_array($rows) ? count($rows) : 0;
697
+		}
698
+		// so_sql sets total only for $start !== false!
644 699
 
645 700
 		return $rows;
646 701
 	}
@@ -682,7 +737,10 @@  discard block
 block discarded – undo
682 737
 		$cat_filter = array();
683 738
 		foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat)
684 739
 		{
685
-			if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'";
740
+			if (is_numeric($cat))
741
+			{
742
+				$cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'";
743
+			}
686 744
 		}
687 745
 		return $cat_filter;
688 746
 	}
@@ -695,10 +753,13 @@  discard block
 block discarded – undo
695 753
 	 */
696 754
 	function change_owner($account_id,$new_owner)
697 755
 	{
698
-		if (!$new_owner)	// otherwise we would create an account (contact_owner==0)
756
+		if (!$new_owner)
757
+		{
758
+			// otherwise we would create an account (contact_owner==0)
699 759
 		{
700 760
 			throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!");
701 761
 		}
762
+		}
702 763
 		// contacts
703 764
 		$this->db->update($this->table_name,array(
704 765
 			'contact_owner' => $new_owner,
@@ -743,7 +804,10 @@  discard block
 block discarded – undo
743 804
 		foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__,
744 805
 			false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row)
745 806
 		{
746
-			if ($member_attr) $row['members'] = array();
807
+			if ($member_attr)
808
+			{
809
+				$row['members'] = array();
810
+			}
747 811
 			$lists[$row['list_id']] = $row;
748 812
 		}
749 813
 		if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name')))
@@ -806,9 +870,15 @@  discard block
 block discarded – undo
806 870
 	function add_list($keys,$owner,$contacts=array(),array &$data=array())
807 871
 	{
808 872
 		//error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace());
809
-		if (!$keys && !$data || !(int)$owner) return false;
873
+		if (!$keys && !$data || !(int)$owner)
874
+		{
875
+			return false;
876
+		}
810 877
 
811
-		if ($keys && !is_array($keys)) $keys = array('list_name' => $keys);
878
+		if ($keys && !is_array($keys))
879
+		{
880
+			$keys = array('list_name' => $keys);
881
+		}
812 882
 		if ($keys)
813 883
 		{
814 884
 			$keys['list_owner'] = $owner;
@@ -828,9 +898,15 @@  discard block
 block discarded – undo
828 898
 		}
829 899
 		$data['list_modified'] = time();
830 900
 		$data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
831
-		if (!$data['list_id']) unset($data['list_id']);
901
+		if (!$data['list_id'])
902
+		{
903
+			unset($data['list_id']);
904
+		}
832 905
 
833
-		if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false;
906
+		if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__))
907
+		{
908
+			return false;
909
+		}
834 910
 
835 911
 		if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) &&
836 912
 			(!isset($data['list_uid']) || !isset($data['list_carddav_name'])))
@@ -848,7 +924,10 @@  discard block
 block discarded – undo
848 924
 
849 925
 			$this->add2list($list_id,$contacts,array());
850 926
 		}
851
-		if ($keys) $data += $keys;
927
+		if ($keys)
928
+		{
929
+			$data += $keys;
930
+		}
852 931
 		//error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id));
853 932
 		return $list_id;
854 933
 	}
@@ -863,7 +942,10 @@  discard block
 block discarded – undo
863 942
 	 */
864 943
 	function add2list($contact,$list,array $existing=null)
865 944
 	{
866
-		if (!(int)$list || !is_array($contact) && !(int)$contact) return false;
945
+		if (!(int)$list || !is_array($contact) && !(int)$contact)
946
+		{
947
+			return false;
948
+		}
867 949
 
868 950
 		if (!is_array($existing))
869 951
 		{
@@ -905,7 +987,10 @@  discard block
 block discarded – undo
905 987
 	 */
906 988
 	function remove_from_list($contact,$list=null)
907 989
 	{
908
-		if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false;
990
+		if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact)
991
+		{
992
+			return false;
993
+		}
909 994
 
910 995
 		$where = array(
911 996
 			'contact_id' => $contact,
@@ -947,7 +1032,10 @@  discard block
 block discarded – undo
947 1032
 	 */
948 1033
 	function delete_list($list)
949 1034
 	{
950
-		if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false;
1035
+		if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__))
1036
+		{
1037
+			return false;
1038
+		}
951 1039
 
952 1040
 		$this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__);
953 1041
 
@@ -962,7 +1050,10 @@  discard block
 block discarded – undo
962 1050
 	 */
963 1051
 	function lists_ctag($owner=null)
964 1052
 	{
965
-		if (is_null($owner)) $owner = array_keys($this->grants);
1053
+		if (is_null($owner))
1054
+		{
1055
+			$owner = array_keys($this->grants);
1056
+		}
966 1057
 
967 1058
 		if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner),
968 1059
 			__LINE__,__FILE__)->fetchColumn()))
@@ -982,9 +1073,12 @@  discard block
 block discarded – undo
982 1073
 	 */
983 1074
 	function read($keys,$extra_cols='',$join='')
984 1075
 	{
985
-		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) {
1076
+		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1077
+		{
986 1078
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
987
-		} else {
1079
+		}
1080
+		else
1081
+		{
988 1082
 			$minimum_uid_length = 8;
989 1083
 		}
990 1084
 
@@ -1004,7 +1098,8 @@  discard block
 block discarded – undo
1004 1098
 
1005 1099
 		// enforce a minium uid strength
1006 1100
 		if (is_array($contact) && (!isset($contact['uid'])
1007
-				|| strlen($contact['uid']) < $minimum_uid_length)) {
1101
+				|| strlen($contact['uid']) < $minimum_uid_length))
1102
+		{
1008 1103
 			parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id'])));
1009 1104
 		}
1010 1105
 		return $contact;
@@ -1021,19 +1116,28 @@  discard block
 block discarded – undo
1021 1116
 	{
1022 1117
 		unset($extra_where);	// not used, but required by function signature
1023 1118
 
1024
-		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) {
1119
+		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1120
+		{
1025 1121
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1026
-		} else {
1122
+		}
1123
+		else
1124
+		{
1027 1125
 			$minimum_uid_length = 8;
1028 1126
 		}
1029 1127
 
1030
-		if (is_array($keys) && count($keys)) $this->data_merge($keys);
1128
+		if (is_array($keys) && count($keys))
1129
+		{
1130
+			$this->data_merge($keys);
1131
+		}
1031 1132
 
1032 1133
 		$new_entry = !$this->data['id'];
1033 1134
 
1034
-		if (isset($this->data['etag']))		// do we have an etag in the data to write
1135
+		if (isset($this->data['etag']))
1136
+		{
1137
+			// do we have an etag in the data to write
1035 1138
 		{
1036 1139
 			$etag = $this->data['etag'];
1140
+		}
1037 1141
 			unset($this->data['etag']);
1038 1142
 			if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag))))
1039 1143
 			{
@@ -1105,7 +1209,10 @@  discard block
 block discarded – undo
1105 1209
 	 */
1106 1210
 	function read_list($list)
1107 1211
 	{
1108
-		if (!$list) return false;
1212
+		if (!$list)
1213
+		{
1214
+			return false;
1215
+		}
1109 1216
 
1110 1217
 		return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch();
1111 1218
 	}
Please login to merge, or discard this patch.