예제 #1
0
파일: Standard.php 프로젝트: rpquadrat/core
 /**
  * Validate data and remove non-available attributes
  *
  * @param array $arrData
  *
  * @return $this
  */
 public function setRow(array $arrData)
 {
     if ($arrData['pid'] > 0) {
         // Do not use the model, it would trigger setRow and generate too much
         // @deprecated use static::buildFindQuery once we drop BC support for buildQueryString
         /** @type object $objParent */
         $objParent = \Database::getInstance()->prepare(static::buildQueryString(array('table' => static::$strTable, 'column' => 'id')))->execute($arrData['pid']);
         if (null === $objParent) {
             throw new \UnderflowException('Parent record of product variant ID ' . $arrData['id'] . ' not found');
         }
         $this->setRow($objParent->row());
         // Must be set before call to getInheritedFields()
         $this->arrData['id'] = $arrData['id'];
         $this->arrData['pid'] = $arrData['pid'];
         $this->arrData['inherit'] = $arrData['inherit'];
         // Set all variant attributes, except if they are inherited
         $arrFallbackFields = Attribute::getFetchFallbackFields();
         $arrVariantFields = array_diff($this->getVariantAttributes(), $this->getInheritedFields());
         foreach ($arrData as $attribute => $value) {
             if (in_array($attribute, $arrVariantFields) || $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute]['attributes']['legend'] == '' && !in_array(str_replace('_fallback', '', $attribute), $arrFallbackFields)) {
                 $this->arrData[$attribute] = $arrData[$attribute];
                 if (in_array($attribute, $arrFallbackFields)) {
                     $this->arrData[$attribute . '_fallback'] = $arrData[$attribute . '_fallback'];
                 }
             }
         }
         // Make sure publishing settings match product and variant (see #1120)
         $this->arrData['published'] = $objParent->published ? $arrData['published'] : '';
         $this->arrData['start'] = $objParent->start != '' && ($arrData['start'] == '' || $objParent->start > $arrData['start']) ? $objParent->start : $arrData['start'];
         $this->arrData['stop'] = $objParent->stop != '' && ($arrData['stop'] == '' || $objParent->stop < $arrData['stop']) ? $objParent->stop : $arrData['stop'];
         return $this;
     }
     // Empty cache
     $this->objPrice = false;
     $this->arrAttributes = null;
     $this->arrVariantAttributes = null;
     $this->arrVariantIds = null;
     $this->arrCategories = null;
     $this->arrRelated = array();
     // Must initialize product type to have attributes etc.
     if (($this->arrRelated['type'] = ProductType::findByPk($arrData['type'])) === null) {
         throw new \UnderflowException('Product type for product ID ' . $arrData['id'] . ' not found');
     }
     $this->strFormId = 'iso_product_' . $arrData['id'];
     // Remove attributes not in this product type
     foreach ($arrData as $attribute => $value) {
         if (!in_array($attribute, $this->getAttributes()) && !in_array($attribute, $this->getVariantAttributes()) && isset($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute]['attributes']['legend']) && $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute]['attributes']['legend'] != '' || in_array($attribute, Attribute::getVariantOptionFields())) {
             unset($arrData[$attribute]);
         }
     }
     return parent::setRow($arrData);
 }
예제 #2
0
파일: Product.php 프로젝트: Aziz-JH/core
 /**
  * Return select statement to load product data including multilingual fields
  * @param array an array of columns
  * @return string
  */
 protected static function buildFindQuery(array $arrOptions)
 {
     $objBase = new \DcaExtractor($arrOptions['table']);
     $arrJoins = array();
     $arrFields = array($arrOptions['table'] . ".*", "IF(" . $arrOptions['table'] . ".pid>0, parent.type, " . $arrOptions['table'] . ".type) AS type", "'" . str_replace('-', '_', $GLOBALS['TL_LANGUAGE']) . "' AS language");
     foreach (Attribute::getMultilingualFields() as $attribute) {
         $arrFields[] = "IFNULL(translation.{$attribute}, " . $arrOptions['table'] . ".{$attribute}) AS {$attribute}";
     }
     foreach (Attribute::getFetchFallbackFields() as $attribute) {
         $arrFields[] = "{$arrOptions['table']}.{$attribute} AS {$attribute}_fallback";
     }
     $arrFields[] = "c.sorting";
     $arrJoins[] = " LEFT OUTER JOIN " . \Isotope\Model\ProductCategory::getTable() . " c ON {$arrOptions['table']}.id=c.pid";
     $arrJoins[] = " LEFT OUTER JOIN " . $arrOptions['table'] . " translation ON " . $arrOptions['table'] . ".id=translation.pid AND translation.language='" . str_replace('-', '_', $GLOBALS['TL_LANGUAGE']) . "'";
     $arrJoins[] = " LEFT OUTER JOIN " . $arrOptions['table'] . " parent ON " . $arrOptions['table'] . ".pid=parent.id";
     if ($objBase->hasRelations()) {
         $intCount = 0;
         foreach ($objBase->getRelations() as $strKey => $arrConfig) {
             // Automatically join the single-relation records
             if ($arrConfig['load'] == 'eager' || $arrOptions['eager']) {
                 if ($arrConfig['type'] == 'hasOne' || $arrConfig['type'] == 'belongsTo') {
                     if (is_array($arrOptions['joinAliases']) && ($key = array_search($arrConfig['table'], $arrOptions['joinAliases'])) !== false) {
                         $strJoinAlias = $key;
                         unset($arrOptions['joinAliases'][$key]);
                     } else {
                         ++$intCount;
                         $strJoinAlias = 'j' . $intCount;
                     }
                     $objRelated = new \DcaExtractor($arrConfig['table']);
                     foreach (array_keys($objRelated->getFields()) as $strField) {
                         $arrFields[] = $strJoinAlias . '.' . $strField . ' AS ' . $strKey . '__' . $strField;
                     }
                     $arrJoins[] = " LEFT JOIN " . $arrConfig['table'] . " {$strJoinAlias} ON " . $arrOptions['table'] . "." . $strKey . "={$strJoinAlias}.id";
                 }
             }
         }
     }
     // Generate the query
     $strQuery = "SELECT " . implode(', ', $arrFields) . " FROM " . $arrOptions['table'] . implode("", $arrJoins);
     // Where condition
     if (!is_array($arrOptions['column'])) {
         $arrOptions['column'] = array($arrOptions['table'] . '.' . $arrOptions['column'] . '=?');
     }
     // The model must never find a language record
     $strQuery .= " WHERE {$arrOptions['table']}.language='' AND " . implode(" AND ", $arrOptions['column']);
     // Group by
     if ($arrOptions['group'] !== null) {
         $strQuery .= " GROUP BY " . $arrOptions['group'];
     }
     // Order by
     if ($arrOptions['order'] !== null) {
         $strQuery .= " ORDER BY " . $arrOptions['order'];
     }
     return $strQuery;
 }