コード例 #1
0
ファイル: node.php プロジェクト: janssit/nickys.janss.be
 /**
  * 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;
 }
コード例 #2
0
ファイル: listbox.php プロジェクト: janssit/www.technovit.be
 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);
 }
コード例 #3
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];
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: html.php プロジェクト: janssit/nickys.janss.be
 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);
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
0
 /**
  * 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;
 }