Ejemplo n.º 1
0
 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");
 }