Skip to content

Instantly share code, notes, and snippets.

@oojacoboo
Created May 17, 2013 02:07
Show Gist options
  • Select an option

  • Save oojacoboo/5596460 to your computer and use it in GitHub Desktop.

Select an option

Save oojacoboo/5596460 to your computer and use it in GitHub Desktop.
/**
* Returns back the value for the setting name passed
* @param string $name
* @return mixed
*/
public function getSetting($name) {
$companyId = $this->getId();
$planId = $this->getPlanId();
$con = Propel::getConnection();
$query = '
SELECT COALESCE(
(
SELECT cs.value
FROM company_setting cs
LEFT JOIN default_setting ds
ON cs.default_setting_id = ds.id
WHERE cs.company_id = :companyId
AND ds.name = :settingName
),
(
SELECT ps.value
FROM plan_setting ps
LEFT JOIN default_setting ds
ON ps.default_setting_id = ds.id
WHERE ps.plan_id = :planId
AND ds.name = :settingName
),
(
SELECT ds.value
FROM default_setting ds
WHERE ds.name = :settingName
)
) AS value';
$stmt = $con->prepare($query);
$stmt->bindParam(":settingName", $name, PDO::PARAM_STR);
$stmt->bindParam(":companyId", $companyId, PDO::PARAM_INT);
$stmt->bindParam(":planId", $planId, PDO::PARAM_INT);
$stmt->execute();
$setting = $stmt->fetch(PDO::FETCH_NUM);
if($setting[0] === "1")
$value = true;
elseif($setting[0] === "0")
$value = false;
else
$value = $setting[0];
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment