@@ -1056,6 +1056,62 @@ public function doesNotMatchKeyInQuery($key, $queryKey, $query)
10561056 * @return ParseQuery The query that is the OR of the passed in queries.
10571057 */
10581058 public static function orQueries ($ queryObjects )
1059+ {
1060+ $ className = self ::_matchClassName ($ queryObjects );
1061+ $ query = new self ($ className );
1062+ $ query ->_or ($ queryObjects );
1063+
1064+ return $ query ;
1065+ }
1066+
1067+ /**
1068+ * Constructs a ParseQuery object that is the NOR of the passed in queries objects.
1069+ * All queries must have same class name.
1070+ *
1071+ * @param array $queryObjects Array of ParseQuery objects to NOR.
1072+ *
1073+ * @throws \Exception If all queries don't have same class.
1074+ *
1075+ * @return ParseQuery The query that is the NOR of the passed in queries.
1076+ */
1077+ public static function norQueries ($ queryObjects )
1078+ {
1079+ $ className = self ::_matchClassName ($ queryObjects );
1080+ $ query = new self ($ className );
1081+ $ query ->_nor ($ queryObjects );
1082+
1083+ return $ query ;
1084+ }
1085+
1086+ /**
1087+ * Constructs a ParseQuery object that is the AND of the passed in queries objects.
1088+ * All queries must have same class name.
1089+ *
1090+ * @param array $queryObjects Array of ParseQuery objects to AND.
1091+ *
1092+ * @throws \Exception If all queries don't have same class.
1093+ *
1094+ * @return ParseQuery The query that is the AND of the passed in queries.
1095+ */
1096+ public static function andQueries ($ queryObjects )
1097+ {
1098+ $ className = self ::_matchClassName ($ queryObjects );
1099+ $ query = new self ($ className );
1100+ $ query ->_and ($ queryObjects );
1101+
1102+ return $ query ;
1103+ }
1104+
1105+ /**
1106+ * All queries must have same class name.
1107+ *
1108+ * @param array $queryObjects Array of ParseQuery objects.
1109+ *
1110+ * @throws \Exception If all queries don't have same class.
1111+ *
1112+ * @return string class name.
1113+ */
1114+ private static function _matchClassname ($ queryObjects )
10591115 {
10601116 $ className = null ;
10611117 $ length = count ($ queryObjects );
@@ -1067,10 +1123,7 @@ public static function orQueries($queryObjects)
10671123 throw new Exception ('All queries must be for the same class ' , 103 );
10681124 }
10691125 }
1070- $ query = new self ($ className );
1071- $ query ->_or ($ queryObjects );
1072-
1073- return $ query ;
1126+ return $ className ;
10741127 }
10751128
10761129 /**
@@ -1082,10 +1135,47 @@ public static function orQueries($queryObjects)
10821135 */
10831136 private function _or ($ queries )
10841137 {
1085- $ this ->where ['$or ' ] = [];
1138+ return $ this ->_mergeQueries ('$or ' , $ queries );
1139+ }
1140+
1141+ /**
1142+ * Add constraint that at none of the passed in queries matches.
1143+ *
1144+ * @param array $queries The list of queries to NOR.
1145+ *
1146+ * @return ParseQuery Returns the query, so you can chain this call.
1147+ */
1148+ private function _nor ($ queries )
1149+ {
1150+ return $ this ->_mergeQueries ('$nor ' , $ queries );
1151+ }
1152+
1153+ /**
1154+ * Add constraint that at all of the passed in queries matches.
1155+ *
1156+ * @param array $queries The list of queries to OR.
1157+ *
1158+ * @return ParseQuery Returns the query, so you can chain this call.
1159+ */
1160+ private function _and ($ queries )
1161+ {
1162+ return $ this ->_mergeQueries ('$and ' , $ queries );
1163+ }
1164+
1165+ /**
1166+ * Combines queries for NOR, AND, OR queries.
1167+ *
1168+ * @param string $key The condition $and, $or, $nor.
1169+ * @param array $queries The list of queries to combine.
1170+ *
1171+ * @return ParseQuery Returns the query, so you can chain this call.
1172+ */
1173+ private function _mergeQueries ($ key , $ queries )
1174+ {
1175+ $ this ->where [$ key ] = [];
10861176 $ length = count ($ queries );
10871177 for ($ i = 0 ; $ i < $ length ; $ i ++) {
1088- $ this ->where [' $or ' ][] = $ queries [$ i ]->where ;
1178+ $ this ->where [$ key ][] = $ queries [$ i ]->where ;
10891179 }
10901180
10911181 return $ this ;
0 commit comments