本文整理汇总了PHP中Cake\Collection\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getBlocksForColumn
/**
* Return all blocks to render in the given row column
*
* @param int $column Numeric column index, starting with 1
* @return array
*/
public function getBlocksForColumn($column)
{
$blocks = new \Cake\Collection\Collection($this->cms_blocks);
return $blocks->filter(function ($block) use($column) {
return $block->column_index == $column;
})->toArray();
}
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:13,代码来源:CmsRow.php
示例2: index
/**
* Index method
*
* @return \Cake\Network\Response|null
*/
public function index()
{
$releases = $this->Releases->find('all')->all();
$collection = new Collection($releases);
$attribute_names = array_unique($collection->extract('attribute_name')->toArray());
$idps = array_unique($collection->extract('idp')->toArray());
$releasesByIdp = $collection->groupBy('idp')->toArray();
foreach ($idps as $idp) {
foreach ($attribute_names as $attribute) {
$releasesByIdPbyAttribute = $collection->match(['idp' => $idp, 'attribute_name' => $attribute]);
$temp_result = $releasesByIdPbyAttribute->countBy(function ($result) {
return strtolower($result->validated) == 'fail' ? 'fail' : 'pass';
});
$results[$idp][$attribute] = $temp_result->toArray();
}
}
# My attributes
$persistentid_array = preg_split('/!/', $this->request->env('persistent-id'));
$persistentid = end($persistentid_array);
$myAttributesTemp = $this->Releases->find()->andWhere(['idp' => $this->request->env('Shib-Identity-Provider'), 'persistentid' => $persistentid])->all();
$myAttributesCollection = new Collection($myAttributesTemp);
$myAttributes = $myAttributesCollection->groupBy('attribute_name')->toArray();
$this->set(compact('myAttributes'));
$this->set('_serialize', ['myAttributes']);
$this->set(compact('results'));
$this->set('_serialize', ['results']);
$this->set(compact('idps'));
$this->set('_serialize', ['idps']);
$this->set(compact('attribute_names'));
$this->set('_serialize', ['attribute_names']);
}
开发者ID:csc-it-center-for-science,项目名称:attribute-test-service,代码行数:36,代码来源:ReleasesController.php
示例3: index
/**
* Index method
*
* @return void
*/
public function index()
{
//$this->set('categorias', $this->paginate($this->Categorias));
$find = $this->Categorias->find('all', ['fields' => ['id', 'categoria_id', 'nome']])->toArray();
$collection = new Collection($find);
$categorias = $collection->nest('id', 'categoria_id')->toArray();
$this->set('categorias', $categorias);
$this->set('_serialize', ['categorias']);
}
开发者ID:QuielSimoes,项目名称:meugarangau,代码行数:14,代码来源:CategoriasController.php
示例4: getNextRowPosition
/**
* Returns the next highest position for adding a new row
*
* @return int
*/
public function getNextRowPosition()
{
$rows = new Collection($this->cms_rows);
$highestRow = $rows->max('position');
$maxPosition = 0;
if ($highestRow) {
$maxPosition = $highestRow->position;
}
return $maxPosition + 1;
}
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:15,代码来源:CmsPage.php
示例5: getPhotosSorted
public function getPhotosSorted()
{
if (isset($this->photos) and !empty($this->photos)) {
$photosCollection = new Collection($this->photos);
return $photosCollection->sortBy(function ($photo) {
return $photo->sort_order;
}, SORT_ASC)->toArray();
}
return [];
}
开发者ID:mswagencia,项目名称:photo-gallery,代码行数:10,代码来源:Gallery.php
示例6: _getLastFiveComments
public function _getLastFiveComments()
{
$alias = Inflector::classify($this->source());
$comment = TableRegistry::get('Social.Comments');
$comments = $comment->find()->where(['Comments.object_id' => $this->id, 'Comments.object' => $alias])->limit(__MAX_COMMENTS_LISTED)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
// Reorder the Comments by creation order
// (even though we got them by descending order)
$collection = new Collection($comments);
$comments = $collection->sortBy('Comment.created');
return $comments->toArray();
}
开发者ID:eripoll,项目名称:webiplan,代码行数:11,代码来源:CommentableTrait.php
示例7: _getSelectOptions
/**
* Method that retrieves select input options by list name.
*
* @param string $listName list name
* @param string $spacer The string to use for prefixing the values according to
* their depth in the tree
* @param bool $flatten flat list flag
* @return array list options
*/
protected function _getSelectOptions($listName, $spacer = ' - ', $flatten = true)
{
$result = $this->__getListFieldOptions($listName);
$result = $this->__filterOptions($result);
if (!$flatten) {
return $result;
}
// flatten list options
$collection = new Collection($result);
$result = $collection->listNested()->printer('name', 'id', $spacer)->toArray();
return $result;
}
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:21,代码来源:ListTrait.php
示例8: _getTagString
protected function _getTagString()
{
if (isset($this->_properties['tag_string'])) {
return $this->_properties['tag_string'];
}
if (empty($this->tags)) {
return '';
}
$tags = new Collection($this->tags);
$str = $tags->reduce(function ($string, $tag) {
return $string . $tag->label . ', ';
}, '');
return trim($str, ', ');
}
开发者ID:robisacommonusername,项目名称:rran-site,代码行数:14,代码来源:Uploadedfile.php
示例9: filterPrimaryKey
/**
* This method is called in case a primary key was defined using the addPrimaryKey() method.
* It currently does something only if using SQLite.
* If a column is an auto-increment key in SQLite, it has to be a primary key and it has to defined
* when defining the column. Phinx takes care of that so we have to make sure columns defined as autoincrement were
* not added with the addPrimaryKey method, otherwise, SQL queries will be wrong.
*
* @return void
*/
protected function filterPrimaryKey()
{
if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($this->options['primary_key'])) {
return;
}
$primaryKey = $this->options['primary_key'];
if (!is_array($primaryKey)) {
$primaryKey = [$primaryKey];
}
$primaryKey = array_flip($primaryKey);
$columnsCollection = new Collection($this->columns);
$primaryKeyColumns = $columnsCollection->filter(function ($columnDef, $key) use($primaryKey) {
return isset($primaryKey[$columnDef->getName()]);
})->toArray();
if (empty($primaryKeyColumns)) {
return;
}
foreach ($primaryKeyColumns as $primaryKeyColumn) {
if ($primaryKeyColumn->isIdentity()) {
unset($primaryKey[$primaryKeyColumn->getName()]);
}
}
$primaryKey = array_flip($primaryKey);
if (!empty($primaryKey)) {
$this->options['primary_key'] = $primaryKey;
} else {
unset($this->options['primary_key']);
}
}
开发者ID:JoHein,项目名称:LeBonCoup,代码行数:38,代码来源:Table.php
示例10: get_for_parent
public function get_for_parent($parent, $page)
{
$comments = $this->Comments->find()->where(['Comments.object_id' => $parent])->limit(__MAX_COMMENTS_LISTED)->page($page)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
// Reorder the Comments by creation order
// (even though we got them by descending order)
$collection = new Collection($comments);
$comments = $collection->sortBy('Comment.created');
$view = new View($this->request, $this->response, null);
$view->layout = 'ajax';
// layout to use or false to disable
$view->set('comments', $comments->toArray());
$data['html'] = $view->render('Social.Comments/get_for_parent');
$this->layout = 'ajax';
$this->set('data', $data);
$this->render('/Shared/json/data');
}
开发者ID:eripoll,项目名称:webiplan,代码行数:16,代码来源:CommentsController.php
示例11: addPattern
/**
* addPattern
*
*/
public function addPattern($field, $pattern)
{
$pattern = new Collection((array) $pattern);
$validationSet = $this->field($field);
$validationPatterns = self::$validationPatterns;
$pattern->each(function ($key) use($field, $validationSet, $validationPatterns) {
if (empty($validationPatterns[$key])) {
if (method_exists($this, $key)) {
$this->{$key}($field);
return;
}
throw new NoValidationPatternException('Not found pattern `' . $key . '`');
}
$rules = new Collection($validationPatterns[$key]);
$rules->each(function ($rule, $name) use($validationSet) {
$validationSet->add($name, $rule);
});
});
return $this;
}
开发者ID:k1low,项目名称:patternable-validator,代码行数:24,代码来源:Validator.php
示例12: getLibrary
public function getLibrary()
{
$this->viewBuilder()->layout("ajax");
$this->autoRender = false;
$this->loadModel('Playlists');
$this->loadModel('Tracks');
$userId = $this->request->session()->read('user.id');
$library = $this->Playlists->find('all')->where(['user_id' => $userId])->contain('Tracks');
if ($library->count() == 0) {
echo json_encode(['success' => false]);
return;
}
$library = $library->toArray();
// remove tracks from playlists
$libraryCollection = new Collection($library);
$playlists = $libraryCollection->extract(function ($list) {
unset($list->tracks);
return $list;
});
// if tokens is expired get new downloadUrls
// GAUTH: is token expired
$gotUpdatedDownloadUrls = false;
$client = new \Google_Client();
$client->setAuthConfigFile('../client_secret.json');
$client->addScope(\Google_Service_Drive::DRIVE);
if ($this->request->session()->check('user.drive_token')) {
$client->setAccessToken($this->request->session()->read('user.drive_token'));
if ($client->isAccessTokenExpired()) {
$gotUpdatedDownloadUrls = true;
}
} else {
$gotUpdatedDownloadUrls = true;
}
$driveFiles = $this->getMusicFromDrive();
$driveFileUrlById = (new Collection($driveFiles))->combine('id', function ($entity) {
return str_replace("?e=download&gd=true", "", $entity['downloadUrl']);
})->toArray();
// create tracks by playlist id, also update new download_url if gotten it
$tracksByPlaylistId = [];
$tracksById = [];
foreach ($library as $list) {
$tracksByPlaylistId[$list->id] = [];
foreach ($list->tracks as $track) {
if ($gotUpdatedDownloadUrls) {
$this->Tracks->patchEntity($track, ['download_url' => $driveFileUrlById[$track->drive_id]]);
$this->Tracks->save($track);
}
$tracksByPlaylistId[$track->playlist_id][] = $track;
$tracksById[$track->id] = $track;
}
}
echo json_encode(['playlists' => $playlists, 'tracksByPlaylistId' => $tracksByPlaylistId, 'tracksById' => $tracksById]);
}
开发者ID:apomarinov,项目名称:cake,代码行数:53,代码来源:UsersController.php
示例13: isPermitted
public function isPermitted($permissions, $operator = OPERATOR_AND)
{
$session = $this->request->session()->read('Auth.User');
if ($session['idr_admin']) {
return true;
}
$acoes = new Collection($session['acoes']);
if (is_array($permissions)) {
if ($operator == OPERATOR_AND) {
foreach ($permissions as $k => $p) {
$permitido = $acoes->filter(function ($acao, $key) use($p) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
});
if (count($permitido->toArray()) == 0) {
break;
}
}
} else {
foreach ($permissions as $k => $p) {
$permitido = $acoes->filter(function ($acao, $key) use($p) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
});
if (count($permitido->toArray()) > 0) {
break;
}
}
}
} else {
$permitido = $acoes->filter(function ($acao, $key) use($permissions) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
});
}
if (count($permitido->toArray()) > 0) {
return true;
} else {
return false;
}
}
开发者ID:ranzate,项目名称:security,代码行数:38,代码来源:SecurityHelper.php
示例14: anyPermitted
private function anyPermitted($permissions, $operator = self::OPERATOR_AND)
{
$session = $this->request->session()->read('Auth.User');
if ($session['idr_admin']) {
return true;
}
$acoes = new Collection($session['acoes']);
if (is_array($permissions)) {
if ($operator == self::OPERATOR_AND) {
foreach ($permissions as $k => $p) {
$permitido = $acoes->filter(function ($acao, $key) use($p) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
});
if (count($permitido->toArray()) == 0) {
break;
}
}
} else {
foreach ($permissions as $k => $p) {
$permitido = $acoes->filter(function ($acao, $key) use($p) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
});
if (count($permitido->toArray()) > 0) {
break;
}
}
}
} else {
$permitido = $acoes->filter(function ($acao, $key) use($permissions) {
return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
});
}
if (count($permitido->toArray()) == 0) {
throw new UnauthorizedException("Usuário da sessão não possui permissão para acessar a ação escolhida");
}
}
开发者ID:ranzate,项目名称:security,代码行数:36,代码来源:SecurityComponent.php
示例15: __construct
/**
* Wraps this iterator around the passed items so when iterated they are returned
* in order.
*
* The callback will receive as first argument each of the elements in $items,
* the value returned in the callback will be used as the value for sorting such
* element. Please not that the callback function could be called more than once
* per element.
*
* @param array|\Traversable $items The values to sort
* @param callable|string $callback A function used to return the actual value to
* be compared. It can also be a string representing the path to use to fetch a
* column or property in each element
* @param int $dir either SORT_DESC or SORT_ASC
* @param int $type the type of comparison to perform, either SORT_STRING
* SORT_NUMERIC or SORT_NATURAL
*/
public function __construct($items, $callback, $dir = SORT_DESC, $type = SORT_NUMERIC)
{
if (is_array($items)) {
$items = new Collection($items);
}
$items = iterator_to_array($items, false);
$callback = $this->_propertyExtractor($callback);
$results = [];
foreach ($items as $key => $value) {
$results[$key] = $callback($value);
}
$dir === SORT_DESC ? arsort($results, $type) : asort($results, $type);
foreach (array_keys($results) as $key) {
$results[$key] = $items[$key];
}
parent::__construct($results);
}
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:34,代码来源:SortIterator.php
示例16: getType
/**
* Retrieves a type that should be used for a specific field
*
* @param string $field Name of field
* @param string $type User-specified type
* @return string
*/
public function getType($field, $type)
{
$reflector = new ReflectionClass('Phinx\\Db\\Adapter\\AdapterInterface');
$collection = new Collection($reflector->getConstants());
$validTypes = $collection->filter(function ($value, $constant) {
$value;
return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_';
})->toArray();
$fieldType = $type;
if ($type === null || !in_array($type, $validTypes)) {
if ($type === 'primary') {
$fieldType = 'integer';
} elseif ($field === 'id') {
$fieldType = 'integer';
} elseif (in_array($field, ['created', 'modified', 'updated'])) {
$fieldType = 'datetime';
} else {
$fieldType = 'string';
}
}
return $fieldType;
}
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:29,代码来源:ColumnParser.php
示例17: statistic
public function statistic($tournament_id)
{
$games = TableRegistry::get('Games')->find()->where(['tournament_id' => $tournament_id]);
$statistics['matchs'] = 0;
$statistics['goals'] = 0;
$statistics['principals_victory'] = 0;
$statistics['visitors_victory'] = 0;
$statistics['draws'] = 0;
foreach ($games as $key => $game) {
$statistics['matchs']++;
$statistics['goals'] += $game['score_a'] + $game['score_b'];
if ($game['score_a'] > $game['score_b']) {
$statistics['principals_victory']++;
} else {
if ($game['score_a'] < $game['score_b']) {
$statistics['visitors_victory']++;
} else {
if (!is_null($game['score_a'])) {
$statistics['draws']++;
}
}
}
}
$conn = ConnectionManager::get('default');
$query = $conn->execute('
SELECT player, team_name, team_shield, IFNULL(sum(goals_pro),0) player_goals_pro, IFNULL(sum(goals_against),0) player_goals_against FROM (
(
SELECT u.id player_id, u.login player, te.name team_name, te.logo team_shield, SUM( score_a ) goals_pro, SUM( score_b ) goals_against
FROM games g
INNER JOIN tournaments t ON g.tournament_id = t.id
INNER JOIN teams_tournaments_users tt ON tt.tournament_id = t.id AND tt.user_id = g.user_a_id
INNER JOIN teams te ON te.id = tt.team_id
INNER JOIN users u ON u.id = g.user_a_id
WHERE t.id =' . $tournament_id . '
GROUP BY g.user_a_id
) UNION (
SELECT u.id player_id, u.login player, te.name team_name, te.logo team_shield, SUM( score_b ) goals_pro, SUM( score_a ) goals_against
FROM games g
INNER JOIN tournaments t ON g.tournament_id = t.id
INNER JOIN teams_tournaments_users tt ON tt.tournament_id = t.id AND tt.user_id = g.user_b_id
INNER JOIN teams te ON te.id = tt.team_id
INNER JOIN users u ON u.id = g.user_b_id
WHERE t.id =' . $tournament_id . '
GROUP BY g.user_b_id
) ORDER BY goals_pro DESC
) a
GROUP BY player_id
ORDER BY player_goals_pro DESC
');
$playersGoals = $query->fetchAll('assoc');
$statistics['best_atack'] = [];
$statistics['best_atack'][0]['player'] = $playersGoals[0]['player'];
$statistics['best_atack'][0]['team'] = $playersGoals[0]['team_name'];
$statistics['best_atack'][0]['shield'] = $playersGoals[0]['team_shield'];
$statistics['best_atack'][0]['goals'] = $playersGoals[0]['player_goals_pro'];
foreach ($playersGoals as $key => $row) {
if ($statistics['best_atack'][0]['goals'] == $row['player_goals_pro']) {
$statistics['best_atack'][$key]['player'] = $row['player'];
$statistics['best_atack'][$key]['team'] = $row['team_name'];
$statistics['best_atack'][$key]['shield'] = $row['team_shield'];
$statistics['best_atack'][$key]['goals'] = $row['player_goals_pro'];
}
}
$playersGoalsCollection = new Collection($playersGoals);
$playersGoals = $playersGoalsCollection->sortBy('player_goals_against', SORT_ASC, SORT_NUMERIC)->toArray();
$playersGoals = array_values($playersGoals);
$statistics['best_defense'] = [];
$statistics['best_defense'][0]['player'] = $playersGoals[0]['player'];
$statistics['best_defense'][0]['team'] = $playersGoals[0]['team_name'];
$statistics['best_defense'][0]['shield'] = $playersGoals[0]['team_shield'];
$statistics['best_defense'][0]['goals'] = $playersGoals[0]['player_goals_against'];
foreach ($playersGoals as $key => $row) {
if ($statistics['best_defense'][0]['goals'] == $row['player_goals_against']) {
$statistics['best_defense'][$key]['player'] = $row['player'];
$statistics['best_defense'][$key]['team'] = $row['team_name'];
$statistics['best_defense'][$key]['shield'] = $row['team_shield'];
$statistics['best_defense'][$key]['goals'] = $row['player_goals_against'];
}
}
$playersGoalsCollection = new Collection($playersGoals);
$playersGoals = $playersGoalsCollection->sortBy('player_goals_pro', SORT_ASC, SORT_NUMERIC)->toArray();
$playersGoals = array_values($playersGoals);
$statistics['worse_atack'] = [];
$statistics['worse_atack'][0]['player'] = $playersGoals[0]['player'];
$statistics['worse_atack'][0]['team'] = $playersGoals[0]['team_name'];
$statistics['worse_atack'][0]['shield'] = $playersGoals[0]['team_shield'];
$statistics['worse_atack'][0]['goals'] = $playersGoals[0]['player_goals_pro'];
foreach ($playersGoals as $key => $row) {
if ($statistics['worse_atack'][0]['goals'] == $row['player_goals_pro']) {
$statistics['worse_atack'][$key]['player'] = $row['player'];
$statistics['worse_atack'][$key]['team'] = $row['team_name'];
$statistics['worse_atack'][$key]['shield'] = $row['team_shield'];
$statistics['worse_atack'][$key]['goals'] = $row['player_goals_pro'];
}
}
$playersGoalsCollection = new Collection($playersGoals);
$playersGoals = $playersGoalsCollection->sortBy('player_goals_against', SORT_DESC, SORT_NUMERIC)->toArray();
$playersGoals = array_values($playersGoals);
$statistics['worse_defense'] = [];
$statistics['worse_defense'][0]['player'] = $playersGoals[0]['player'];
//.........这里部分代码省略.........
开发者ID:albertoneto,项目名称:localhost,代码行数:101,代码来源:TournamentsController.php
示例18: getRanking
public function getRanking($product_id, $videogame)
{
$players = [];
$titles = TableRegistry::get('Users')->find()->select(['Users.id', 'Users.login', 'Users.photo', 'titles' => TableRegistry::get('Users')->find()->func()->count('Users.id')])->join(['Tournaments' => ['table' => 'tournaments', 'type' => 'INNER', 'conditions' => 'Users.id = Tournaments.champion_user_id']])->where(['Tournaments.product_id' => $product_id, 'Tournaments.videogame' => $videogame])->group(['Users.id', 'Users.login', 'Users.photo']);
foreach ($titles as $key => $value) {
if (isset($value['login'])) {
$players[$value['id']]['login'] = $value['login'];
}
if (isset($value['photo'])) {
$players[$value['id']]['photo'] = $value['photo'];
}
$players[$value['id']]['titles'] = $value['titles'];
}
$victoriesA = TableRegistry::get('Users')->find()->select(['Users.id', 'Users.login', 'Users.photo', 'victories' => TableRegistry::get('Users')->find()->func()->count('Users.id')])->join(['Games' => ['table' => 'games', 'type' => 'INNER', 'conditions' => 'Users.id = Games.user_a_id AND Games.score_a > Games.score_b'], 'Tournaments' => ['table' => 'tournaments', 'type' => 'INNER', 'conditions' => 'Tournaments.id = Games.tournament_id']])->where(['Tournaments.product_id' => $product_id, 'Tournaments.videogame' => $videogame])->group(['Users.id']);
foreach ($victoriesA as $key => $value) {
if (isset($value['login'])) {
$players[$value['id']]['login'] = $value['login'];
}
if (isset($value['photo'])) {
$players[$value['id']]['photo'] = $value['photo'];
}
if (isset($players[$value['id']]['victories'])) {
$players[$value['id']]['victories'] += $value['victories'];
} else {
$players[$value['id']]['victories'] = $value['victories'];
}
}
$victoriesB = TableRegistry::get('Users')->find()->select(['Users.id', 'victories' => TableRegistry::get('Users')->find()->func()->count('Users.id')])->join(['Games' => ['table' => 'games', 'type' => 'INNER', 'conditions' => 'Users.id = Games.user_b_id AND Games.score_b > Games.score_a'], 'Tournaments' => ['table' => 'tournaments', 'type' => 'INNER', 'conditions' => 'Tournaments.id = Games.tournament_id']])->where(['Tournaments.product_id' => $product_id, 'Tournaments.videogame' => $videogame])->group(['Users.id']);
foreach ($victoriesB as $key => $value) {
if (isset($value['login'])) {
$players[$value['id']]['login'] = $value['login'];
}
if (isset($value['photo'])) {
$players[$value['id']]['photo'] = $value['photo'];
}
if (isset($players[$value['id']]['victories'])) {
$players[$value['id']]['victories'] += $value['victories'];
} else {
$players[$value['id']]['victories'] = $value['victories'];
}
}
$goalA = TableRegistry::get('Users')->find()->select(['Users.id', 'goals' => TableRegistry::get('Users')->find()->func()->sum('Games.score_a')])->join(['Games' => ['table' => 'games', 'type' => 'INNER', 'conditions' => 'Users.id = Games.user_a_id AND Games.score_a > Games.score_b'], 'Tournaments' => ['table' => 'tournaments', 'type' => 'INNER', 'conditions' => 'Tournaments.id = Games.tournament_id']])->where(['Tournaments.product_id' => $product_id, 'Tournaments.videogame' => $videogame])->group(['Users.id']);
foreach ($goalA as $key => $value) {
if (isset($value['login'])) {
$players[$value['id']]['login'] = $value['login'];
}
if (isset($value['photo'])) {
$players[$value['id']]['photo'] = $value['photo'];
}
if (isset($players[$value['id']]['goals'])) {
$players[$value['id']]['goals'] += $value['goals'];
} else {
$players[$value['id']]['goals'] = $value['goals'];
}
}
$goalB = TableRegistry::get('Users')->find()->select(['Users.id', 'goals' => TableRegistry::get('Users')->find()->func()->sum('Games.score_b')])->join(['Games' => ['table' => 'games', 'type' => 'INNER', 'conditions' => 'Users.id = Games.user_b_id AND Games.score_b > Games.score_a'], 'Tournaments' => ['table' => 'tournaments', 'type' => 'INNER', 'conditions' => 'Tournaments.id = Games.tournament_id']])->where(['Tournaments.product_id' => $product_id, 'Tournaments.videogame' => $videogame])->group(['Users.id']);
foreach ($goalB as $key => $value) {
if (isset($value['login'])) {
$players[$value['id']]['login'] = $value['login'];
}
if (isset($value['photo'])) {
$players[$value['id']]['photo'] = $value['photo'];
}
if (isset($players[$value['id']]['goals'])) {
$players[$value['id']]['goals'] += $value['goals'];
} else {
$players[$value['id']]['goals'] = $value['goals'];
}
}
$playersCollection = new Collection($players);
$players = $playersCollection->sortBy('titles', SORT_DESC, SORT_NUMERIC)->toArray();
$players = array_values($players);
return $players;
}
开发者ID:albertoneto,项目名称:localhost,代码行数:74,代码来源:SiteController.php
示例19: testChunkNested
/**
* Tests the chunk method with non-scalar items
*
* @return void
*/
public function testChunkNested()
{
$collection = new Collection([1, 2, 3, [4, 5], 6, [7, [8, 9], 10], 11]);
$chunked = $collection->chunk(2)->toList();
$expected = [[1, 2], [3, [4, 5]], [6, [7, [8, 9], 10]], [11]];
$this->assertEquals($expected, $chunked);
}
开发者ID:mhd94,项目名称:cakephp,代码行数:12,代码来源:CollectionTest.php
示例20: testInsert
/**
* Tests insert
*
* @return void
*/
public function testInsert()
{
$items = [['a' => 1], ['b' => 2]];
$collection = new Collection($items);
$iterator = $collection->insert('c', [3, 4]);
$this->assertInstanceOf('\\Cake\\Collection\\Iterator\\InsertIterator', $iterator);
$this->assertEquals([['a' => 1, 'c' => 3], ['b' => 2, 'c' => 4]], iterator_to_array($iterator));
}
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:13,代码来源:CollectionTest.php
注:本文中的Cake\Collection\Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论