在PHP中检查arangodb中的集合总数

时间:2016-10-27 14:22:53

标签: arangodb arangodb-php

如何在PHP中检查arangodb中的集合总数?

这就是我的尝试:

- (id)init
{
    self = [super init];
    if (self) {

        NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
        _receipt = receiptURL.absoluteString;
        NSLog(@"Receipt = %@", _receipt);
    }

    return self;
}

- (void)purchaseSmallCreditPackWithCompletion:(IAPManagerBlock)completionBlock failure:(IAPManagerBlock)failureBlock
{
    [self makePurchaseWithId:iap_SmallCreditPack completion:completionBlock failure:failureBlock];
}

- (void)purchaseMiddleCreditPackWithCompletion:(IAPManagerBlock)completionBlock failure:(IAPManagerBlock)failureBlock
{
    [self makePurchaseWithId:iap_MiddleCreditPack completion:completionBlock failure:failureBlock];
}

- (void)purchaseLargeCreditPackWithCompletion:(IAPManagerBlock)completionBlock failure:(IAPManagerBlock)failureBlock
{
    [self makePurchaseWithId:iap_LargeCreditPack completion:completionBlock failure:failureBlock];
}

- (void)makePurchaseWithId:(NSString *)idStr completion:(IAPManagerBlock)completionBlock failure:(IAPManagerBlock)failureBlock
{
    if ([SKPaymentQueue canMakePayments]) {

        _completionBlock = completionBlock;
        _failureBlock = failureBlock;

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:idStr]];
        productsRequest.delegate = self;
        [productsRequest start];
    }
    else
    {
        NSLog(@"This user can't make any payments");
    }
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    if (response.products.count == 0) {
        NSLog(@"There're no any products whatsoever");
        return;
    }

    SKProduct *product = [response.products firstObject];
    [self purchase:product];
}

- (void)purchase:(SKProduct *)product
{
    SKPayment *payment = [SKPayment paymentWithProduct:product];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions
{
    SKPaymentTransaction *transaction = [transactions firstObject];

    switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchasing:

            NSLog(@"Purchasing %@...", transaction.payment.productIdentifier);

            break;
        case SKPaymentTransactionStateFailed:
        {
            NSLog(@"Failed to purchase %@", transaction.payment.productIdentifier);

            if (_failureBlock) {
                _failureBlock();
            }

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
        }
            break;
        case SKPaymentTransactionStateRestored:
        {
            //just in case, we don't need to restore anything so far
            if (_completionBlock) {
                _completionBlock();
            }

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
        }
            break;
        case SKPaymentTransactionStatePurchased:
        {

            NSLog(@"Purchased %@", transaction.description);
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
            NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
            NSString *strReceipt = [receiptData base64EncodedStringWithOptions:0];
            //NSLog(@"strReceipt = %@", strReceipt);

        }
            break;
        default:
            break;
    }
}

- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray<SKPaymentTransaction *> *)transactions
{
    NSLog(@"Removed Transactions");

    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
}

1 个答案:

答案 0 :(得分:1)

要获取收藏数量,您可以使用CollectionHandler::getAllCollections()来实现此目的:

// create the connection as usual
$handler = new \triagens\ArangoDb\CollectionHandler($connection);
$collections = $handler->getAllCollections();
$collectionNames = array_values($collections);
$collectionCount = count($collectionNames);

要获取集合中的文档数量(如代码示例所示),请使用CollectionHandler::count($collection)