Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Code Igniter question...

I'm trying to trace the logic of an app that's already built and I wanted somebody's eyes on this besides my own.

I "think" I've figured out what I need to do, it all depends on this construct.

The thing I'm trying to confirm is whether or not "StatementImage.php" is part of the process that you see below:

require_once __dir__."/AbstractStatementPDFGenerator.php";
class StandardStatementPDFGenerator extends AbstractStatementPDFGenerator {

    //STATE VARIABLES
    // Current Index is the row of the current table that we are trying to print.
    protected $current_index = 0;
    // Broken is set the table in question if we are part-way through printing a table when we reach the end of the page.
    protected $broken_tbl = false;

    protected $finished = false;

    protected $drawstatus;

    //Statement Types
    const TYPE_LOW_BALANCE = 0;
    const TYPE_NO_PAYMENT_PLAN = 1;
    const TYPE_PAYMENTPLAN = 2;

    protected $STATEMENT_TYPE;

    public function __construct(StatementImage $statement){
        $data = $statement->getData();
        $this->STATEMENT_TYPE = count($data['paymentplan']) > 0 ? StandardStatementPDFGenerator::TYPE_PAYMENTPLAN : ( count($data['paymentplan_options']) > 0 ? StandardStatementPDFGenerator::TYPE_NO_PAYMENT_PLAN : StandardStatementPDFGenerator::TYPE_LOW_BALANCE );
        parent::__construct($statement);
    }

Open in new window


On line 21 you see public function __construct(StatementImage $statement)v{. Is that calling StatementImage.php? I believe it is, partially because of the next line where it asks for "getData();." That function is on the StatementImage.php page.

Could someone confirm whether or not I'm correct in my analysis? I'm hesitant because I don't see "StatementImage.php," although that seems to be consistent with Code Igniter protocol.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marco Gasi
As what I can argue from the code, in AbstractStatementPDFGenerator.php there is a class called StatementImage, so in your counstructor this class is passed as paramter and the class is hold by the $statement variable which becomes n instance of the class itself. Then, the code can use StatementImage functions using $statement instance of the class.

A more correct approach would be converting the class StatementImage into a CI library and then loading the library. Prctically, you should create a file called StatementImage.php in your application/libraries folder and paste within this file the whole code of the StatementImage class.

Once this is done, you can load the library instead of requiring the php file and then you can use it this way:
//no need to require external file since we use our library
//require_once __dir__."/AbstractStatementPDFGenerator.php";
class StandardStatementPDFGenerator extends AbstractStatementPDFGenerator {

    //STATE VARIABLES
    // Current Index is the row of the current table that we are trying to print.
    protected $current_index = 0;
    // Broken is set the table in question if we are part-way through printing a table when we reach the end of the page.
    protected $broken_tbl = false;

    protected $finished = false;

    protected $drawstatus;

    //Statement Types
    const TYPE_LOW_BALANCE = 0;
    const TYPE_NO_PAYMENT_PLAN = 1;
    const TYPE_PAYMENTPLAN = 2;

    protected $STATEMENT_TYPE;

    public function __construct(StatementImage $statement){
        $this->load->library('StatementImage');
        $data = $this->StatementImage->getData();
        $this->STATEMENT_TYPE = count($data['paymentplan']) > 0 ? StandardStatementPDFGenerator::TYPE_PAYMENTPLAN : ( count($data['paymentplan_options']) > 0 ? StandardStatementPDFGenerator::TYPE_NO_PAYMENT_PLAN : StandardStatementPDFGenerator::TYPE_LOW_BALANCE );
//        no need to call the library's constructor
//        parent::__construct($statement);
    }

Open in new window


Depending on CI version, you can find more help on this in CI online help. For CI 3.x you can red this: https://www.codeigniter.com/user_guide/general/creating_libraries.html. A good example is here: http://www.coderiddles.com/creating-custom-library-in-codeigniter/
Avatar of Bruce Gust

ASKER

Excellent, Ray! Thank you!