示例#1
0
 /**
  * Get a record by ID
  * 
  * @param $id
  * @return ARRAY Record
  */
 public static function getAllInfo($id, $locale = 1)
 {
     $dq = Doctrine_Query::create()->from('Products p')->leftJoin('p.ProductsAttributesGroups pag')->leftJoin("p.ProductsData pd WITH pd.language_id = {$locale}")->leftJoin('p.Taxes t')->leftJoin('p.ProductsAttributesIndexes pai')->leftJoin('p.ProductsTranches pt')->leftJoin('pt.BillingCycle bc')->where('p.product_id = ?', $id)->addWhere("p.isp_id = ?", Isp::getCurrentId());
     $product = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     if (isset($product[0])) {
         if (array_key_exists('ProductsTranches', $product[0])) {
             $tranches = $product[0]['ProductsTranches'];
             $tranchesIndex = array();
             foreach ($tranches as $tranche) {
                 $tranchesIndex[$tranche['tranche_id']] = $tranche;
             }
             unset($product[0]['ProductsTranches']);
             $product[0]['ProductsTranches'] = $tranchesIndex;
         }
         // Handle the Attributes Values
         if (!empty($product[0]['ProductsAttributesIndexes'])) {
             $attributes = $product[0]['ProductsAttributesIndexes'];
             foreach ($attributes as $attribute) {
                 $attr = ProductsAttributes::find($attribute['attribute_id']);
                 $code = $attr['code'];
                 $product[0][$code] = $attribute['value'];
             }
             unset($product[0]['ProductsAttributesIndexes']);
         }
         return $product[0];
     } else {
         return array();
     }
 }