예제 #1
0
 public function parameterListAction()
 {
     $this->init();
     //Load the parameters
     $paramsRaw = $this->config('admin.parameters');
     //Get theme information
     $themeDir = dir("themes");
     while (false != ($entry = $themeDir->read())) {
         if (in_array($entry, array(".", ".."))) {
             continue;
         }
         $paramsRaw['core-theme']['options'][] = $entry;
     }
     $params = array();
     foreach ($paramsRaw as $id => $param) {
         $group = $param['group'];
         $subGroup = isset($param['subGroup']) ? $param['subGroup'] : 'General';
         if (!isset($params[$group])) {
             $params[$group] = array();
         }
         if (!isset($params[$group][$subGroup])) {
             $params[$group][$subGroup] = array();
         }
         $params[$group][$subGroup][$id] = $param;
     }
     //Sort groups
     ksort($params, SORT_STRING);
     foreach ($params as &$group) {
         ksort($group, SORT_STRING);
     }
     if (count($_POST)) {
         foreach ($_POST['params'] as $group => $postParams) {
             foreach ($postParams as $identifier => $value) {
                 $param = new \ATPCore\Model\Parameter();
                 $param->loadByIdentifier($identifier);
                 $param->identifier = $identifier;
                 $param->value = $value;
                 $param->save();
             }
         }
         $this->flash->addSuccessMessage("Module Parameters saved.");
         $this->redirect()->toUrl($this->getRequest()->getUri());
     }
     //Load the objects
     $modelClass = $this->modelData['class'];
     $obj = new $modelClass();
     $objectsRaw = $obj->loadMultiple(null, array(), array(), $this->modelData['defaultOrder']);
     $objects = array();
     foreach ($objectsRaw as $object) {
         $objects[$object->identifier] = $object;
     }
     //Send data to the view
     $this->view->model = $this->modelType;
     $this->view->modelData = $this->modelData;
     $this->view->params = $params;
     $this->view->objects = $objects;
     return $this->view;
 }
 protected function siteParam($name)
 {
     $param = new \ATPCore\Model\Parameter();
     $param->loadByIdentifier($name);
     //Param does not exist, set default
     if (!$param->id) {
         $param->identifier = $name;
         $param->value = $this->config("admin.parameters.{$name}.default");
         $param->save();
     }
     return $param->value;
 }
예제 #3
0
 public function __invoke($name)
 {
     try {
         $param = new \ATPCore\Model\Parameter();
         if (!$param->loadByIdentifier($name)) {
             $param->identifier = $name;
             $param->value = "{{$name} goes here}";
         }
         return $param->value;
     } catch (\Exception $e) {
         return "";
     }
 }
예제 #4
0
 protected function _loadObject($id)
 {
     try {
         $param = new \ATPCore\Model\Parameter();
         if (!$param->loadByIdentifier($id)) {
             $param->identifier = $id;
             $param->value = "{{$id} goes here}";
             $param->save();
         }
         return $param;
     } catch (\Exception $e) {
         $obj = new \stdClass();
         $obj->value = null;
         return $obj;
     }
 }
예제 #5
0
 public function install($options = array())
 {
     $config = $this->getServiceManager()->get('Config');
     //Setup database parameters
     $configFile = new \ATP\Config\File("config/autoload/global.php.blank");
     $configFile->apply($options);
     $configFile->save("config/autoload/global.php");
     //Setup a temp adapter for the ActiveRecord classes to use while installing
     $dbConfig = $config['db'];
     unset($dbConfig['database']);
     $dbConfig['host'] = $options['db_host'];
     $dbConfig['username'] = $options['db_user'];
     $dbConfig['password'] = $options['db_pass'];
     $adapter = new \Zend\Db\Adapter\Adapter($dbConfig);
     \ATP\ActiveRecord::setAdapter($adapter);
     //Create the database schema
     $adapter->query("CREATE DATABASE {$options['db_schema']}", \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
     //Add database to adapter
     $dbConfig['database'] = $options['db_schema'];
     $adapter = new \Zend\Db\Adapter\Adapter($dbConfig);
     \ATP\ActiveRecord::setAdapter($adapter);
     //Install database tables
     $this->installDatabaseEntries();
     //Reinitialize modules so its config is reloaded
     \ATPCore\Model\Module::init();
     //Set default parameters
     \ATPCore\Model\Parameter::init();
     foreach ($config['admin']['parameters'] as $id => $paramData) {
         $param = new \ATPCore\Model\Parameter();
         $param->identifier = $id;
         $param->value = $paramData['default'];
         $param->save();
     }
 }
예제 #6
0
 public function __invoke($fileName)
 {
     //Only include files once
     static $existingCssFiles = array();
     if (in_array($fileName, $existingCssFiles)) {
         return;
     }
     $existingCssFiles[] = $fileName;
     //Preprocess .less files first
     $fileParts = explode(".", $fileName);
     $ext = array_pop($fileParts);
     if ($ext == "less") {
         if (getenv('APPLICATION_ENV') == 'development') {
             //Resolve asset
             $pluginManager = $this->getView()->getHelperPluginManager();
             $sm = $pluginManager->getServiceLocator();
             $assetManager = $sm->get('AssetManager\\Service\\AssetManager');
             $resolver = $assetManager->getResolver();
             $asset = $resolver->resolve($fileName);
             $config = $sm->get('Config');
             $paths = $config['asset_manager']['resolver_configs']['prioritized_paths'];
             $themeDir = null;
             try {
                 $param = new \ATPCore\Model\Parameter();
                 $param->loadByIdentifier('core-theme');
                 $themeDir = $param->value;
             } catch (\Exception $e) {
             }
             if (empty($themeDir)) {
                 $themeDir = "Default";
             }
             $paths[] = array("path" => realpath("themes/{$themeDir}/public"), "priority" => 5000);
             usort($paths, function ($a, $b) {
                 return $b['priority'] - $a['priority'];
             });
             $paths = \ATP\MapReduce::process($paths, function ($pathData) {
                 return array($pathData['path'] => '');
             }, function ($joined, $cur) {
                 return array_merge($joined, $cur);
             }, array());
             //Set original and compiled filenames
             $originalFile = $asset ? $asset->getSourceDirectory() . '/' . $asset->getSourcePath() : getcwd() . "/public" . $fileName;
             $compiledFile = substr($originalFile, 0, -4) . "css";
             //Initialize less compiler
             $lessc = new \Less_Parser();
             //Make the definitions file available to all less files
             $lessc->SetImportDirs($paths);
             //Compile the less code
             try {
                 set_time_limit(60);
                 $lessc->parseFile($originalFile);
                 file_put_contents($compiledFile, $lessc->getCss());
             } catch (\Exception $e) {
                 echo "Less compilation error while compiling <b>{$fileName}</b>: <br/>" . $e->getMessage();
                 die;
             }
         }
         //Set new filename
         $fileName = substr($fileName, 0, -4) . "css";
     }
     $func = $this->_function;
     $this->getView()->headLink()->{$func}($this->getView()->basePath() . $fileName);
     return $this->getView();
 }