/** * Test the count() method which is part of the ResultSet duck type. * * @return void */ public function testCount() { $data = new \ArrayIterator([1, 2, 3]); $decorator = new ResultSetDecorator($data); $this->assertEquals(3, $decorator->count()); $this->assertCount(3, $decorator); }
/** * Modifies the results from a table find in order to merge full translation records * into each entity under the `_translations` key * * @param \Cake\Datasource\ResultSetDecorator $results * @return \Cake\Collection\Collection */ public function groupTranslations($results) { return $results->map(function ($row) { $translations = (array) $row->get('_i18n'); $grouped = new Collection($translations); $result = []; foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) { $translation = new Entity($keys + ['locale' => $locale], ['markNew' => false, 'useSetters' => false, 'markClean' => true]); $result[$locale] = $translation; } $options = ['setter' => false, 'guard' => false]; $row->set('_translations', $result, $options); unset($row['_i18n']); $row->clean(); return $row; }); }
/** * Prepend parent module display field value to resultset. * * @param \Cake\Datasource\ResultSetDecorator $entities Entities * @return array */ protected function _prependParentModule(ResultSetDecorator $entities) { $result = $entities->toArray(); foreach ($result as $id => &$value) { $parentProperties = $this->_getRelatedParentProperties($this->_getRelatedProperties($this->{$this->name}->registryAlias(), $id)); if (!empty($parentProperties['dispFieldVal'])) { $value = implode(' ' . $this->_separator . ' ', [$parentProperties['dispFieldVal'], $value]); } } return $result; }
/** * Modifies the results from a table find in order to merge the translated fields * into each entity for a given locale. * * @param \Cake\DataSource\ResultSetDecorator $results * @param string $locale * @return \Cake\Collection\Collection */ protected function _rowMapper($results, $locale) { return $results->map(function ($row) use($locale) { $options = ['setter' => false, 'guard' => false]; foreach ($this->_config['fields'] as $field) { $name = $field . '_translation'; $translation = $row->get($name); if (!$translation) { continue; } $content = $translation->get('content'); if ($content !== null) { $row->set($field, $content, $options); } unset($row[$name]); } $row->set('_locale', $locale, $options); $row->clean(); return $row; }); }