/** * Return the views output * * This function will auto assign the model data to the view if the auto_assign * property is set to TRUE. * * @return string The output of the view */ public function display() { if(empty($this->output)) { $model = $this->getModel(); //Auto-assign the state to the view $this->assign('state', $model->getState()); //Auto-assign the data from the model if($this->_auto_assign) { //Get the view name $name = $this->getName(); //Assign the data of the model to the view if(KInflector::isPlural($name)) { $this->assign($name, $model->getList()) ->assign('total', $model->getTotal()); } else $this->assign($name, $model->getItem()); } } return parent::display(); }
public function render() { $name = $this->getName(); $img = KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.img', '/32/' . $name . '.png'); if ($img) { KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.css', '.toolbar .icon-32-' . $name . ' { background-image: url(' . $img . '); }'); } $text = JText::_($this->_options['text']); $view = KRequest::get('get.view', 'cmd'); $link = ' href="' . JRoute::_($this->getLink()) . '"'; $html = array(); // Sanitize the url since we can't trust the server var $url = KFactory::get('lib.koowa.filter.url')->sanitize($this->getLink()); // Create the URI object $uri = KFactory::tmp('lib.koowa.http.uri', array('uri' => $url)); $query = $uri->getQuery(1); $html[] = '<td class="button" id="' . $this->getId() . '">'; $active = $view == KInflector::variablize(KInflector::pluralize($query['view'])) || $view == KInflector::variablize(KInflector::singularize($query['view'])); $hide = !KInflector::isPlural($view); if ($active || $hide || !$this->modal) { $html[] = '<a class="toolbar inactive">'; } else { $html[] = '<a' . $link . ' onclick="' . $this->getOnClick() . '" class="toolbar">'; } $html[] = '<span class="' . $this->getClass() . '" title="' . $text . '">'; $html[] = '</span>'; $html[] = $text; if (!$active && !$hide || $this->modal) { $html[] = '</a>'; } else { $html[] = '</a>'; } $html[] = '</td>'; return implode(PHP_EOL, $html); }
/** * Sets the document title */ public function setDocumentTitle() { if (!KInflector::isPlural($this->getName())) { $item = $this->getModel()->getItem(); JFactory::getDocument()->setTitle($item->title); } }
/** * Generic function for setting the permissions * * @return void */ public function setPermissions($context) { //Temp fix if (KInflector::isPlural(KRequest::get('get.view', 'cmd')) || KRequest::type() == 'AJAX') { return; } $model = KFactory::get($this->getModel()); $table = KFactory::tmp(KFactory::get(KFactory::get('admin::com.ninja.helper.access')->models->assets)->getTable()); $query = $table->getDatabase()->getQuery(); $item = $model->getItem(); $identifier = $this->getIdentifier(); $id = $identifier->type . '_' . $identifier->package . '.' . $identifier->name . '.' . $item->id . '.'; $permissions = (array) KRequest::get('post.permissions', 'int'); $editable = KRequest::get('post.editpermissions', 'boolean', false); if (!$permissions && $editable) { $query->where('tbl.name', 'LIKE', $id . '%'); $table->select($query)->delete(); } $safe = array(); $query = $table->getDatabase()->getQuery()->where('name', 'like', $id . '%'); foreach ((array) KRequest::get('post.params.permissions', 'raw') as $group => $other) { $safe[] = $id . $group; } if ($safe) { $query->where('name', 'not in', $safe); } $table->select($query, KDatabase::FETCH_ROWSET)->delete(); foreach ($permissions as $usergroup => $rules) { foreach ($rules as $name => $permission) { KFactory::tmp(KFactory::get('admin::com.ninja.helper.access')->models->assets)->name($id . $usergroup . '.' . $name)->getItem()->setData(array('name' => $id . $usergroup . '.' . $name, 'level' => $permission))->save(); } } }
/** * Get action. * * @param KCommandContext $context Context parameter * * @return string */ protected function _actionGet(KCommandContext $context) { $action = null; if ($this->_request->get) { $action = strtolower('get' . $this->_request->get); } else { $action = KInflector::isPlural($this->view) ? 'browse' : 'read'; } $result = null; if (in_array($action, $this->getActions())) { $result = $this->execute($action, $context); if (is_string($result) || $result === false) { $context->response->setContent($result . ' '); } } $view = $this->getView(); if (!$context->response->getContent()) { if ($context->params) { foreach ($context->params as $key => $value) { $view->set($key, $value); } } $content = $view->display(); //Set the data in the response $context->response->setContent($content); } $context->response->setContentType($view->mimetype); return $context->response->getContent(); }
public function __construct(KConfig $config) { //show only enabled posts in the posts view if (KInflector::isPlural(KRequest::get('get.view', 'string'))) { $config->request->enabled = 1; } parent::__construct($config); }
public function display() { $name = $this->getName(); //Append enable and disbale button for all the list views if ($name != 'dashboard' && KInflector::isPlural($name) && KRequest::type() != 'AJAX') { KFactory::get('admin::com.error.toolbar.' . $name)->append('divider')->append('enable')->append('disable'); } return parent::display(); }
/** * Edit Command for an entity * * @param LibBaseTemplateObject $command The action object * * @return void */ protected function _commandEdit($command) { $entity = $this->getController()->getItem(); $view = $this->getController()->getView()->getName(); $layout = pick($command->layout, 'edit'); $command->append(array('label' => JText::_('LIB-AN-ACTION-EDIT')))->href($entity->getURL() . '&layout=' . $layout); if (KInflector::isPlural($view)) { $command->setAttribute('data-action', 'edit'); } }
/** * Sets the default view to the comment views. * * @param stirng $view * * @return ComBaseControllerComment */ public function setView($view) { parent::setView($view); if (!$this->_view instanceof LibBaseViewAbstract) { $view = KInflector::isPlural($view) ? 'comments' : 'comment'; $defaults[] = 'ComBaseView' . ucfirst($view) . ucfirst($this->_view->name); register_default(array('identifier' => $this->_view, 'default' => $defaults)); } return $this; }
public function display() { $name = $this->getName(); $toolbar = KFactory::get($this->getToolbar()); $toolbar->setTitle('Jedi: ' . KInflector::humanize($this->getName())); //Apend enable and disbale button for all the list views if (KInflector::isPlural($name)) { $toolbar->append('divider')->append('enable')->append('disable'); } return parent::display(); }
public function display() { $model = $this->getModel(); if (KInflector::isPlural($this->getName())) { $data = array('settings' => $model->getList()->toArray()); } else { $data = $model->getItem()->toArray(); } $this->output = $data; return parent::display(); }
/** * Return the views output * * If the view 'output' variable is empty the output will be generated based on * the model data, if it set it will be returned instead. * * @return string The output of the view */ public function display() { if (empty($this->output)) { $model = $this->getModel(); if (KInflector::isPlural($this->getName())) { $data = $model->getList(); } else { $data = $model->getItem(); } $this->output = json_encode($data->toArray()); } return parent::display(); }
/** * Draw the toolbar * * @param KCommandContext $context The command context * * @return string */ protected function _actionRender(KCommandContext $context) { if ($context->result !== false) { $view = $this->getController()->getView(); //Set the document mimetype JFactory::getDocument()->setMimeEncoding($view->mimetype); //Disabled the application menubar if (!KInflector::isPlural($view->getName()) && !KRequest::has('get.hidemainmenu')) { KRequest::set('get.hidemainmenu', 1); } } return parent::_actionRender($context); }
/** * Constructor * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); $app = $this->_identifier->application; $package = $this->_identifier->package; $name = $this->_identifier->name; if (KInflector::isPlural($name)) { //Create the toolbar $this->append('new')->append('delete'); } else { // Create the toolbar $this->append('save')->append('apply')->append('cancel'); } }
public function display() { $model = $this->getModel(); if(KInflector::isPlural($this->getName())) { $data = $this->_getList($model); } else { $data = $this->_getItem($model); } $this->output = $data; return parent::display(); }
/** * Load a template helper * * This function merges the elements of the attached view model state with the parameters passed to the helper * so that the values of one are appended to the end of the previous one. * * If the view state have the same string keys, then the parameter value for that key will overwrite the state. * * @param string Name of the helper, dot separated including the helper function to call * @param mixed Parameters to be passed to the helper * @return string Helper output */ public function renderHelper($identifier, $params = array()) { $view = $this->getView(); if (KInflector::isPlural($view->getName())) { if ($state = $view->getModel()->getState()) { $params = array_merge($state->getData(), $params); } } else { if ($item = $view->getModel()->getItem()) { $params = array_merge($item->getData(), $params); } } return parent::renderHelper($identifier, $params); }
/** * Return the views output * * If the view 'output' variable is empty the output will be generated based on the * model data, if it set it will be returned instead. * * If the model contains a callback state, the callback value will be used to apply * padding to the JSON output. * * @return string The output of the view */ public function display() { if (empty($this->output)) { $this->output = KInflector::isPlural($this->getName()) ? $this->_getList() : $this->_getItem(); } if (!is_string($this->output)) { $this->output = json_encode($this->output); } //Handle JSONP if (!empty($this->_padding)) { $this->output = $this->_padding . '(' . $this->output . ');'; } return parent::display(); }
/** * Build the route. * * @param array An array of URL arguments * * @return array The URL arguments to use to assemble the subsequent URL. */ public function build(&$query) { $segments = array(); if (isset($query['view']) && !KInflector::isPlural($query['view'])) { unset($query['view']); } if (isset($query['id'])) { unset($query['id']); } if (isset($query['alias'])) { $segments[] = $query['alias']; unset($query['alias']); } return $segments; }
public function display() { $toolbar = $this->_createToolbar(); if ($this->getName() == 'dashboard') { $toolbar->reset(); } else { $toolbar->append('spacer'); } $toolbar->append(KFactory::get('admin::com.ninja.toolbar.button.about')); if (KInflector::isPlural(KFactory::get($this->getModel())->getIdentifier()->name)) { $this->_mixinMenubar(); } $this->templates = $this->getModel()->limit(0)->getList(); return parent::display(); }
/** * Set a view properties * * @param string The property name. * @param mixed The property value. */ public function __set($property, $value) { $name = $this->getName(); if ($property == 'item' || $property == 'items') { $name = $property; } if ($property == $name) { if (KInflector::isPlural($name)) { $this->_state->setList($value); } else { $this->_state->setItem($value); } } return parent::__set($property, $value); }
/** * @param KConfig $config */ public function __construct(KConfig $config) { parent::__construct($config); //Dynamic state injection based on relations. if ($this->getTable()->hasBehavior('relationable')) { $relations = $this->getTable()->getBehavior('relationable')->getRelations(); foreach ($relations as $children) { foreach ($children as $name => $relation) { if (KInflector::isPlural($name)) { $this->_state->insert($name, 'raw'); } $this->_state->insert(KInflector::singularize($name), 'int'); } } } $this->_state->insert('ancestors', 'raw'); }
protected function _actionGet(KCommandContext $context) { $view = $this->getView(); //Set the layout if ($view instanceof KViewTemplate) { if (KInflector::isPlural($view->getName())) { $view->getIdentifier()->path[1] = 'taxonomies'; } else { $view->getIdentifier()->path[1] = 'taxonomy'; } $layout = clone $view->getIdentifier(); $layout->package = 'taxonomy'; $layout->name = $view->getLayout(); //Force re-creation of the filepath to load the category templates $layout->filepath = ''; $view->setLayout($layout); } return parent::_actionGet($context); }
/** * @param $column * @return null */ private function __getRelation($type, $column) { $relations = $this->getRelations(); $taxonomies = json_decode($this->{$type}); if (KInflector::isSingular($column)) { return $this->getService($relations->{$type}->{$column}->identifier)->id($taxonomies->{$column})->getItem(); } if (KInflector::isPlural($column)) { $model = $this->getService($relations->{$type}->{$column}->identifier); $state = $model->getState(); if ($relations->{$type}->{$column}->{$column}->state) { foreach ($relations->{$type}->{$column}->state as $key => $value) { if ($filter = $state[$key]->filter) { $state->remove($key)->insert($key, $filter, $value); } } } return $model->id($taxonomies->{$column})->getList(); } }
/** * Constructor * * @param array Associative array of values */ public function __construct(KConfig $options) { $option = KRequest::get('get.option', 'cmd'); $view = KRequest::get('get.view', 'cmd'); if (KInflector::isPlural($view)) { $view = KInflector::singularize($view); } $id = KRequest::get('get.id', 'int', false); $name = $id ? $option . '.' . $view . '.' . $id : $option . '.' . $view; $app = KFactory::get('lib.joomla.application')->isAdmin() ? 'admin' : 'site'; $package = str_replace('com_', null, $option); //Override default settings $this->set($options->append(array('name' => $name, 'models' => (object) array('assets' => $app . '::com.' . $package . '.model.assets', 'user_groups' => $app . '::com.' . $package . '.model.user_groups'), 'inputName' => 'access', 'inputId' => 'access', 'id' => 'access', 'render' => 'permissions', 'objects' => array(), 'default' => false))->toArray()); return; // @TODO this shouldn't be needed anymore $actions = isset($options->actions) ? $options->actions : 'admin::com.ninja.controller.view'; foreach ((array) $actions as $action) { $this->setActions(KFactory::get($action)->getActions()); } }
/** * Method to set a controller object attached to the dispatcher * * @param mixed An object that implements KObjectServiceable, KServiceIdentifier object * or valid identifier string * @throws KDispatcherException If the identifier is not a controller identifier * @return KDispatcherAbstract */ public function setController($controller) { if (!$controller instanceof KControllerAbstract) { if (is_string($controller) && strpos($controller, '.') === false) { // Controller names are always singular if (KInflector::isPlural($controller)) { $controller = KInflector::singularize($controller); } $identifier = clone $this->getIdentifier(); $identifier->path = array('controller'); $identifier->name = $controller; } else { $identifier = $this->getIdentifier($controller); } if ($identifier->path[0] != 'controller') { throw new KDispatcherException('Identifier: ' . $identifier . ' is not a controller identifier'); } $controller = $identifier; } $this->_controller = $controller; return $this; }
/** * Return the views output. * * @return string The output of the view */ public function display() { $name = $this->getName(); $data = array(); //if data is set the just json encode those if (count($this->_data)) { $this->output = $this->_data; } elseif (KInflector::isPlural($name)) { $this->output = $this->_getList(); } else { $this->output = $this->_getItem(); } //if null then return empty string $this->output = pick($this->output, ''); if (!is_string($this->output)) { $this->output = json_encode($this->_toArray(KConfig::unbox($this->output))); } //Handle JSONP if (!empty($this->_padding)) { $this->output = $this->_padding . '(' . $this->output . ');'; } return $this->output; }
/** * Constructor * * @param array An optional associative array of configuration settings. */ public function __construct(KConfig $options) { parent::__construct($options); if (!isset($this->_buttons)) { $this->_buttons = array(); } $this->_name = empty($options->name) ? KRequest::get('get.view', 'cmd') : $options->name; $this->_title = empty($options->title) ? KInflector::humanize($this->getName()) : $options->title; KFactory::get('admin::com.ninja.helper.default')->css('/toolbar.css'); KFactory::get('admin::com.ninja.helper.default')->js('/toolbar.js'); if (KInflector::isSingular(KRequest::get('get.view', 'cmd', 'items'))) { KFactory::get('admin::com.ninja.helper.default')->js('window.addEvent(\'domready\',function(){if(formToolbar = $(\'' . KFactory::get('admin::com.ninja.helper.default')->formid() . '\')) formToolbar.addClass(\'validator-inline\');});'); } if (KInflector::isPlural($this->getName())) { $this->append('new')->append('edit')->append('delete'); } else { $this->append('save')->append('apply')->append('cancel'); } $template = KFactory::get('lib.joomla.application')->getTemplate(); $path = JPATH_THEMES . '/' . $template . '/html/com_' . $this->_identifier->package . '/toolbar'; KFactory::get($this->getTemplate())->addPath($path); $this->setLayout('admin::com.ninja.view.toolbar.toolbar_render'); $this->id = 'toolbar-' . $this->getName(); }
public function display() { //Load the js message box plugin KFactory::get('admin::com.ninja.helper.default')->js('/Roar.js'); KFactory::get('admin::com.ninja.helper.default')->css('/Roar.css'); // Display the toolbar $toolbar = $this->_createToolbar(); $path = KFactory::get($this->getModel())->getIdentifier()->path; if (KInflector::isPlural(KFactory::get($this->getModel())->getIdentifier()->name) && $this->getName() != 'dashboard') { $this->_mixinMenubar(); } if ($this->getName() == 'dashboard') { $toolbar->reset(); $this->_document->setBuffer(false, 'modules', 'submenu'); } else { $toolbar->append('spacer'); } $toolbar->append(KFactory::get('admin::com.ninja.toolbar.button.about')); //@TODO finish this //$this->lang(); return '<div class="nf template-' . JFactory::getApplication()->getTemplate() . '">' . parent::display() . '</div>'; //Add tooltips? //if(KInflector::isPlural($this->getName()) && (KFactory::get($this->getModel())->getTotal() > 1)) KTemplate::loadHelper('admin::com.ninja.helper.behavior.tooltip', 'th.hasHint', array('showOnce' => true, 'showOnLoad' => true, 'fixed' => true)); }
/** * Method to get a controller identifier * * @return object The controller. */ public function getController() { if (!$this->_controller) { $application = $this->_identifier->application; $package = $this->_identifier->package; //Get the controller name $controller = KRequest::get('get.view', 'cmd', $this->_controller_default); // Controller names are always singular if (KInflector::isPlural($controller)) { $controller = KInflector::singularize($controller); } $config = array('request' => $this->_request, 'persistent' => $this->_request_persistent, 'dispatched' => true); $this->_controller = KFactory::get($application . '::com.' . $package . '.controller.' . $controller, $config); } return $this->_controller; }
/** * @dataProvider providePlurals */ public function testIsPlural($singular, $plural) { $this->assertTrue(KInflector::isPlural($plural)); }