/**
  * Load the factories.
  *
  * @param  string $basePath
  * @return array
  */
 public function load($basePath)
 {
     $this->assertThatFactoriesDirectoryExists($basePath);
     $designer = new Designer();
     $faker = new FakerAdapter();
     $factory = function ($name, $shortName, $attributes = []) use($designer, $faker) {
         return $designer->define($name, $shortName, $attributes);
     };
     foreach ((new FactoriesFinder($basePath))->find() as $file) {
         include $file;
     }
     return $designer->definitions();
 }
 public function getThemeTemplates($themeName)
 {
     $path = FilesHelper::normalizePath(getThemeDir($themeName . _PREVIEW_SUFFIX_)) . '/templates/templates.php';
     if (file_exists($path)) {
         // TODO: Maybe we have to store all html and parse them after each update or export operation for backward
         require_once $path;
     } else {
         $templates = getTemplates();
         // backward with old themes which do not have templates.php file but plugin is already updated
     }
     $context = Context::getContext();
     $link = $context->link;
     $controllers = getTemplateControllers();
     $previewParam = 'theme_name=' . $themeName;
     $result = array();
     foreach ($templates as $type => $template) {
         $controller = $controllers[$type];
         $method = 'get' . $controller . 'Link';
         if (method_exists($link, $method)) {
             $lower = strtolower($controller);
             $item = Designer::getFirstItem($lower);
             if ($item > 0) {
                 $baseUrl = $link->{$method}($item);
                 $pos = strpos($baseUrl, '?');
                 if ($pos !== FALSE) {
                     // HACK: preview parameter must be first in URL in Debug mode
                     $mainPart = substr($baseUrl, 0, $pos);
                     $params = substr($baseUrl, $pos + 1);
                     $templateUrl = $mainPart . '?' . $previewParam . '&' . $params;
                 } else {
                     $templateUrl = $baseUrl . '?' . $previewParam;
                 }
             } else {
                 $templateUrl = $link->getPageLink('index') . '?' . $previewParam . '&missingContent=' . $lower;
             }
         } else {
             $templateUrl = $link->getPageLink($controller);
             if (strpos($templateUrl, $previewParam) === FALSE) {
                 // can be set in some case from Dispatcher.php
                 $templateUrl .= (strpos($templateUrl, '?') !== FALSE ? '&' : '?') . $previewParam;
             }
         }
         if (is_array($template)) {
             // updated theme with templates.php file
             foreach ($template as $t) {
                 $result[$t['name']] = $templateUrl . '&template=' . $type . '_' . $t['id'];
                 // format as {templateName_id.tpl}
             }
         } else {
             // backward with old themes which do not have templates.php file but plugin is already updated
             $result[$type] = $templateUrl;
         }
     }
     return $result;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDesignerUserName()
 {
     return $this->hasOne(Designer::className(), ['designer_user_name' => 'designer_user_name']);
 }
Beispiel #4
0
 if (isset($params['action']) && strlen($params['action']) > 0) {
     $action = isset($params['action']) ? $params['action'] : null;
     switch (strtolower($params['action'])) {
         case "addemployee":
             $name = isset($params['name']) ? $params['name'] : null;
             $surname = isset($params['surname']) ? $params['surname'] : null;
             $profession = isset($params['profession']) ? $params['profession'] : null;
             $companyId = isset($params['companyId']) ? $params['companyId'] : null;
             if ($name != null && $surname != null && $profession != null && $companyId != null) {
                 $type = isset($params['type']) ? $params['type'] : null;
                 $age = isset($params['age']) ? $params['age'] : null;
                 $company = new Company($companyId);
                 if (strtolower($profession) == "programmer") {
                     $employee = new Programmer();
                 } else {
                     $employee = new Designer();
                 }
                 $employee->setName($name);
                 $employee->setSurname($surname);
                 $employee->setAge($age);
                 $employee->setType($type);
                 $result = $company->addEmployee($employee);
                 $outMsg = "addemployee processed. New EmployeeID: " . $result;
                 $outStatusCode = 200;
             } else {
                 $outMsg = "name, surname, profession and companyId are mandatory parameters";
                 $outStatusCode = 500;
             }
             break;
         case "addcompany":
             $name = isset($params['name']) ? $params['name'] : null;
function uploadFile($themeName, $filename, $tmp_path)
{
    $themeDir = FilesHelper::normalizePath(getThemeDir($themeName));
    $previewThemeDir = FilesHelper::normalizePath(getThemeDir($themeName . _PREVIEW_SUFFIX_));
    $base_dir = $previewThemeDir . '/img';
    $base_path = $base_dir . '/' . $filename;
    FilesHelper::deleteFile($base_path);
    FilesHelper::createDir($base_dir);
    FilesHelper::renameFile($tmp_path, $base_path);
    $changed_files = getPreviewChangedFiles($themeDir);
    $changed_files[] = $base_path;
    setPreviewChangedFiles($themeDir, $previewThemeDir, $changed_files);
    return array('status' => 'done', 'url' => Designer::getBaseUrlWithLastSlash() . 'themes/' . $themeName . '_preview/img/' . $filename);
}
 public function rename($newThemeName)
 {
     $result = $this->canRename($newThemeName);
     if ($result['message']) {
         return $result;
     }
     if (!is_dir($this->_themeDir)) {
         return array('errors' => 'Theme `' . $this->_themeName . '` doesn\'t exist');
     }
     ProviderLog::start('rename');
     $isActive = Designer::isActiveTheme($this->_themeName);
     $this->prepareCopyRename($newThemeName);
     Designer::deleteTheme($this->_themeName);
     Designer::deleteTheme($this->_previewThemeName);
     Designer::addTheme($newThemeName);
     if ($isActive) {
         // renamed theme was activated before
         Designer::setActiveThemeForShop($newThemeName);
     }
     ProviderLog::end('rename');
     return array('result' => 'done', 'log' => ProviderLog::getLog());
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItemDesigner()
 {
     return $this->hasOne(Designer::className(), ['designer_user_name' => 'item_designer_id']);
 }
 private function getThemesInfo()
 {
     return Designer::buildThemesData(self::$currentIndex, basename(_PS_ADMIN_DIR_));
 }
 public static function buildThemesData($currentIndex = '', $adminDir = '')
 {
     $token = Designer::getToken();
     $baseUrl = Designer::getBaseUrlWithLastSlash();
     $themesUrl = $baseUrl . 'themes';
     $adminUrl = $baseUrl . $adminDir . '/' . ($currentIndex ? $currentIndex : 'index.php?controller=AdminAjax') . '&token=' . $token;
     $shop = Designer::getShop();
     $themes = array();
     foreach (Theme::getAvailable(false) as $themeName) {
         if (strpos($themeName, _PREVIEW_SUFFIX_) !== FALSE || !file_exists(getProjectPath($themeName))) {
             continue;
         }
         $id = Designer::getThemeId($themeName);
         $themeUrl = $themesUrl . '/' . $themeName;
         $url = $adminUrl . '&theme_name=' . $themeName;
         $themes['themes'][$themeName] = array('themeName' => $themeName, 'thumbnailUrl' => $themeUrl . '/preview.jpg', 'openUrl' => $url . '&ajax=1&ver=' . theme_get_manifest_version($themeName) . getDesktopParams(), 'settingsUrl' => $url . '&edit=1', 'isActive' => $id && $shop->id_theme == $id);
     }
     return $themes;
 }