1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 
<?php
/* --------------------------------------------------------------
 ParcelTrackingCodeFinder.inc.php 2018-01-15
 Gambio GmbH
 http://www.gambio.de
 Copyright (c) 2018 Gambio GmbH
 Released under the GNU General Public License (Version 2)
 [http://www.gnu.org/licenses/gpl-2.0.html]
 --------------------------------------------------------------
 */

/**
 * Class ParcelTrackingCodeFinder
 */
class ParcelTrackingCodeFinder
{
    /**
     * @var \CI_DB_query_builder
     */
    protected $db;
    
    /**
     * @var string
     */
    protected $table = 'orders_parcel_tracking_codes';
    
    
    /**
     * ParcelTrackingCodeFinder constructor.
     *
     * @param \CI_DB_query_builder $db Database access.
     */
    public function __construct(CI_DB_query_builder $db)
    {
        $this->db = $db;
    }
    
    
    /**
     * Returns parcel tracking code data by the given tracking code id.
     *
     * @param \ParcelTrackingCodeId $id Id of searched parcel tracking code entry.
     *
     * @return array
     */
    public function find(ParcelTrackingCodeId $id)
    {
        return $this->db->where('orders_parcel_tracking_code_id', $id->is())->get($this->table)->row_array() ? : [];
    }
    
    
    /**
     * Returns parcel tracking codes data by the given order id.
     *
     * @param \ParcelTrackingCodeOrderId $orderId Id of order.
     *
     * @return array
     */
    public function findByOrderId(ParcelTrackingCodeOrderId $orderId)
    {
        return $this->db->where('order_id', $orderId->is())->get($this->table)->result_array() ? : [];
    }
    
    
    /**
     * Returns all parcel tracking code data.
     *
     * @return array
     */
    public function getAll()
    {
        return $this->db->get($this->table)->result_array() ? : [];
    }
}