protected function _getDefaultImageId()
{
if ($this->countImages()) {
if ($default = $this->get('default')) {
return $default;
}
$keys = $this->listImages();
$this->set('default', $keys[count($keys) - 1]);
$this->set('default_type', 'auto');
$this->save();
return $keys[count($keys) - 1];
}
if ($this->hasSubGalleries()) {
try {
$galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->id, 'all_levels' => false));
foreach ($galleries as $gallery) {
if ($default_img = $gallery->getKeyImage()) {
return $default_img;
}
}
} catch (Ansel_Exception $e) {
return false;
}
}
}