Beispiel #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");
 }
Beispiel #2
0
 public function getCover(OW_Event $event)
 {
     $params = $event->getParams();
     $userId = $params["userId"];
     $forWidth = empty($params["forWidth"]) ? null : $params["forWidth"];
     $permited = UHEADER_CLASS_PrivacyBridge::getInstance()->checkPrivacy($userId);
     if (!$permited) {
         return null;
     }
     $cover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_ACTIVE);
     if ($cover === null) {
         $cover = $this->service->findDefaultTemplateForUser($userId);
     }
     if ($cover === null) {
         return null;
     }
     $out = array("userId" => $userId, "src" => $cover->getSrc(), "data" => $cover->getSettings(), "canvas" => $cover->getCanvas($forWidth), "css" => $cover->getCss(), "cssString" => $cover->getCssString());
     $event->setData($out);
     return $out;
 }
Beispiel #3
0
 public function __construct($userId)
 {
     parent::__construct();
     UHEADER_CLASS_Plugin::getInstance()->includeStatic();
     $this->userId = $userId;
     $this->service = UHEADER_BOL_Service::getInstance();
     $this->cover = $this->service->findCoverByUserId($this->userId, UHEADER_BOL_Cover::STATUS_ACTIVE);
     if ($this->cover === null) {
         $removedCover = $this->service->findCoverByUserId($this->userId, UHEADER_BOL_Cover::STATUS_REMOVED);
         if ($removedCover === null) {
             $template = $this->service->findDefaultTemplateForUser($userId);
             if ($template !== null) {
                 $this->cover = $template->createCover($this->userId);
                 $this->templateId = $template->id;
                 $this->defaultTemplateMode = true;
             }
         }
     } else {
         $this->hasCover = true;
     }
     $this->defaultTemplatesCount = $this->service->findTemplatesCountForUser($this->userId, true);
 }