Example #1
0
 /**
  * Constructs a new queue table
  * @param string $formAction URL where the form of the table will point to
  * @param string $detailAction URL where the action of a queue job will point to
  * @return null
  */
 public function __construct($formAction, $detailAction, $translator)
 {
     $model = ModelManager::getInstance()->getModel(QueueModel::NAME);
     parent::__construct($model, $formAction);
     $this->addDecorator(new ZebraDecorator(new DetailDecorator($detailAction)));
     $this->addDecorator(new StatusDecorator($translator));
 }
 /**
  * Gets the country model
  * @return zibo\library\orm\model\CountryModel
  */
 private function getCountryModel()
 {
     if (!$this->model) {
         $this->model = ModelManager::getInstance()->getModel(Module::MODEL_COUNTRY);
     }
     return $this->model;
 }
 /**
  * Initializes this field, fetches the continents and sets them to this field
  * @return null
  */
 protected function init()
 {
     parent::init();
     $continentModel = ModelManager::getInstance()->getModel(ContinentModel::NAME);
     $continents = $continentModel->getDataList();
     $this->setOptions($continents);
 }
 /**
  * Gets the forum category from the form
  * @return joppa\forum\model\data\ForumCategoryData
  */
 public function getCategory()
 {
     $category = ModelManager::getInstance()->getModel(ForumCategoryModel::NAME)->createData(false);
     $category->id = $this->getValue(self::FIELD_ID);
     $category->name = $this->getValue(self::FIELD_NAME);
     return $category;
 }
 /**
  * Constructs a new cached model query
  * @param string|zibo\library\orm\model\Model $model Name or instance of the model for this query
  * @param string $operator Logical operator for the conditions
  * @return null
  */
 public function __construct($model, $operator = null)
 {
     parent::__construct($model, $operator);
     $this->variables = array();
     $this->willCacheResult = true;
     $this->cache = ModelManager::getInstance()->getModelCache();
 }
 /**
  * Construct this form
  * @param string $action url where this form will point to
  * @param joppa\model\Node $node Node to retrieve the node list
  * @param string $nodeId node id to set to the form
  * @param string $url url to set to the form
  * @return null
  */
 public function __construct($action, $node, $nodeId = null, $url = null)
 {
     parent::__construct($action, self::NAME, self::TRANSLATION_SAVE);
     if ($url) {
         $redirectType = self::REDIRECT_TYPE_URL;
     } else {
         $redirectType = self::REDIRECT_TYPE_NODE;
     }
     $modelManager = ModelManager::getInstance();
     $factory = FieldFactory::getInstance();
     $siteModel = $modelManager->getModel(SiteModel::NAME);
     $nodeModel = $modelManager->getModel(NodeModel::NAME);
     $nodeTree = $siteModel->getNodeTreeForNode($node->id, null, null, null, true, false);
     $nodeList = $nodeModel->createListFromNodeTree($nodeTree);
     if (isset($nodeList[$node->id])) {
         unset($nodeList[$node->id]);
     }
     $redirectTypeField = $factory->createField(FieldFactory::TYPE_OPTION, self::FIELD_REDIRECT_TYPE, $redirectType);
     $redirectTypeField->setOptions($this->getRedirectTypeOptions());
     $nodeField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_NODE, $nodeId);
     $nodeField->setOptions($nodeList);
     $urlField = $factory->createField(FieldFactory::TYPE_STRING, self::FIELD_URL, $url);
     $this->addField($redirectTypeField);
     $this->addField($nodeField);
     $this->addField($urlField);
 }
Example #7
0
 /**
  * Add a empty value to the option
  * @param string $value label of the option
  * @param string $key key of the option
  * @return null
  */
 public function addEmpty($value = '---', $key = 0)
 {
     $model = ModelManager::getInstance()->getModel(CountryModel::NAME);
     $country = $model->createData(false);
     $country->id = $key;
     $country->name = $value;
     $this->options = Structure::merge(array('---' => array($key => $country)), $this->options);
 }
Example #8
0
 /**
  * Sets the name of the model for this table
  * @param string $modelName
  * @return null
  * @throws zibo\ZiboException when the name of the model is empty or invalid
  * @throws zibo\library\orm\exception\OrmException when the model does not exist
  */
 private function setModelName($modelName)
 {
     if (String::isEmpty($modelName)) {
         throw new OrmException('Provided model name is empty');
     }
     ModelManager::getInstance()->getModel($modelName);
     $this->modelName = $modelName;
 }
 /**
  * Gets the post of this form
  * @return joppa\forum\model\data\ForumPostData
  */
 public function getPost()
 {
     $post = ModelManager::getInstance()->getModel(ForumPostModel::NAME)->createData(false);
     $post->id = $this->getValue(self::FIELD_ID);
     $post->subject = $this->getValue(self::FIELD_SUBJECT);
     $post->message = $this->getValue(self::FIELD_MESSAGE);
     return $post;
 }
 /**
  * Construct this manager
  * @return null
  */
 private function __construct()
 {
     $this->nodeTypes = array();
     $modelManager = ModelManager::getInstance();
     $this->registerNodeType(PageNodeType::NAME, new PageNodeType());
     $this->registerNodeType(FolderNodeType::NAME, new FolderNodeType());
     $this->registerNodeType(SiteModel::NODE_TYPE, $modelManager->getModel('Site'));
 }
Example #11
0
 /**
  * Installs or updates the continents and countries from the data directory into the model.
  * @return null
  */
 public function install()
 {
     $modelManager = ModelManager::getInstance();
     $continentModel = $modelManager->getModel(ContinentModel::NAME);
     $countryModel = $modelManager->getModel(CountryModel::NAME);
     $locales = I18n::getInstance()->getLocaleCodeList();
     $continents = $continentModel->installContinents($locales);
     $countryModel->installCountries($locales, $continents);
 }
 /**
  * Gets the text submitted by this form
  * @return joppa\text\model\TextData
  */
 public function getText()
 {
     $textModel = ModelManager::getInstance()->getModel(TextModel::NAME);
     $text = $textModel->createData(false);
     $text->id = $this->getValue(self::FIELD_ID);
     $text->text = $this->getValue(self::FIELD_TEXT);
     $text->version = $this->getValue(self::FIELD_VERSION);
     return $text;
 }
 /**
  * Get the site which is currently selected in this form
  * @return joppa\model\Site if nothing is selected, null will be returned
  */
 public function getSite()
 {
     $id = $this->getValue(self::FIELD_SITE);
     if (empty($id)) {
         return null;
     }
     $siteModel = ModelManager::getInstance()->getModel('Site');
     return $siteModel->getSite($id);
 }
 /**
  * Get the options for the node field
  * @return array Array with nodes which contain a search result widget. The array has the node id as key and the node name as value.
  */
 private function getNodeOptions()
 {
     $nodeModel = ModelManager::getInstance()->getModel('Node');
     $nodes = $nodeModel->getNodesForWidget('joppa', 'searchResult');
     $options = array('0' => '---');
     foreach ($nodes as $node) {
         $options[$node->id] = $node->name;
     }
     return $options;
 }
 public function orderFieldsAction($modelName, $recursiveDepth)
 {
     $fields = array();
     if ($modelName !== '0') {
         try {
             $fields = ContentOverviewPropertiesForm::getModelFieldOptions(ModelManager::getInstance(), $modelName, true, false, $recursiveDepth);
         } catch (Exception $exception) {
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString());
         }
     }
     $view = new JsonView(array('fields' => $fields));
     $this->response->setView($view);
 }
Example #16
0
 /**
  * Decorates the data in the cell
  * @param zibo\library\html\table\Cell $cell Cell to decorate
  * @param zibo\library\html\table\Row $row Row containing the cell
  * @param int $rowNumber Number of the current row
  * @param array $remainingValues Array containing the values of the remaining rows of the table
  * @return null
  */
 public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues)
 {
     $log = $cell->getValue();
     $value = $log->dataModel . ' #' . $log->dataId;
     if ($this->action) {
         $anchor = new Anchor($value, $this->action . $log->id);
         $value = $anchor->getHtml();
     }
     $data = null;
     try {
         $model = $this->modelManager->getModel($log->dataModel);
         $data = $this->logModel->getDataByVersion($log->dataModel, $log->dataId, $log->dataVersion);
         $data = $model->getMeta()->formatData($data);
     } catch (Exception $exception) {
         Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
     }
     if (!$data) {
         $data = '---';
     }
     $value .= '<div class="info">' . $data . '</div>';
     $cell->setValue($value);
 }
 /**
  * Construct this form
  * @param string $action url where this form will point to
  * @param int $rootNodeId id of the root node for the filter field
  * @param string $label Label for the breadcrumbs
  * @param mixed $filter value for the filter field
  * @param string $styleId value for the style id field
  * @return null
  */
 public function __construct($action, $rootNodeId, $label, $filter, $styleId = null)
 {
     parent::__construct($action, self::NAME);
     $factory = FieldFactory::getInstance();
     $siteModel = ModelManager::getInstance()->getModel(SiteModel::NAME);
     $nodeModel = ModelManager::getInstance()->getModel(NodeModel::NAME);
     $nodeTree = $siteModel->getNodeTreeForNode($rootNodeId, null, null, null, true, false);
     $nodeList = $nodeModel->createListFromNodeTree($nodeTree);
     $labelField = $factory->createField(FieldFactory::TYPE_STRING, self::FIELD_LABEL, $label);
     $filterField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_FILTER, $filter);
     $filterField->setOptions($nodeList);
     $filterField->setIsMultiple(true);
     $styleIdField = $factory->createField(FieldFactory::TYPE_STRING, self::FIELD_STYLE_ID, $styleId);
     $this->addField($labelField);
     $this->addField($filterField);
     $this->addField($styleIdField);
 }
 protected function setUp()
 {
     parent::setUp();
     $path = new File(getcwd(), Zibo::DIRECTORY_APPLICATION);
     $modelIO = new XmlModelIO();
     $models = $modelIO->readModelsFromPath($path);
     $register = new ModelRegister();
     $register->registerModels($models);
     $models = $register->getModels();
     $definer = new ModelDefiner();
     $definer->defineModels($models);
     $connection = DatabaseManager::getInstance()->getConnection();
     $connection->executeFile(new File(self::SQL_SETUP));
     if ($this->modelName != null) {
         $this->model = ModelManager::getInstance()->getModel($this->modelName);
     }
     Zibo::getInstance()->registerEventListener(Zibo::EVENT_LOG, array($this, 'logSql'));
 }
Example #19
0
 /**
  * Prepares TinyMCE with all the nodes from the site tree
  * @param zibo\tinymce\controller\TinyMCEController $controller The TinyMCE controller
  * @return null
  */
 public function prepareTinyMCE(TinyMCEController $controller)
 {
     $modelManager = ModelManager::getInstance();
     $nodeModel = $modelManager->getModel(NodeModel::NAME);
     $siteModel = $modelManager->getModel(SiteModel::NAME);
     $sites = $siteModel->getSites();
     foreach ($sites as $site) {
         $nodeTree = $siteModel->getNodeTreeForSite($site);
         $nodeList = $nodeModel->createListFromNodeTree($nodeTree);
         $prefix = '';
         if (count($sites) > 1) {
             $prefix = '/' . $site->node->name;
         }
         foreach ($nodeList as $nodeId => $nodeName) {
             $controller->addLink('%node.' . $nodeId . '.url%', $prefix . $nodeName);
         }
     }
 }
Example #20
0
 /**
  * Gets the base path for a data object of this mapper
  * @return string
  */
 private function getBasePath()
 {
     if ($this->basePath) {
         return $this->basePath;
     }
     $modelName = $this->model->getName();
     $nodeModel = ModelManager::getInstance()->getModel(NodeModel::NAME);
     $nodes = $nodeModel->getNodesForWidget('joppa', 'contentDetail');
     foreach ($nodes as $node) {
         if ($modelName != $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_MODEL_NAME)) {
             continue;
         }
         $this->idField = $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_PARAMETER_ID);
         $this->basePath = $this->getBaseUrl() . '/' . $node->getRoute();
         break;
     }
     return $this->basePath;
 }
Example #21
0
 /**
  * Render this view
  * @param boolean $return Set to false to output the rendered view
  * @return null|string The rendered view if $return is set to true, null otherwise
  */
 public function render($return = true)
 {
     $this->baseUrl = Zibo::getInstance()->getRequest()->getBaseUrl() . '/';
     $this->nodeTypeFacade = NodeTypeFacade::getInstance();
     $this->locale = LocalizeController::getLocale();
     $this->translator = I18n::getInstance()->getTranslator();
     $defaultNodeId = null;
     if ($this->site->defaultNode) {
         $defaultNodeId = $this->site->defaultNode->id;
     }
     $siteModel = ModelManager::getInstance()->getModel(SiteModel::NAME);
     $this->site->node->children = $siteModel->getNodeTreeForSite($this->site, null, null, $this->locale, true);
     $nodeTree = array($this->site->node->id => $this->site->node);
     $output = $this->getNodeTreeHtml($nodeTree, $defaultNodeId, $this->site->localizationMethod == SiteModel::LOCALIZATION_METHOD_COPY, $this->node);
     if ($return) {
         return $output;
     }
     echo $output;
 }
Example #22
0
 public function initializeContentMappers()
 {
     $request = Zibo::getInstance()->getRequest();
     if (!$request instanceof JoppaRequest) {
         return;
     }
     $contentFacade = ContentFacade::getInstance();
     $contentMappers = $contentFacade->getTypes();
     $nodeModel = ModelManager::getInstance()->getModel(NodeModel::NAME);
     $nodes = $nodeModel->getNodesForWidget('joppa', 'contentDetail');
     foreach ($nodes as $node) {
         $modelName = $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_MODEL_NAME);
         if (in_array($modelName, $contentMappers)) {
             continue;
         }
         $recursiveDepth = $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_RECURSIVE_DEPTH);
         $mapper = new ContentMapper($modelName, $recursiveDepth);
         $contentFacade->setMapper($modelName, $mapper);
         $contentMappers[] = $modelName;
     }
 }
 /**
  * Constructs a new forum search form
  * @param string $action URL where this form will point to
  * @param joppa\forum\model\data\ForumSearchData $data The data to preset the form
  * @return null
  */
 public function __construct($action, ForumSearchData $data)
 {
     parent::__construct($action, self::NAME);
     $modelManager = ModelManager::getInstance();
     $fieldFactory = FieldFactory::getInstance();
     $categoryModel = $modelManager->getModel(ForumCategoryModel::NAME);
     $categories = $categoryModel->getCategories();
     $queryField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_QUERY, $data->query);
     $boardField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_CATEGORY, $data->category);
     $boardField->setIsMultiple(true);
     foreach ($categories as $category) {
         $boards = array();
         foreach ($category->boards as $board) {
             $boards[$board->id] = $board->name;
         }
         $boardField->setOptions($boards, $category->name);
     }
     $searchButton = $fieldFactory->createSubmitField(self::BUTTON_SEARCH, self::TRANSLATION_SEARCH);
     $this->addField($queryField);
     $this->addField($boardField);
     $this->addField($searchField);
 }
Example #24
0
 /**
  * Prepare the controller by loading the needed models into the $models variable based on the $useModels variable in the controller
  *
  * The $useModels variable should be defined public in your controller. This can be a string with 1 model name or an array with multiple model names. Those models
  * will be loaded into the $models variable of your controller before the controller is dispatched.
  *
  * @param zibo\core\Controller $controller Instance of the controller to be dispatched
  * @param string $actionName The name of the action to execute
  * @param array $parameters The parameters for the action
  * @return null
  */
 public function prepareController(Controller $controller, $actionName, array $parameters)
 {
     if (!isset($controller->useModels)) {
         return;
     }
     if (!is_array($controller->useModels)) {
         $models = array($controller->useModels);
     } else {
         $models = $controller->useModels;
     }
     $manager = ModelManager::getInstance();
     $controller->models = array();
     foreach ($models as $modelName) {
         $controller->models[$modelName] = $manager->getModel($modelName);
     }
 }
 /**
  * Gets a model from the model manager
  * @param string $modelName
  * @return zibo\library\orm\model\Model
  */
 protected function getModel($modelName)
 {
     return ModelManager::getInstance()->getModel($modelName);
 }
 /**
  * Gets the information about the unlinked models of the provided table
  * @param string $tableName The name of the table
  * @return string The information about the unlinked models of the provided table
  */
 private function getUnlinkedModelsInfo($tableName)
 {
     $info = '';
     $model = ModelManager::getInstance()->getModel($tableName);
     $unlinkedModels = $model->getMeta()->getUnlinkedModels();
     $numUnlinkedModels = count($unlinkedModels);
     if ($this->action) {
         foreach ($unlinkedModels as $index => $modelName) {
             $anchor = new Anchor($modelName, $this->action . $modelName);
             $unlinkedModels[$index] = $anchor->getHtml();
         }
     }
     if ($numUnlinkedModels == 1) {
         $model = array_pop($unlinkedModels);
         $info .= $this->translator->translate('orm.label.unlinked.model', array('model' => $model)) . '<br />';
     } elseif ($numUnlinkedModels) {
         $last = array_pop($unlinkedModels);
         $first = implode(', ', $unlinkedModels);
         $info .= $this->translator->translate('orm.label.unlinked.models', array('first' => $first, 'last' => $last)) . '<br />';
     }
     return $info;
 }
 /**
  * Gets the fields of a model as options for a form field
  * @param zibo\library\orm\ModelManager $modelManager Manager of the models
  * @param string $model Name of the selected model
  * @param boolean $includeRelationFields
  * @param boolean $includeHasFields
  * @return array Array with tne name of the field as key and as value
  */
 public static function getModelFieldOptions(ModelManager $modelManager, $model, $includeRelationFields = false, $includeHasFields = false, $recursiveDepth = 1)
 {
     if ($includeRelationFields) {
         $options = array('' => '---');
     } else {
         $options = array();
     }
     if (!$model) {
         return $options;
     }
     $model = $modelManager->getModel($model);
     $meta = $model->getMeta();
     $fields = $meta->getFields();
     foreach ($fields as $fieldName => $field) {
         if (!$includeRelationFields || $field instanceof PropertyField) {
             $options[$fieldName] = $fieldName;
             continue;
         }
         if (!($includeHasFields || $field instanceof BelongsToField)) {
             continue;
         }
         if ($recursiveDepth != '1') {
             $options[$fieldName] = $fieldName;
             continue;
         }
         $relationModel = $meta->getRelationModel($fieldName);
         $relationMeta = $relationModel->getMeta();
         $relationFields = $relationMeta->getFields();
         foreach ($relationFields as $relationFieldName => $relationField) {
             if (!$includeHasFields && $relationField instanceof HasField) {
                 continue;
             }
             $name = $fieldName . '.' . $relationFieldName;
             $options[$name] = $name;
         }
     }
     return $options;
 }
Example #28
0
 /**
  * Get a preview of the properties of this widget
  * @return string
  */
 public function getPropertiesPreview()
 {
     $translator = $this->getTranslator();
     $parent = $this->getParent();
     $depth = $this->getDepth();
     $showTitle = $this->getShowTitle();
     if ($parent) {
         $nodeModel = ModelManager::getInstance()->getModel(NodeModel::NAME);
         $parentNode = $nodeModel->getNode($parent, 0);
         $parent = $parentNode->name;
     } else {
         $parent = '---';
     }
     $preview = '';
     $preview .= $translator->translate(self::TRANSLATION_PARENT) . ': ' . $parent . '<br />';
     $preview .= $translator->translate(self::TRANSLATION_DEPTH) . ': ' . $depth . '<br />';
     $preview .= $translator->translate(self::TRANSLATION_SHOW_TITLE) . ': ' . $translator->translate($showTitle ? self::TRANSLATION_YES : self::TRANSLATION_NO);
     return $preview;
 }
Example #29
0
 /**
  * Gets the cache
  * @return zibo\library\orm\cache\ModelCache
  */
 private function getCache()
 {
     $modelManager = ModelManager::getInstance();
     return $modelManager->getModelCache();
 }
Example #30
0
 /**
  * Sets the model of this query
  * @param string|zibo\library\orm\model\Model $model Name or instance of the model for this query
  * @return null
  */
 private function setModel($model)
 {
     if ($model instanceof Model) {
         $this->model = $model;
     } else {
         $this->model = ModelManager::getInstance()->getModel($model);
     }
 }