Ui/DataProvider/Downline/Grid/A/Repo/Query/Grid.php
protected function getQueryItems()
    {
        $result = $this->conn->select();

        /* define tables aliases for internal usage (in this method) */
        $asCust = self::AS_CUST;
        $asDwnlBon = self::AS_DWNL_BON;
        $asDwnlCust = self::AS_DWNL_CUST;
        $asDwnlParent = self::AS_DWNL_PARENT;
        $asParent = self::AS_PARENT;
        $asRank = self::AS_RANK;

        /* SELECT FROM prxgt_bon_hyb_dwnl */
        $tbl = $this->resource->getTableName(self::E_BON);
        $as = $asDwnlBon;
        $cols = [
            self::A_CALC_ID => EBonDwnl::A_CALC_REF,
            self::A_CUST_ID => EBonDwnl::A_CUST_REF,
            self::A_DEPTH => EBonDwnl::A_DEPTH,
            self::A_OV => EBonDwnl::A_OV,
            self::A_PARENT_ID => EBonDwnl::A_PARENT_REF,
            self::A_PATH => EBonDwnl::A_PATH,
            self::A_PV => EBonDwnl::A_PV,
            self::A_TV => EBonDwnl::A_TV,
            self::A_MONTH_UNQ => EBonDwnl::A_UNQ_MONTHS
        ];
        $result->from([$as => $tbl], $cols);

        /* LEFT JOIN prxgt_bon_base_rank */
        $tbl = $this->resource->getTableName(self::E_RANK);
        $as = $asRank;
        $cols = [
            self::A_RANK => ERank::A_CODE
        ];
        $cond = $as . '.' . ERank::A_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_RANK_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN prxgt_dwnl_customer as customer */
        $tbl = $this->resource->getTableName(self::E_DWNL);
        $as = $asDwnlCust;
        $cols = [
            self::A_CUST_MLM_ID => EDwnlCust::A_MLM_ID
        ];
        $cond = $as . '.' . EDwnlCust::A_CUSTOMER_REF . '=' . $asDwnlBon . '.' . EBonDwnl::A_CUST_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN customer_entity as customer */
        $tbl = $this->resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
        $as = $asCust;
        $exp = $this->expFullNameCust();
        $cols = [
            self::A_CUST_NAME => $exp
        ];
        $cond = $as . '.' . Cfg::E_CUSTOMER_A_ENTITY_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_CUST_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN prxgt_dwnl_customer as parent */
        $tbl = $this->resource->getTableName(self::E_DWNL);
        $as = $asDwnlParent;
        $cols = [
            self::A_PARENT_MLM_ID => EDwnlCust::A_MLM_ID
        ];
        $cond = $as . '.' . EDwnlCust::A_CUSTOMER_REF . '=' . $asDwnlBon . '.' . EBonDwnl::A_PARENT_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN customer_entity as parent */
        $tbl = $this->resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
        $as = $asParent;
        $exp = $this->expFullNameParent();
        $cols = [
            self::A_PARENT_NAME => $exp
        ];
        $cond = $as . '.' . Cfg::E_CUSTOMER_A_ENTITY_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_PARENT_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* WHERE */
        $byCust = "$asDwnlBon." . EBonDwnl::A_CALC_REF . "=:" . self::BND_CALC_ID;
        $result->where($byCust);

        /* return  result */
        return $result;
    }
protected function getQueryItems()
    {
        $result = $this->conn->select();

        /* define tables aliases for internal usage (in this method) */
        $asCust = self::AS_CUST;
        $asDwnlBon = self::AS_DWNL_BON;
        $asDwnlCust = self::AS_DWNL_CUST;
        $asDwnlParent = self::AS_DWNL_PARENT;
        $asParent = self::AS_PARENT;
        $asRank = self::AS_RANK;

        /* SELECT FROM prxgt_bon_hyb_dwnl */
        $tbl = $this->resource->getTableName(self::E_BON);
        $as = $asDwnlBon;
        $cols = [
            self::A_CALC_ID => EBonDwnl::A_CALC_REF,
            self::A_CUST_ID => EBonDwnl::A_CUST_REF,
            self::A_DEPTH => EBonDwnl::A_DEPTH,
            self::A_OV => EBonDwnl::A_OV,
            self::A_PARENT_ID => EBonDwnl::A_PARENT_REF,
            self::A_PATH => EBonDwnl::A_PATH,
            self::A_PV => EBonDwnl::A_PV,
            self::A_TV => EBonDwnl::A_TV,
            self::A_MONTH_UNQ => EBonDwnl::A_UNQ_MONTHS
        ];
        $result->from([$as => $tbl], $cols);

        /* LEFT JOIN prxgt_bon_base_rank */
        $tbl = $this->resource->getTableName(self::E_RANK);
        $as = $asRank;
        $cols = [
            self::A_RANK => ERank::A_CODE
        ];
        $cond = $as . '.' . ERank::A_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_RANK_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN prxgt_dwnl_customer as customer */
        $tbl = $this->resource->getTableName(self::E_DWNL);
        $as = $asDwnlCust;
        $cols = [
            self::A_CUST_MLM_ID => EDwnlCust::A_MLM_ID
        ];
        $cond = $as . '.' . EDwnlCust::A_CUSTOMER_REF . '=' . $asDwnlBon . '.' . EBonDwnl::A_CUST_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN customer_entity as customer */
        $tbl = $this->resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
        $as = $asCust;
        $exp = $this->expFullNameCust();
        $cols = [
            self::A_CUST_NAME => $exp
        ];
        $cond = $as . '.' . Cfg::E_CUSTOMER_A_ENTITY_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_CUST_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN prxgt_dwnl_customer as parent */
        $tbl = $this->resource->getTableName(self::E_DWNL);
        $as = $asDwnlParent;
        $cols = [
            self::A_PARENT_MLM_ID => EDwnlCust::A_MLM_ID
        ];
        $cond = $as . '.' . EDwnlCust::A_CUSTOMER_REF . '=' . $asDwnlBon . '.' . EBonDwnl::A_PARENT_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* LEFT JOIN customer_entity as parent */
        $tbl = $this->resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
        $as = $asParent;
        $exp = $this->expFullNameParent();
        $cols = [
            self::A_PARENT_NAME => $exp
        ];
        $cond = $as . '.' . Cfg::E_CUSTOMER_A_ENTITY_ID . '=' . $asDwnlBon . '.' . EBonDwnl::A_PARENT_REF;
        $result->joinLeft([$as => $tbl], $cond, $cols);

        /* WHERE */
        $byCust = "$asDwnlBon." . EBonDwnl::A_CALC_REF . "=:" . self::BND_CALC_ID;
        $result->where($byCust);

        /* return  result */
        return $result;
    }
protected function getQueryItems ( ) { $ result = $ this -> conn -> select ( ) ; /* define tables aliases for internal usage (in this method) */ $ asCust = self :: AS_CUST ; $ asDwnlBon = self :: AS_DWNL_BON ; $ asDwnlCust = self :: AS_DWNL_CUST ; $ asDwnlParent = self :: AS_DWNL_PARENT ; $ asParent = self :: AS_PARENT ; $ asRank = self :: AS_RANK ; /* SELECT FROM prxgt_bon_hyb_dwnl */ $ tbl = $ this -> resource -> getTableName ( self :: E_BON ) ; $ as = $ asDwnlBon ; $ cols = [ self :: A_CALC_ID => EBonDwnl :: A_CALC_REF , self :: A_CUST_ID => EBonDwnl :: A_CUST_REF , self :: A_DEPTH => EBonDwnl :: A_DEPTH , self :: A_OV => EBonDwnl :: A_OV , self :: A_PARENT_ID => EBonDwnl :: A_PARENT_REF , self :: A_PATH => EBonDwnl :: A_PATH , self :: A_PV => EBonDwnl :: A_PV , self :: A_TV => EBonDwnl :: A_TV , self :: A_MONTH_UNQ => EBonDwnl :: A_UNQ_MONTHS ] ; $ result -> from ( [ $ as => $ tbl ] , $ cols ) ; /* LEFT JOIN prxgt_bon_base_rank */ $ tbl = $ this -> resource -> getTableName ( self :: E_RANK ) ; $ as = $ asRank ; $ cols = [ self :: A_RANK => ERank :: A_CODE ] ; $ cond = $ as . '.' . ERank :: A_ID . '=' . $ asDwnlBon . '.' . EBonDwnl :: A_RANK_REF ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; /* LEFT JOIN prxgt_dwnl_customer as customer */ $ tbl = $ this -> resource -> getTableName ( self :: E_DWNL ) ; $ as = $ asDwnlCust ; $ cols = [ self :: A_CUST_MLM_ID => EDwnlCust :: A_MLM_ID ] ; $ cond = $ as . '.' . EDwnlCust :: A_CUSTOMER_REF . '=' . $ asDwnlBon . '.' . EBonDwnl :: A_CUST_REF ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; /* LEFT JOIN customer_entity as customer */ $ tbl = $ this -> resource -> getTableName ( Cfg :: ENTITY_MAGE_CUSTOMER ) ; $ as = $ asCust ; $ exp = $ this -> expFullNameCust ( ) ; $ cols = [ self :: A_CUST_NAME => $ exp ] ; $ cond = $ as . '.' . Cfg :: E_CUSTOMER_A_ENTITY_ID . '=' . $ asDwnlBon . '.' . EBonDwnl :: A_CUST_REF ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; /* LEFT JOIN prxgt_dwnl_customer as parent */ $ tbl = $ this -> resource -> getTableName ( self :: E_DWNL ) ; $ as = $ asDwnlParent ; $ cols = [ self :: A_PARENT_MLM_ID => EDwnlCust :: A_MLM_ID ] ; $ cond = $ as . '.' . EDwnlCust :: A_CUSTOMER_REF . '=' . $ asDwnlBon . '.' . EBonDwnl :: A_PARENT_REF ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; /* LEFT JOIN customer_entity as parent */ $ tbl = $ this -> resource -> getTableName ( Cfg :: ENTITY_MAGE_CUSTOMER ) ; $ as = $ asParent ; $ exp = $ this -> expFullNameParent ( ) ; $ cols = [ self :: A_PARENT_NAME => $ exp ] ; $ cond = $ as . '.' . Cfg :: E_CUSTOMER_A_ENTITY_ID . '=' . $ asDwnlBon . '.' . EBonDwnl :: A_PARENT_REF ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; /* WHERE */ $ byCust = "$asDwnlBon." . EBonDwnl :: A_CALC_REF . "=:" . self :: BND_CALC_ID ; $ result -> where ( $ byCust ) ; /* return  result */ return $ result ; }
SELECT
`dwnlBon`.`calc_ref` AS `calcId`,
`dwnlBon`.`cust_ref` AS `custId`,
`dwnlBon`.`depth`,
`dwnlBon`.`ov`,
`dwnlBon`.`parent_ref` AS `parentId`,
`dwnlBon`.`path`,
`dwnlBon`.`pv`,
`dwnlBon`.`tv`,
`dwnlBon`.`unq_months` AS `monthUnq`,
`ranks`.`code` AS `rank`,
`dwnlCust`.`mlm_id` AS `custMlmId`,
(CONCAT(cust.firstname,
" ",
cust.lastname)) AS `custName`,
`dwnlParent`.`mlm_id` AS `parentMlmId`,
(CONCAT(parent.firstname,
" ",
parent.lastname)) AS `parentName`
FROM
`prxgt_bon_hyb_dwnl` AS `dwnlBon`
LEFT JOIN `prxgt_bon_base_rank` AS `ranks` ON
ranks.id = dwnlBon.rank_ref
LEFT JOIN `prxgt_dwnl_customer` AS `dwnlCust` ON
dwnlCust.customer_ref = dwnlBon.cust_ref
LEFT JOIN `customer_entity` AS `cust` ON
cust.entity_id = dwnlBon.cust_ref
LEFT JOIN `prxgt_dwnl_customer` AS `dwnlParent` ON
dwnlParent.customer_ref = dwnlBon.parent_ref
LEFT JOIN `customer_entity` AS `parent` ON
parent.entity_id = dwnlBon.parent_ref
WHERE
(dwnlBon.calc_ref =:calcId)
SELECT dwnlBon . calc_ref AS calcId dwnlBon . cust_ref AS custId dwnlBon . depth dwnlBon . ov dwnlBon . parent_ref AS parentId dwnlBon . path dwnlBon . pv dwnlBon . tv dwnlBon . unq_months AS monthUnq ranks . code AS rank dwnlCust . mlm_id AS custMlmId ( CONCAT ( cust . firstname cust . lastname )) AS custName dwnlParent . mlm_id AS parentMlmId ( CONCAT ( parent . firstname parent . lastname )) AS parentName FROM prxgt_bon_hyb_dwnl AS dwnlBon LEFT JOIN prxgt_bon_base_rank AS ranks ON ranks . id = dwnlBon . rank_ref LEFT JOIN prxgt_dwnl_customer AS dwnlCust ON dwnlCust . customer_ref = dwnlBon . cust_ref LEFT JOIN customer_entity AS cust ON cust . entity_id = dwnlBon . cust_ref LEFT JOIN prxgt_dwnl_customer AS dwnlParent ON dwnlParent . customer_ref = dwnlBon . parent_ref LEFT JOIN customer_entity AS parent ON parent . entity_id = dwnlBon . parent_ref WHERE ( dwnlBon . calc_ref = : calcId )