samedi 22 octobre 2016

OOP design of app in php

So I have to create an object design for this application, it is just problem for practicing.

You are building application that will load data from several different advertising systems and then store the data into database, so it will be possible to analyze them.

You need to take in mind that every advertising system has different structure of report: Different named columns, different order of columns, different date formats Also data from ad systems are in different data formats(JSON,CSV,XML),

Reports from each system contains different amount of columns, our application is interested only in some of them: date, ad_campaing, ad_group, keyword, impressions, price (in every system they have different name)

Logic of advertising accounts is that one ad campaing contains multiple ad groups and one ad group contains multiple keywords.

So I need an Advertising_System class that will have method loadData which will load data from which report will be created, then I will need createReport method that will create a new report and save it to report array, then there should be a saveReport method which will save the report to the database. Next will be Report class, it will have variable for each column and with construct function it will instantiate a new Format object, which will have method isCSV, isXML, isJSON, it also will have a method formatDate and formatNumber. So, the format object should return an array with data that have uniform format. Okay I've got data that i wanted, but what now. My plan was to save them into columns variable in report, but since each ad_system could have different names of the columns then there should be probably method that will store names for each ad_system, and i could do something like method columnMatch that will iterate through array with column names that user specified and our returned data from format object, if match is found then i want to save that value in specific variable that does belong to is(eg. user named column as PRICE, in reported data it is as PRICE and i want to save it in variable COST), but since column name specified by user and in report could be also COST or howMuchItCosts etc.. then i don't know how to match the desired column with my variable. Also, i don't know how to handle ad_campaing, ad_group, keyword columns, should they be objects ? or just variables ?

<?php 


class Advertising_System {
    private $name = "";
    private $report = [];   
    private $column_names = [];
    private $data;

    public function loadData(){
        //load report data
    }


    public function createReport(){
        $this->report[] = new Report($this->data, $column_names);

    }
    public function setColumnNames(){
        //specify names of columns for this advertising system
    }

    public function saveReport($mysql){
        //save report to database

    }

}

class Report {

    protected $price;
    protected $impressions;
    protected $clicks;
    protected $conversions;
    protected $format;


    public function __construct($data, $column_names = []){
        $this->format = new Format();


    }

    private function matchColumns(){

    }

    public function setPrice($price){

    }

    public function setImpressions($impressions){

    }

    public function setClicks($clicks){

    }

    public function setConversions($conversions){

    }

    public function getAllColumns(){
    }
}

class Format {




    public function __construct($data){
        if(isJson($data))
            return json_decode($data);
        elseif(isXML($data))
            return xml_parse($data);
        elseif(isCSV($data))
            return csv_parse();
        else{
            "Dojebané";
        }
    }           

    public function isJson(){
        //check is data are in json format
    }   

    public function isXML(){
        //check if data are in xml format
    }   

    public function isCSV(){
        //check if data are in CSV format
    }

    public function formatDate(){
        //format date so it always has same format
    }

    public function formatNumber(){
        //format numbers so they always has same format
    }                                   
}

class Database {


    public function connect(){
        return mysql;
    }

}

Aucun commentaire:

Enregistrer un commentaire