/** * Finds all model objects in the DB that appear to be a copy of $model_object_or_attributes_array. * We consider something to be a copy if all the attributes match (except the ID, of course). * @param array|EE_Base_Class $model_object_or_attributes_array If its an array, it's field-value pairs * @param array $query_params like EEM_Base::get_all's query_params. * @throws EE_Error * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) */ public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { if ($model_object_or_attributes_array instanceof EE_Base_Class) { $attributes_array = $model_object_or_attributes_array->model_field_array(); } elseif (is_array($model_object_or_attributes_array)) { $attributes_array = $model_object_or_attributes_array; } else { throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); } //even copies obviously won't have the same ID, so remove the primary key //from the WHERE conditions for finding copies (if there is a primary key, of course) if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { unset($attributes_array[$this->primary_key_name()]); } if (isset($query_params[0])) { $query_params[0] = array_merge($attributes_array, $query_params); } else { $query_params[0] = $attributes_array; } return $this->get_all($query_params); }