95 |
95 |
96 if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) { |
96 if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) { |
97 return array(); |
97 return array(); |
98 } |
98 } |
99 |
99 |
100 $count = count( $args ); |
100 $count = count( $args ); |
101 $filtered = array(); |
101 $filtered = array(); |
102 |
102 |
103 foreach ( $this->output as $key => $obj ) { |
103 foreach ( $this->output as $key => $obj ) { |
104 $to_match = (array) $obj; |
104 $to_match = (array) $obj; |
105 |
105 |
113 if ( |
113 if ( |
114 ( 'AND' == $operator && $matched == $count ) || |
114 ( 'AND' == $operator && $matched == $count ) || |
115 ( 'OR' == $operator && $matched > 0 ) || |
115 ( 'OR' == $operator && $matched > 0 ) || |
116 ( 'NOT' == $operator && 0 == $matched ) |
116 ( 'NOT' == $operator && 0 == $matched ) |
117 ) { |
117 ) { |
118 $filtered[$key] = $obj; |
118 $filtered[ $key ] = $obj; |
119 } |
119 } |
120 } |
120 } |
121 |
121 |
122 $this->output = $filtered; |
122 $this->output = $filtered; |
123 |
123 |
138 * @return array Array of found values. If `$index_key` is set, an array of found values with keys |
138 * @return array Array of found values. If `$index_key` is set, an array of found values with keys |
139 * corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
139 * corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
140 * `$list` will be preserved in the results. |
140 * `$list` will be preserved in the results. |
141 */ |
141 */ |
142 public function pluck( $field, $index_key = null ) { |
142 public function pluck( $field, $index_key = null ) { |
|
143 $newlist = array(); |
|
144 |
143 if ( ! $index_key ) { |
145 if ( ! $index_key ) { |
144 /* |
146 /* |
145 * This is simple. Could at some point wrap array_column() |
147 * This is simple. Could at some point wrap array_column() |
146 * if we knew we had an array of arrays. |
148 * if we knew we had an array of arrays. |
147 */ |
149 */ |
148 foreach ( $this->output as $key => $value ) { |
150 foreach ( $this->output as $key => $value ) { |
149 if ( is_object( $value ) ) { |
151 if ( is_object( $value ) ) { |
150 $this->output[ $key ] = $value->$field; |
152 $newlist[ $key ] = $value->$field; |
151 } else { |
153 } else { |
152 $this->output[ $key ] = $value[ $field ]; |
154 $newlist[ $key ] = $value[ $field ]; |
153 } |
155 } |
154 } |
156 } |
|
157 |
|
158 $this->output = $newlist; |
|
159 |
155 return $this->output; |
160 return $this->output; |
156 } |
161 } |
157 |
162 |
158 /* |
163 /* |
159 * When index_key is not set for a particular item, push the value |
164 * When index_key is not set for a particular item, push the value |
160 * to the end of the stack. This is how array_column() behaves. |
165 * to the end of the stack. This is how array_column() behaves. |
161 */ |
166 */ |
162 $newlist = array(); |
|
163 foreach ( $this->output as $value ) { |
167 foreach ( $this->output as $value ) { |
164 if ( is_object( $value ) ) { |
168 if ( is_object( $value ) ) { |
165 if ( isset( $value->$index_key ) ) { |
169 if ( isset( $value->$index_key ) ) { |
166 $newlist[ $value->$index_key ] = $value->$field; |
170 $newlist[ $value->$index_key ] = $value->$field; |
167 } else { |
171 } else { |