本文整理汇总了PHP中Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getStream
public static function getStream(User $user)
{
$sql = "SELECT id\n\t\t\t\tFROM activities\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY id DESC\n\t\t\t";
$stream = new Collection($sql, array($user->id));
$stream->bindType('id', 'Activity');
return $stream;
}
开发者ID:eric116,项目名称:BotQueue,代码行数:7,代码来源:activity.php
示例2: getChildren
public function getChildren()
{
$sql = "SELECT id\n\t\t \tFROM s3_files\n\t\t \tWHERE parent_id = ?\n\t\t \tORDER BY id DESC";
$children = new Collection($sql, array($this->id));
$children->bindType('id', get_class($this));
return $children;
}
开发者ID:eric116,项目名称:BotQueue,代码行数:7,代码来源:StorageInterface.php
示例3: hookInstall
public function hookInstall()
{
//set up my Collectors table
$db = get_db();
$sql = "\n CREATE TABLE IF NOT EXISTS `{$db->Collector}` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `collection_id` int(10) unsigned NOT NULL,\n `name` TEXT NOT NULL,\n `bio` TEXT NOT NULL,\n `public` tinyint(1) default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$db->query($sql);
//set up some fake data to work with
//this is the kind of work that is usually done in a Controller when processing a form
$collection = new Collection();
$collection->name = "Fake Collection";
$collection->owner_id = 1;
$collection->save();
$collector = new Collector();
$collector->name = "Mr. Fake Collector";
$collector->collection_id = $collection->id;
$collector->bio = "I collected stuff for the Fake Collection";
$collector->public = 1;
$collector->save();
$collector = new Collector();
$collector->name = "Mysterious Ghost Collector";
$collector->collection_id = $collection->id;
$collector->bio = "I collected stuff for the Fake Collection, but in secret so I don't want the public to know";
$collector->public = 0;
$collector->save();
$collection = new Collection();
$collection->name = "Pseudo Collection";
$collection->owner_id = 1;
$collection->save();
$collector = new Collector();
$collector->name = "Mrs. Pseudo Collector";
$collector->collection_id = $collection->id;
$collector->bio = "I collected stuff for the Pseudo Collection";
$collector->public = 1;
$collector->save();
}
开发者ID:josebakmoreno,项目名称:TrainingMaterials,代码行数:35,代码来源:ModelExamplePlugin.php
示例4: write
public function write(Collection $items)
{
$path = $this->_getPath();
$this->items = $items;
//if (defined('JSON_PRETTY_PRINT')) { //PHP >= 5.4
// $json = json_encode($items->convertToArray(), JSON_PRETTY_PRINT); //JSON_PRETTY_PRINT: for debugging issues
//} else {
$json = json_encode($items->convertToArray());
//}
if ($json === false) {
throw new \RuntimeException('Cannot encode data to JSON');
}
$parentPath = dirname($path);
if (!is_dir($parentPath)) {
mkdir($parentPath, 0777, true);
chmod($parentPath, 0777);
}
$alreadyExists = file_exists($path);
$result = file_put_contents($path, $json);
if ($result === false) {
throw new \RuntimeException('Cannot open data file "' . $this->index . '" ("' . $path . '" : error while writing)');
}
if (!$alreadyExists) {
chmod($path, 0777);
}
}
开发者ID:Rudi9719,项目名称:stein-syn,代码行数:26,代码来源:File.class.php
示例5: seleccComments
public static function seleccComments($tittle)
{
$c = new Collection();
$conn = conexion();
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$sentencia = $conn->stmt_init();
if (!$sentencia->prepare("select * from comentarios where (blog_id=?)")) {
echo "Falló la preparación: (" . $conn->errno . ") " . $conn->error;
} else {
mysqli_stmt_bind_param($sentencia, "i", $tittle);
if (!$sentencia->execute()) {
return "0";
} else {
$sentencia->bind_result($Id, $Titulo, $Autor, $Texto, $Blog_id, $Fecha);
while ($sentencia->fetch()) {
$comment = new Comment(array("autor" => $Autor, "fecha" => $Fecha, "titulo" => $Titulo, "texto" => $Texto, "id" => $Id, "blog_id" => $Blog_id));
$c->addItem($comment);
}
$conn->close();
return $c;
}
}
}
}
开发者ID:andnune,项目名称:MaterialDesign,代码行数:26,代码来源:ModelComment.php
示例6: 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:coretyson,项目名称:coretyson,代码行数:38,代码来源:Table.php
示例7: renderView
public function renderView()
{
$badges_feature = new Collection('badge', $this->context->language->id);
$badges_feature->where('type', '=', 'feature');
$badges_feature->orderBy('id_group');
$badges_feature->orderBy('group_position');
$badges_achievement = new Collection('badge', $this->context->language->id);
$badges_achievement->where('type', '=', 'achievement');
$badges_achievement->orderBy('id_group');
$badges_achievement->orderBy('group_position');
$badges_international = new Collection('badge', $this->context->language->id);
$badges_international->where('type', '=', 'international');
$badges_international->orderBy('id_group');
$badges_international->orderBy('group_position');
$groups = array();
$query = new DbQuery();
$query->select('DISTINCT(b.`id_group`), bl.group_name, b.type');
$query->from('badge', 'b');
$query->join('
LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
foreach ($result as $res) {
$groups['badges_' . $res['type']][$res['id_group']] = $res['group_name'];
}
$badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international));
$levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend'));
$this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels);
return parent::renderView();
}
开发者ID:rongandat,项目名称:vatfairfoot,代码行数:29,代码来源:AdminGamificationController.php
示例8: combine
public static function combine($type, $files, $compress = false)
{
$root = panel::instance()->roots()->assets() . DS . $type;
$cache = new Media($root . DS . 'panel.' . $type);
$media = new Collection(array_map(function ($file) use($root) {
return new Media($root . DS . str_replace('/', DS, $file));
}, $files));
// get the max modification date
$modified = max($media->pluck('modified'));
if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
$cache->remove();
$content = '';
foreach ($media as $asset) {
$content .= $asset->read() . PHP_EOL;
}
if ($compress) {
$content = static::compress($content);
}
f::write($root . DS . 'panel.' . $type, $content);
}
if ($cache->exists()) {
return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
}
return $type(array_map(function ($item) use($type) {
return 'panel/assets/' . $type . '/' . $item;
}, $files));
}
开发者ID:LucasFyl,项目名称:korakia,代码行数:27,代码来源:assets.php
示例9: getValidatedByIdTab
public static function getValidatedByIdTab($id_tab)
{
$advices = new Collection('advice', Context::getContext()->language->id);
$advices->where('validated', '=', 1);
$advices->where('id_tab', '=', (int) $id_tab);
return $advices;
}
开发者ID:rongandat,项目名称:vatfairfoot,代码行数:7,代码来源:Advice.php
示例10: getAvailableConfigOptions
/**
* Return a list of available configuration options.
*
* @param Collection $availableTypes Collection of Injector\InjectorInterface::TYPE_*
* constants indicating valid package types that could be injected.
* @param string $projectRoot Path to the project root; assumes PWD by
* default.
* @return Collection Collection of ConfigOption instances.
*/
public function getAvailableConfigOptions(Collection $availableTypes, $projectRoot = '')
{
// Create an initial collection to which we'll append.
// This approach is used to ensure indexes are sane.
$discovered = new Collection([new ConfigOption('Do not inject', new Injector\NoopInjector())]);
Collection::create($this->discovery)->map(function ($discoveryClass) use($projectRoot) {
if (is_array($discoveryClass)) {
return new ConfigDiscovery\DiscoveryChain($discoveryClass, $projectRoot);
}
return new $discoveryClass($projectRoot);
})->filter(function ($discovery) {
return $discovery->locate();
})->map(function ($discovery, $file) use($projectRoot, $availableTypes) {
// Look up the injector based on the file type
$injectorClass = $this->injectors[$file];
if (is_array($injectorClass)) {
return new Injector\ConfigInjectorChain($injectorClass, $discovery, $availableTypes, $projectRoot);
}
return new $injectorClass($projectRoot);
})->filter(function ($injector) use($availableTypes) {
return $availableTypes->reduce(function ($flag, $type) use($injector) {
return $flag || $injector->registersType($type);
}, false);
})->each(function ($injector, $file) use($discovered) {
$discovered[] = new ConfigOption($file, $injector);
});
return 1 === $discovered->count() ? new Collection([]) : $discovered;
}
开发者ID:zendframework,项目名称:zend-component-installer,代码行数:37,代码来源:ConfigDiscovery.php
示例11: getActiveBots
public function getActiveBots()
{
$sql = "SELECT id\n\t\t\t\tFROM bots\n\t\t\t\tWHERE oauth_token_id = ?\n\t\t\t\tAND status != 'retired'\n\t\t\t\tORDER BY name";
$bots = new Collection($sql, array($this->id));
$bots->bindType('id', 'Bot');
return $bots;
}
开发者ID:eric116,项目名称:BotQueue,代码行数:7,代码来源:oauthtoken.php
示例12: getIncompleteProductLoads
public function getIncompleteProductLoads($user_id)
{
//get user and in progress product requests / ideas
$user = $this->eloquent->with(['ideas' => function ($query) {
$query->where('is_fulfilled', '=', 0);
}])->with(['productRequests' => function ($query) {
$query->whereNull('product_id');
}])->find($user_id);
if (empty($user)) {
return [];
}
$user = $user->toArray();
$product_requests = $user['product_requests'];
$ideas = $user['ideas'];
//compile inprogress items
$inprogress_items = new \Collection();
foreach ($product_requests as $product_request) {
$inprogress_items->add(['type' => 'id load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $product_request['created_at'])->diffForHumans(), 'created_at' => $product_request['created_at'], 'updated_at' => $product_request['updated_at'], 'id' => $product_request['id'], 'description' => $product_request['vendor'] . ' ' . $product_request['vendor_id'], 'query' => ['vendor' => $product_request['vendor'], 'vendor_id' => $product_request['vendor_id']]]);
}
foreach ($ideas as $idea) {
$inprogress_items->add(['type' => 'idea load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $idea['created_at'])->diffForHumans(), 'created_at' => $idea['created_at'], 'updated_at' => $idea['updated_at'], 'id' => $idea['id'], 'description' => $idea['description'], 'query' => ['idea_description' => $idea['description']]]);
}
$inprogress_items->sortBy('created_at');
return $inprogress_items->toArray();
}
开发者ID:ryanrobertsname,项目名称:giftertipster.com,代码行数:25,代码来源:EloquentUserRepository.php
示例13: getSliceJobs
public function getSliceJobs()
{
$sql = "SELECT id\n \t\tFROM slice_jobs\n \t\tWHERE slice_config_id = ?\n \t\tORDER BY id DESC";
$sliceJobs = new Collection($sql, array($this->id));
$sliceJobs->bindType('id', 'SliceJob');
return $sliceJobs;
}
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:7,代码来源:sliceconfig.php
示例14: buildCollection
public static function buildCollection($filters, $order = null)
{
// filters must be field=>value
$collection = new Collection();
$sql = $params = array();
foreach ($filters as $key => $filter) {
if (!is_array($filter)) {
$params[":{$key}"] = $filter;
$sql[] = "`{$key}` = :{$key}";
} else {
$params[":{$key}"] = $filter['value'];
$sql[] = "`{$key}` {$filter['operator']} :{$key}";
}
}
if ($sql) {
$sql = "WHERE " . implode(' AND ', $sql);
} else {
$sql = '';
}
$sql = "SELECT * FROM `" . static::TABLE_NAME . "` {$sql}";
$stmt = static::getConnection()->prepAndExecute(new \ArtfulRobot\PDO_Query("Fetch records from " . static::TABLE_NAME, $sql, $params));
if ($stmt->errorCode() != '00000') {
throw new Exception("PDO error: " . print_r($stmt->errorInfo(), 1));
}
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
// create an object of the class
$obj = new static();
$obj->loadFromArray($row, false, self::CAST_DB);
// these lines differ from main code
$id = implode("\\A", $obj->getPK());
$collection->append($obj, $id);
unset($obj);
}
return $collection;
}
开发者ID:artfulrobot,项目名称:artfulrobot,代码行数:35,代码来源:ModelMultiplePK.php
示例15: search
function search($query)
{
$collection = new Collection(\OCP\User::getUser());
$l = \OC_L10N::get('media');
$app_name = (string) $l->t('Music');
$artists = $collection->getArtists($query);
$albums = $collection->getAlbums(0, $query);
$songs = $collection->getSongs(0, 0, $query);
$results = array();
foreach ($artists as $artist) {
$results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
}
foreach ($albums as $album) {
$artist = $collection->getArtistName($album['album_artist']);
$results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
}
foreach ($songs as $song) {
$minutes = floor($song['song_length'] / 60);
$seconds = $song['song_length'] % 60;
$artist = $collection->getArtistName($song['song_artist']);
$album = $collection->getalbumName($song['song_album']);
$results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
}
return $results;
}
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:25,代码来源:media.php
示例16: newMerged
public static function newMerged(array $decks)
{
$merged = new Collection();
foreach ($decks as $deck) {
$merged->merge($deck);
}
return new static($merged);
}
开发者ID:sixteenstudio,项目名称:poker,代码行数:8,代码来源:Deck.php
示例17: testRand
public function testRand()
{
$collection = new Collection([1, 2, 3]);
$result = $collection->rand();
$this->assertCount(1, $result);
$result = $collection->rand(2);
$this->assertCount(2, $result);
}
开发者ID:Raphhh,项目名称:trex-collection,代码行数:8,代码来源:AbstractFilterTest.php
示例18: testCollection
public function testCollection()
{
$data = array(new Record(), new Record());
$collection = new Collection($data);
$recordInfo = $collection->getRecordInfo();
$this->assertInstanceOf('PSX\\Data\\RecordInfo', $recordInfo);
$this->assertEquals(array('entry' => $data), $recordInfo->getData());
}
开发者ID:seytar,项目名称:psx,代码行数:8,代码来源:CollectionTest.php
示例19: getShopUrls
/**
* Get list of shop urls
*
* @param bool $id_shop
* @return Collection
*/
public static function getShopUrls($id_shop = false)
{
$urls = new Collection('ShopUrl');
if ($id_shop) {
$urls->where('id_shop', '=', $id_shop);
}
return $urls;
}
开发者ID:jicheng17,项目名称:vipinsg,代码行数:14,代码来源:ShopUrl.php
示例20: fromCollection
public static function fromCollection(Collection $initialData)
{
$tree = new self();
foreach ($initialData->toArray() as $element) {
$tree->insert($element);
}
return $tree;
}
开发者ID:nathanklick,项目名称:collections,代码行数:8,代码来源:NaryTree.php
注:本文中的Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论