Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into development

This commit is contained in:
vAugagneur
2013-01-09 15:47:03 +01:00
2 changed files with 59 additions and 44 deletions
+7 -3
View File
@@ -295,13 +295,17 @@ class GroupCore extends ObjectModel
*/ */
public static function getCurrent() public static function getCurrent()
{ {
static $groups = array();
$customer = Context::getContext()->customer; $customer = Context::getContext()->customer;
$id_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
if (Validate::isLoadedObject($customer)) if (Validate::isLoadedObject($customer))
$id_group = (int)$customer->id_default_group; $id_group = (int)$customer->id_default_group;
else
$id_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
return new self($id_group); if (!isset($groups[$id_group]))
$groups[$id_group] = new Group($id_group);
return $groups[$id_group];
} }
} }
+50 -39
View File
@@ -170,7 +170,7 @@ abstract class ObjectModelCore
if (!ObjectModel::$db) if (!ObjectModel::$db)
ObjectModel::$db = Db::getInstance(); ObjectModel::$db = Db::getInstance();
$this->def = self::getDefinition($this); $this->def = ObjectModel::getDefinition($this);
$this->setDefinitionRetrocompatibility(); $this->setDefinitionRetrocompatibility();
if ($id_lang !== null) if ($id_lang !== null)
@@ -209,36 +209,37 @@ abstract class ObjectModelCore
// Get shop informations // Get shop informations
if (Shop::isTableAssociated($this->def['table'])) if (Shop::isTableAssociated($this->def['table']))
$sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop); $sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop);
if ($row = ObjectModel::$db->getRow($sql)) if ($object_datas = ObjectModel::$db->getRow($sql))
Cache::store($cache_id, $row); {
if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang'])
{
$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.$this->def['primary'].'` = '.(int)$id
.(($this->id_shop && $this->isLangMultishop()) ? ' AND `id_shop` = '.$this->id_shop : '');
if ($object_datas_lang = ObjectModel::$db->executeS($sql))
foreach ($object_datas_lang as $row)
foreach ($row as $key => $value)
{
if (array_key_exists($key, $this) && $key != $this->def['primary'])
{
if (!isset($object_datas[$key]) || !is_array($object_datas[$key]))
$object_datas[$key] = array();
$object_datas[$key][$row['id_lang']] = $value;
}
}
}
Cache::store($cache_id, $object_datas);
}
} }
else
$object_datas = Cache::retrieve($cache_id);
$result = Cache::retrieve($cache_id); if ($object_datas)
if ($result)
{ {
$this->id = (int)$id; $this->id = (int)$id;
foreach ($result as $key => $value) foreach ($object_datas as $key => $value)
if (array_key_exists($key, $this)) if (array_key_exists($key, $this))
$this->{$key} = $value; $this->{$key} = $value;
if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang'])
{
$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.$this->def['primary'].'` = '.(int)$id
.(($this->id_shop && $this->isLangMultishop()) ? ' AND `id_shop` = '.$this->id_shop : '');
$result = ObjectModel::$db->executeS($sql);
if ($result)
foreach ($result as $row)
foreach ($row as $key => $value)
{
if (array_key_exists($key, $this) && $key != $this->def['primary'])
{
if (!is_array($this->{$key}))
$this->{$key} = array();
$this->{$key}[$row['id_lang']] = $value;
}
}
}
} }
} }
@@ -1459,24 +1460,34 @@ abstract class ObjectModelCore
*/ */
public static function getDefinition($class, $field = null) public static function getDefinition($class, $field = null)
{ {
$reflection = new ReflectionClass($class);
$definition = $reflection->getStaticPropertyValue('definition');
if (is_object($class)) if (is_object($class))
$definition['classname'] = get_class($class); $class = get_class($class);
else
if ($field === null)
$cache_id = 'objectmodel_def_'.$class;
if ($field !== null || !Cache::isStored($cache_id))
{
$reflection = new ReflectionClass($class);
$definition = $reflection->getStaticPropertyValue('definition');
$definition['classname'] = $class; $definition['classname'] = $class;
if (!empty($definition['multilang'])) if (!empty($definition['multilang']))
$definition['associations'][Collection::LANG_ALIAS] = array( $definition['associations'][Collection::LANG_ALIAS] = array(
'type' => self::HAS_MANY, 'type' => self::HAS_MANY,
'field' => $definition['primary'], 'field' => $definition['primary'],
'foreign_field' => $definition['primary'], 'foreign_field' => $definition['primary'],
); );
if ($field) if ($field)
return isset($definition['fields'][$field]) ? $definition['fields'][$field] : null; return isset($definition['fields'][$field]) ? $definition['fields'][$field] : null;
return $definition;
Cache::store($cache_id, $definition);
return $definition;
}
return Cache::retrieve($cache_id);
} }
/** /**