public function chooseTemplate($params) { $userId = (int) $params['userId']; $this->checkCredits(); $templateId = (int) $params['templateId']; $reposition = false; //(bool) $params['reposition']; $template = $this->service->findTemplateById($templateId); if ($template === null) { return array("error" => "Template was not found!"); } $status = $reposition ? UHEADER_BOL_Cover::STATUS_TMP : UHEADER_BOL_Cover::STATUS_ACTIVE; $cover = $template->createCover($userId, $status); $eventName = null; if (!$reposition) { $activeCover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_ACTIVE); $eventName = $activeCover === null ? UHEADER_BOL_Service::EVENT_ADD : UHEADER_BOL_Service::EVENT_CHANGE; } $this->service->deleteCoverByUserId($userId, $status); $this->service->saveCover($cover); if ($eventName !== null) { $src = $cover->getSrc(); $event = new OW_Event($eventName, array('userId' => $userId, 'id' => $cover->id, 'file' => $cover->file, 'path' => $this->service->getCoverPath($cover), 'src' => $src, 'data' => $cover->getSettings()), $cover->getSettings()); OW::getEventManager()->trigger($event); } return array('src' => $cover->getSrc(), 'data' => $cover->getSettings(), 'ratio' => $cover->getRatio(), "mode" => $reposition ? "reposition" : "view"); }
public function saveInfo($coverData) { $info = $coverData["info"]; $tplId = (int) $coverData['tplId']; $tpl = $this->service->findTemplateById($tplId); /* @var UHEADER_BOL_Template $tpl */ $tpl->default = $info["default"]; $this->service->saveTemplate($tpl); $error = null; if (empty($info["roles"])) { $error = OW::getLanguage()->text("uheader", "template_no_roles_selected_error"); } else { $this->service->saveRoleIdsForTemplateId($tplId, $info["roles"]); } return array("cover" => $this->getTplInfo($tpl), "warning" => $error); }