/** * Updates an EAV "value" object with the given value. * * @param \Cartalyst\Attributes\Value $valueInstance * @param mixed $value * @return \Cartalyst\Attributes\Value|bool */ protected function updateEavValue(Value $valueInstance, $value) { if (!$value) { $valueInstance->delete(); return; } $valueInstance->setValueKey($value); if ($valueInstance->save()) { return $valueInstance; } }
/** @test */ public function it_can_retrieve_the_entity_relation() { $value = new Value(); $this->assertEquals('entity', $value->getEntityRelation()); }
/** * Applies a filter to the given query. * * @param mixed $query * @param string $column * @param string $operator * @param mixed $value * @param string $method * @return void */ protected function applyFilter($query, $column, $operator, $value, $method = 'and') { $method = $method === 'and' ? 'where' : 'orWhere'; switch ($operator) { case 'like': $value = "%{$value}%"; break; case 'regex': if ($this->supportsRegexFilters()) { $method .= 'Raw'; } if ($this->getConnection() instanceof MySqlDatabaseConnection) { $query->{$method}("{$column} {$operator} ?", array($value)); } return; } if (strpos($column, '..') !== false) { $cols = explode('..', $column); $query->whereHas(head($cols), function ($q) use($cols, $operator, $value) { $q->where(last($cols), $operator, $value); }); } elseif (array_search($column, $this->attributes) !== false) { $valueModel = new Value(); $matches = $valueModel->newQuery()->where('entity_type', $this->eavClass)->{$method}('value', $operator, $value)->get(); $key = $query->getModel()->getKeyName(); if (!$matches->toArray()) { $query->where($key, null); } foreach ($matches as $match) { $query->{$method}($key, $operator, $match->entity_id); } } else { if ($value === '%null%') { $query->whereNull($column); } elseif ($value === '%not_null%') { $query->whereNotNull($column); } else { $query->{$method}($column, $operator, $value); } } }