Example #1
0
$tito->reload();
echo "{$tito->name} has " . count($tito->orders) . " orders for: " . join(', ', ActiveRecord\collect($tito->orders, 'item_name')) . "\n\n";
// get all orders placed by Tito
foreach (Order::find_all_by_person_id($tito->id) as $order) {
    echo "Order #{$order->id} for {$order->item_name} (\${$order->price} + \${$order->tax} tax) ordered by " . $order->person->name . "\n";
    if (count($order->payments) > 0) {
        // display each payment for this order
        foreach ($order->payments as $payment) {
            echo "  payment #{$payment->id} of \${$payment->amount} by " . $payment->person->name . "\n";
        }
    } else {
        echo "  no payments\n";
    }
    echo "\n";
}
// display summary of all payments made by Tito and Jax
$conditions = array('conditions' => array('id IN(?)', array($tito->id, $jax->id)), 'order' => 'name desc');
foreach (Person::all($conditions) as $person) {
    $n = count($person->payments);
    $total = array_sum(ActiveRecord\collect($person->payments, 'amount'));
    echo "{$person->name} made {$n} payments for a total of \${$total}\n\n";
}
// using order has_many people through payments with options
// array('people', 'through' => 'payments', 'select' => 'people.*, payments.amount', 'conditions' => 'payments.amount < 200'));
// this means our people in the loop below also has the payment information since it is part of an inner join
// we will only see 2 of the people instead of 3 because 1 of the payments is greater than 200
$order = Order::find($pokemon->id);
echo "Order #{$order->id} for {$order->item_name} (\${$order->price} + \${$order->tax} tax)\n";
foreach ($order->people as $person) {
    echo "  payment of \${$person->amount} by " . $person->name . "\n";
}
Example #2
0
 public function test_collect_with_array_hash_using_string()
 {
     $this->assert_equals(array("0a", "1a"), ActiveRecord\collect($this->array_hash, "a"));
 }
Example #3
0
 private function limit($offset, $limit)
 {
     $ret = array();
     $sql = 'SELECT * FROM authors ORDER BY name ASC';
     $this->conn->query_and_fetch($this->conn->limit($sql, $offset, $limit), function ($row) use(&$ret) {
         $ret[] = $row;
     });
     return ActiveRecord\collect($ret, 'author_id');
 }
            $messages = Model_Message_Log::find_all_by_debt_recovery_id($debt_id);
            break;
    }
} else {
    $recovery_id = isset($_REQUEST['debt_recovery_id']) ? trim(strtolower($_REQUEST['debt_recovery_id'])) : 0;
    if ($recovery_id > 0) {
        $ids = Model_Debt_Recovery_Run::find_all_by_debt_recovery_id($recovery_id);
        switch ($message_type) {
            case 'sms':
                $messages = Model_Message_Log::all(array('conditions' => array('debt_recovery_id in (?) and module_name in (?) ', ActiveRecord\collect($ids, 'id'), array('higate'))));
                break;
            case 'email':
                $messages = Model_Message_Log::all(array('conditions' => array('debt_recovery_id in (?) and module_name in (?) ', ActiveRecord\collect($ids, 'id'), array('phpmailer'))));
                break;
            default:
                $messages = Model_Message_Log::all(array('order' => 'created_at desc', 'limit' => 100, 'offset' => 0, 'conditions' => array('debt_recovery_id in (?) ', ActiveRecord\collect($ids, 'id'))));
                break;
        }
    } else {
        $messages = Model_Message_Log::all(array('order' => 'created_at desc', 'limit' => 100, 'offset' => 0));
    }
}
if (count($messages) > 0) {
    ?>
<table width="100%" border="1">
    <thead>
        <tr>
            <th>Billing ID</th>
            <th>Customer</th>
            <th>Date Sent</th>
            <th>Cell Number</th>