/** * Set the Background Image * @param int $layoutId [description] * @param int $resolutionId [description] * @param string $color [description] * @param int $backgroundImageId [description] */ public function SetBackground($layoutId, $resolutionId, $color, $backgroundImageId, $zindex = NULL) { Debug::LogEntry('audit', 'IN', 'Layout', 'SetBackground'); try { $dbh = PDOConnect::init(); if ($layoutId == 0) { $this->ThrowError(__('Layout not selected')); } if ($resolutionId == 0) { $this->ThrowError(__('Resolution not selected')); } // Allow for the 0 media idea (no background image) if ($backgroundImageId == 0) { $bg_image = ''; } else { // Get the file URI $sth = $dbh->prepare('SELECT StoredAs FROM media WHERE MediaID = :mediaid'); $sth->execute(array('mediaid' => $backgroundImageId)); // Look up the bg image from the media id given if (!($row = $sth->fetch())) { $this->ThrowError(__('Cannot find the background image selected')); } $bg_image = Kit::ValidateParam($row['StoredAs'], _STRING); // Tag the background image as a background image $media = new Media(); $media->tag('background', $backgroundImageId); } // Look up the width and the height $sth = $dbh->prepare('SELECT intended_width, intended_height, width, height, version FROM resolution WHERE resolutionID = :resolutionid'); $sth->execute(array('resolutionid' => $resolutionId)); // Look up the bg image from the media id given if (!($row = $sth->fetch())) { return $this->SetError(__('Unable to get the Resolution information')); } $version = Kit::ValidateParam($row['version'], _INT); if ($version == 1) { $width = Kit::ValidateParam($row['width'], _INT); $height = Kit::ValidateParam($row['height'], _INT); } else { $width = Kit::ValidateParam($row['intended_width'], _INT); $height = Kit::ValidateParam($row['intended_height'], _INT); } $region = new region($this->db); $region->delayFinalise = $this->delayFinalise; if (!$region->EditBackground($layoutId, $color, $bg_image, $width, $height, $resolutionId, $zindex)) { throw new Exception("Error Processing Request", 1); } // Update the layout record with the new background $sth = $dbh->prepare('UPDATE layout SET backgroundimageid = :backgroundimageid WHERE layoutid = :layoutid'); $sth->execute(array('backgroundimageid' => $backgroundImageId, 'layoutid' => $layoutId)); // Check to see if we already have a LK record for this. $lkSth = $dbh->prepare('SELECT lklayoutmediaid FROM `lklayoutmedia` WHERE layoutid = :layoutid AND regionID = :regionid'); $lkSth->execute(array('layoutid' => $layoutId, 'regionid' => 'background')); if ($lk = $lkSth->fetch()) { // We have one if ($backgroundImageId != 0) { // Update it if (!$region->UpdateDbLink($lk['lklayoutmediaid'], $backgroundImageId)) { $this->ThrowError(__('Unable to update background link')); } } else { // Delete it if (!$region->RemoveDbLink($lk['lklayoutmediaid'])) { $this->ThrowError(__('Unable to remove background link')); } } } else { // None - do we need one? if ($backgroundImageId != 0) { if (!$region->AddDbLink($layoutId, 'background', $backgroundImageId)) { $this->ThrowError(__('Unable to create background link')); } } } // Is this layout valid $this->SetValid($layoutId); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { return $this->SetError(__("Unable to update background information")); } return false; } }
/** * Set the Background Image * @param int $layoutId [description] * @param int $resolutionId [description] * @param string $color [description] * @param int $backgroundImageId [description] */ public function SetBackground($layoutId, $resolutionId, $color, $backgroundImageId) { Debug::LogEntry('audit', 'IN', 'Layout', 'SetBackground'); try { $dbh = PDOConnect::init(); if ($layoutId == 0) { $this->ThrowError(__('Layout not selected')); } if ($layoutId == 0) { $this->ThrowError(__('Resolution not selected')); } // Allow for the 0 media idea (no background image) if ($backgroundImageId == 0) { $bg_image = ''; } else { // Get the file URI $sth = $dbh->prepare('SELECT StoredAs FROM media WHERE MediaID = :mediaid'); $sth->execute(array('mediaid' => $backgroundImageId)); // Look up the bg image from the media id given if (!($row = $sth->fetch())) { $this->ThrowError(__('Cannot find the background image selected')); } $bg_image = Kit::ValidateParam($row['StoredAs'], _STRING); } // Look up the width and the height $sth = $dbh->prepare('SELECT width, height FROM resolution WHERE resolutionID = :resolutionid'); $sth->execute(array('resolutionid' => $resolutionId)); // Look up the bg image from the media id given if (!($row = $sth->fetch())) { return $this->SetError(__('Unable to get the Resolution information')); } $width = Kit::ValidateParam($row['width'], _INT); $height = Kit::ValidateParam($row['height'], _INT); include_once "lib/data/region.data.class.php"; $region = new region($this->db); if (!$region->EditBackground($layoutId, '#' . $color, $bg_image, $width, $height, $resolutionId)) { throw new Exception("Error Processing Request", 1); } // Update the layout record with the new background $sth = $dbh->prepare('UPDATE layout SET background = :background WHERE layoutid = :layoutid'); $sth->execute(array('background' => $bg_image, 'layoutid' => $layoutId)); // Is this layout valid $this->SetValid($layoutId); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { return $this->SetError(__("Unable to update background information")); } return false; } }