Give_Customer::get_notes PHP Method

get_notes() public method

Get the parsed notes for a customer as an array.
Since: 1.0
public get_notes ( integer $length = 20, integer $paged = 1 ) : array
$length integer The number of notes to get.
$paged integer What note to start at.
return array The notes requested.
    public function get_notes($length = 20, $paged = 1)
    {
        $length = is_numeric($length) ? $length : 20;
        $offset = is_numeric($paged) && $paged != 1 ? (absint($paged) - 1) * $length : 0;
        $all_notes = $this->get_raw_notes();
        $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
        $desired_notes = array_slice($notes_array, $offset, $length);
        return $desired_notes;
    }

Usage Example

Esempio n. 1
0
 public function test_customer_notes()
 {
     $customer = new Give_Customer('*****@*****.**');
     $this->assertInternalType('array', $customer->notes);
     $this->assertEquals(0, $customer->get_notes_count());
     $note_1 = $customer->add_note('Testing');
     $this->assertEquals(0, array_search($note_1, $customer->notes));
     $this->assertEquals(1, $customer->get_notes_count());
     $note_2 = $customer->add_note('Test 2nd Note');
     $this->assertEquals(1, array_search($note_1, $customer->notes));
     $this->assertEquals(0, array_search($note_2, $customer->notes));
     $this->assertEquals(2, $customer->get_notes_count());
     // Verify we took out all empty rows
     $this->assertEquals(count($customer->notes), count(array_values($customer->notes)));
     // Test 1 note per page, page 1
     $newest_note = $customer->get_notes(1);
     $this->assertEquals(1, count($newest_note));
     $this->assertEquals($newest_note[0], $note_2);
     // Test 1 note per page, page 2
     $second_note = $customer->get_notes(1, 2);
     $this->assertEquals(1, count($second_note));
     $this->assertEquals($second_note[0], $note_1);
 }