public function createFromDb($id)
 {
     try {
         $wmc = new wmc();
         $res = $wmc->createFromDb($id);
         if ($res === false) {
             throw new Exception("Could not create WMC from DB.");
         }
     } catch (Exception $e) {
         throw new Exception("Could not create WMC from DB.");
     }
     return $wmc;
 }
function initWmcById($wmcId, $wmcAction)
{
    $wmc = new wmc();
    $wmc->createFromDb($wmcId);
    $updatedWMC = $wmc->updateUrlsFromDb();
    $wmc->createFromXml($updatedWMC);
    $jsArray = $wmc->toJavaScript();
    if ($jsArray) {
        $jsString = implode("", $jsArray);
        echo $jsString;
    } else {
        $e = new mb_exception("WMC could not be loaded.");
    }
}
     // load the merged WMC
     $jsArray = $currentWmc->toJavaScript();
     if (is_array($jsArray) && count($jsArray) > 0) {
         $resultObj["javascript"] = $jsArray;
         $ajaxResponse->setResult($resultObj);
         $ajaxResponse->setSuccess(true);
     } else {
         $ajaxResponse->setMessage(_mb("WMC could not be appended."));
         $ajaxResponse->setSuccess(false);
     }
     break;
 case 'setWMCPublic':
     $wmcId = $ajaxResponse->getParameter("id");
     $public = $ajaxResponse->getParameter("isPublic") == 1 ? true : false;
     $wmc = new wmc();
     $wmc->createFromDb($wmcId);
     if ($wmc->setPublic($public)) {
         $ajaxResponse->setMessage(_mb("Updated public flag"));
         $ajaxResponse->setSuccess(true);
     } else {
         $ajaxResponse->setMessage(_mb("could not update public flag"));
         $ajaxResponse->setSuccess(false);
     }
     break;
 case 'checkConstraints':
     $checkLayerIdExists = $ajaxResponse->getParameter("checkLayerIdExists");
     $checkLayerIdValid = $ajaxResponse->getParameter("checkLayerIdValid");
     $checkLayerPermission = $ajaxResponse->getParameter("checkLayerPermission");
     $checkLayerAvailability = $ajaxResponse->getParameter("checkLayerAvailability");
     $wmcId = $ajaxResponse->getParameter("id");
     $wmc->createFromDb($wmcId);