Exemplo n.º 1
0
 protected function _commandNew(Library\ControllerToolbarCommand $command)
 {
     $option = $this->getController()->getIdentifier()->package;
     $view = Library\StringInflector::singularize($this->getIdentifier()->name);
     $table = $this->getController()->getModel()->getState()->table;
     $command->href = 'option=com_' . $option . '&view=' . $view . '&table=' . $table;
 }
Exemplo n.º 2
0
 public function createRow(array $options = array())
 {
     $identifier = clone $this->getIdentifier();
     $identifier->path = array('database', 'row');
     $identifier->name = Library\StringInflector::singularize($this->getIdentifier()->name);
     return $this->getObject($identifier, $options);
 }
Exemplo n.º 3
0
 public function getRequest()
 {
     $request = parent::getRequest();
     if (!$this->getUser()->isAuthentic()) {
         $request->query->access = 0;
     }
     $view = $request->query->get('view', 'cmd', null);
     if ($view && Library\StringInflector::isPlural($view)) {
         if ($request->getFormat() != 'json') {
             $sort_by_map = array('newest' => array('ordering_date' => 'DESC'), 'oldest' => array('ordering_date' => 'ASC'), 'order' => array('ordering' => 'ASC'));
             // Get the parameters
             $params = $this->getObject('application')->getParams();
             // Force some request vars based on setting parameters.
             $request->query->limit = (int) $params->get('articles_per_page', 3);
             $sort_by = $sort_by_map[$params->get('sort_by', 'newest')];
             $request->query->sort = key($sort_by);
             $request->query->direction = current($sort_by);
         }
         // Allow editors (and above) to view unpublished items on lists.
         if (!$this->canEdit()) {
             $request->query->published = 1;
         }
         //Always show child category articles
         $request->query->category_recurse = false;
     }
     return $request;
 }
Exemplo n.º 4
0
 public function render()
 {
     $model = $this->getModel();
     if (Library\StringInflector::isPlural($this->getName())) {
         $data = array('settings' => $model->getRowset()->toArray());
     } else {
         $data = $model->getRow()->toArray();
     }
     $this->setContent($data);
     return parent::render();
 }
Exemplo n.º 5
0
 public function _inline()
 {
     $url = $this->getObject('lib:http.url', array('url' => $this->module->params->get('url')));
     $parts = $url->getQuery(true);
     $package = substr($parts['option'], 4);
     $view = Library\StringInflector::singularize($parts['view']);
     $identifier = 'com:' . $package . '.controller.' . $view;
     //Render the component
     $html = $this->getObject($identifier, array('request' => $parts))->render();
     return $html;
 }
Exemplo n.º 6
0
 /**
  * Get the children rowset
  *
  * @return	Library\DatabaseRowInterface
  */
 public function getChildren()
 {
     if (!$this->_children instanceof Library\DatabaseRowsetInterface) {
         $identifier = clone $this->getIdentifier();
         $identifier->path = array('database', 'rowset');
         $identifier->name = Library\StringInflector::pluralize($this->getIdentifier()->name);
         //The row default options
         $options = array('identity_column' => $this->getIdentityColumn());
         $this->_children = $this->getObject($identifier, $options);
     }
     return $this->_children;
 }
Exemplo n.º 7
0
 public function groups($config = array())
 {
     $config = new Library\ObjectConfig($config);
     $config->append(array('name' => '', 'row' => '', 'package' => '', 'model' => 'groups', 'label' => 'title', 'deselect' => ''))->append(array('selected' => ''))->append(array('filter' => array('sort' => 'title')));
     $identifier = 'com:products.model.' . ($config->model ? $config->model : Library\StringInflector::pluralize($config->package));
     $categories = $this->getObject($identifier)->setState(Library\ObjectConfig::unbox($config->filter))->getRowset();
     $options = $this->options(array('entity' => $categories, 'value' => 'id', 'label' => $config->label));
     if ($config->deselect) {
         array_unshift($options, $this->option(array('label' => '-- Select --', 'value' => '0')));
     }
     //Add the options to the config object
     $config->options = $options;
     return $this->optionlist($config);
 }
Exemplo n.º 8
0
 /**
  * Finds the page for a component & view pair
  * @param $component
  * @param $view
  * @return mixed
  */
 public function findPage($query)
 {
     static $ids = array();
     ksort($query);
     $querystring = http_build_query($query);
     if (!isset($ids[$querystring])) {
         $pages = $this->getObject('application.pages');
         $view = isset($query['view']) ? $query['view'] : null;
         $itemid = isset($query['Itemid']) ? $query['Itemid'] : null;
         $match = null;
         $view_plural = Library\StringInflector::pluralize($view);
         if (!($match = $pages->find($itemid))) {
             //Need to reverse the array (highest sublevels first)
             $reverse = array_reverse($pages->toArray());
             $param_count = 0;
             foreach ($reverse as $page) {
                 $page = $pages->getPage($page['id']);
                 $link = $page->getLink();
                 if ($link) {
                     $link = clone $link;
                     unset($link->query['Itemid']);
                     if (count($link->query) && array_intersect_key($query, $link->query) == $link->query && count($link->query) > $param_count) {
                         $match = $page;
                         $param_count = count($link->query);
                     }
                 }
             }
             $param_count = 0;
             //Try plural views
             if (!$match && $view_plural != $view) {
                 foreach ($reverse as $page) {
                     $page = $pages->getPage($page['id']);
                     $q = $query;
                     $q['view'] = $view_plural;
                     $link = $page->getLink();
                     if ($link) {
                         $link = clone $link;
                         unset($link->query['Itemid']);
                         if (count($link->query) && array_intersect_key($q, $link->query) == $link->query && count($link->query) > $param_count) {
                             $match = $page;
                             $param_count = count($link->query);
                         }
                     }
                 }
             }
         }
         $ids[$querystring] = $match;
     }
     return $ids[$querystring];
 }
Exemplo n.º 9
0
 public function order($config = array())
 {
     $config = new Library\ObjectConfig($config);
     $config->append(array('name' => 'order', 'state' => null, 'attribs' => array(), 'model' => null, 'package' => $this->getIdentifier()->package, 'selected' => 0));
     //@TODO can be removed when name collisions fixed
     $config->name = 'order';
     $identifier = 'com:' . $config->package . '.model.' . ($config->model ? $config->model : Library\StringInflector::pluralize($config->package));
     $list = $this->getObject($identifier)->set($config->filter)->getRowset();
     $options = array();
     foreach ($list as $item) {
         $options[] = $this->option(array('label' => $item->ordering, 'value' => $item->ordering - $config->ordering));
     }
     $list = $this->optionlist(array('options' => $options, 'name' => $config->name, 'attribs' => $config->attribs, 'selected' => $config->selected));
     return $list;
 }
Exemplo n.º 10
0
 /**
  * Get the list of commands
  *
  * Will attempt to use information from the xml manifest if possible
  *
  * @return  array
  */
 public function getCommands()
 {
     $menu = $this->getObject('com:pages.model.menus')->application('admin')->getRowset()->find(array('slug' => 'menubar'));
     if (count($menu)) {
         $package = $this->getObject('component')->getIdentifier()->package;
         $view = $this->getObject('component')->getController()->getIdentifier()->name;
         $extension = $this->getObject('application.extensions')->getExtension($package);
         $groups = $this->getObject('user')->getGroups();
         // Make sure that pages without an assigned group are also included.
         $groups[] = 0;
         $pages = $this->getObject('application.pages')->find(array('pages_menu_id' => $menu->top()->id, 'extensions_extension_id' => $extension->id, 'hidden' => 0, 'users_group_id' => $groups));
         foreach ($pages as $page) {
             if ($page->level > 2) {
                 $this->addCommand(JText::_((string) $page->title), array('href' => (string) $page->link_url, 'active' => (string) $view == Library\StringInflector::singularize($page->getLink()->query['view'])));
             }
         }
     }
     return parent::getCommands();
 }
Exemplo n.º 11
0
 public function humanize($config = array())
 {
     $config = new Library\ObjectConfig($config);
     $config->append(array('sizes' => array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB')));
     $bytes = $config->size;
     $result = '';
     $format = ($bytes > 1024 * 1024 && $bytes % 1024 !== 0 ? '%.2f' : '%d') . ' %s';
     foreach ($config->sizes as $s) {
         $size = $s;
         if ($bytes < 1024) {
             $result = $bytes;
             break;
         }
         $bytes /= 1024;
     }
     if ($result == 1) {
         $size = Library\StringInflector::singularize($size);
     }
     return sprintf($format, $result, $this->translate($size));
 }
Exemplo n.º 12
0
 protected function _getFolders()
 {
     $page = $this->getObject('application.pages')->getActive();
     $params = new JParameter($page->params);
     if ($params->get('show_folders', 1)) {
         $state = $this->getModel()->getState();
         $identifier = clone $this->getIdentifier();
         $identifier->path = array('model');
         $identifier->name = Library\StringInflector::pluralize($this->getName());
         $model = $this->getObject($identifier)->container($state->container)->folder($state->folder);
         $folders = $model->getRowset();
         $total = $model->getTotal();
         if ($params->get('humanize_filenames', 1)) {
             foreach ($folders as $folder) {
                 $folder->display_name = ucfirst(preg_replace('#[-_\\s\\.]+#i', ' ', $folder->name));
             }
         }
     } else {
         $folders = array();
         $total = 0;
     }
     return array('items' => $folders, 'total' => $total);
 }
 /**
  * Create a new entity for the data source
  * Overridden to ensure identifier is set correctly
  *
  * @param Library\ModelContext $context A model context object
  * @return  Library\ModelEntityInterface The entity
  */
 protected function _actionCreate(Library\ModelContext $context)
 {
     //Get the data
     $data = Library\ModelContext::unbox($context->entity);
     //Create the entity identifier
     $identifier = $this->getIdentifier()->toArray();
     $identifier['path'] = array('model', 'entity');
     $identifier['name'] = 'venues';
     if (!is_numeric(key($data))) {
         $identifier['name'] = Library\StringInflector::singularize($identifier['name']);
     } else {
         $identifier['name'] = Library\StringInflector::pluralize($identifier['name']);
     }
     $options = array('data' => $data, 'identity_key' => $context->getIdentityKey());
     return $this->getObject($identifier, $options);
 }
 /**
  * Returns the states for a particular view as an array of state name => regex
  *
  * @param Library\ObjectIdentifier $identifier
  * @param $view
  * @return array
  */
 protected function getComponentViewStates(Library\ObjectIdentifier $identifier, $view)
 {
     $states = array();
     $model = $identifier->toArray();
     $model['path'] = array('model');
     $model['name'] = Library\StringInflector::pluralize($view);
     try {
         $model = $this->getObject($model);
     } catch (\Exception $e) {
         return array();
     }
     $state = $model->getState();
     foreach ($state as $value) {
         if (!$value->unique) {
             continue;
         }
         switch ($value->filter) {
             case 'word':
                 $regex = '[A-Za-z_]+';
                 break;
             case 'int':
                 $regex = '\\d+';
                 break;
             default:
                 $regex = '[A-Za-z0-9.\\-_]+';
                 break;
         }
         //Can't have multiple of the same state type for a route
         if (!in_array($regex, $states)) {
             $states[$value->name] = $regex;
         }
     }
     return $states;
 }