Beispiel #1
0
 public function testFormatComplexQueryWithAliases()
 {
     $aliases = ["product.id" => "pid", "product_sale_elements.id" => "pseid", "product_sale_elements.quantity" => "stock"];
     $formatterData = new FormatterData($aliases);
     $query = ProductSaleElementsQuery::create()->useProductQuery()->addAsColumn("\"" . ProductTableMap::ID . "\"", ProductTableMap::ID)->endUse()->select([ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::QUANTITY])->limit(1);
     $formattedData = $formatterData->loadModelCriteria($query)->getData();
     /** @var array $data */
     $data = $query->findOne();
     $expectedData = [["pid" => $data["product.ID"], "pseid" => $data["product_sale_elements.ID"], "stock" => $data["product_sale_elements.QUANTITY"]]];
     $this->assertEquals($expectedData, $formattedData);
 }
Beispiel #2
0
 /**
  * @param  \Thelia\Model\Lang                               $lang
  * @return \Thelia\Core\FileFormat\Formatting\FormatterData
  *
  * The method builds the FormatterData for the formatter
  */
 public function buildData(Lang $lang)
 {
     $data = new FormatterData($this->getAliases());
     $query = $this->buildDataSet($lang);
     if ($query instanceof ModelCriteria) {
         return $data->loadModelCriteria($query);
     } elseif (is_array($query)) {
         return $data->setData($query);
     } elseif ($query instanceof BaseLoop) {
         $pagination = null;
         $results = $query->exec($pagination);
         for ($results->rewind(); $results->valid(); $results->next()) {
             $current = $results->current();
             $data->addRow($current->getVarVal());
         }
         return $data;
     }
     throw new InvalidValueException(Translator::getInstance()->trans("The method \"%class\"::buildDataSet must return an array or a ModelCriteria", ["%class" => get_class($this)]));
 }