Esempio n. 1
0
 /**
  * Get the view object attached to the controller
  *
  * If the view is not an object, an object identifier or a fully qualified identifier string and the request does
  * not contain view information try to get the view from based on the model state instead. If the model is unique
  * use a singular view name, if not unique use a plural view name.
  *
  * @return  KViewInterface
  */
 public function getView()
 {
     if (!$this->_view instanceof KViewInterface) {
         if (!$this->_view instanceof KObjectIdentifier) {
             if (is_string($this->_view) && strpos($this->_view, '.') === false) {
                 if (!$this->getRequest()->query->has('view')) {
                     $view = $this->getIdentifier()->name;
                     if ($this->getModel()->getState()->isUnique()) {
                         $view = KStringInflector::singularize($view);
                     } else {
                         $view = KStringInflector::pluralize($view);
                     }
                 } else {
                     $view = $this->getRequest()->query->get('view', 'cmd');
                 }
             } else {
                 $view = $this->_view;
             }
             //Set the view
             $this->setView($view);
         }
         //Get the view
         $view = parent::getView();
         //Set the model in the view
         $view->setModel($this->getModel());
     }
     return parent::getView();
 }
Esempio n. 2
0
 public function getCommands()
 {
     $name = $this->getController()->getIdentifier()->name;
     $menu = array('Articles');
     foreach ($menu as $menu) {
         $this->addCommand($menu, array('href' => 'view=' . KStringInflector::pluralize(strtolower($menu)), 'active' => $name == KStringInflector::singularize(strtolower($menu))));
     }
     return parent::getCommands();
 }
Esempio n. 3
0
 protected function _buildQueryJoins(KDatabaseQueryInterface $query)
 {
     $state = $this->getState();
     parent::_buildQueryJoins($query);
     if ($state->table) {
         $identity_column = KStringInflector::singularize($state->table) . '_id';
         $table = KStringInflector::singularize($state->table) . '_translations';
         $query->columns('IFNULL(' . $identity_column . ', 0) AS translated')->columns('IFNULL(r.original, 0) AS original')->join(array('r' => $table), 'r.locale = tbl.lang_code AND r.' . $identity_column . ' = :id', 'left')->bind(array('id' => $state->row));
     }
 }
Esempio n. 4
0
 /**
  * Redirect to the form with the last category preselected if it exists in the URL
  *
  * @param KControllerContextInterface $context
  * @return KModelEntityInterface
  */
 protected function _setRedirect(KControllerContextInterface $context)
 {
     $referrer = $this->getReferrer($context);
     if ($referrer) {
         $query = $referrer->getQuery(true);
         if (!empty($query['category'])) {
             $identifier = $this->getIdentifier();
             $view = KStringInflector::singularize($identifier->name);
             $url = sprintf('index.php?option=com_%s&view=%s&category=%d', $identifier->package, $view, $query['category']);
             $context->response->setRedirect($this->getObject('lib:http.url', array('url' => $url)));
         }
     }
 }
Esempio n. 5
0
 /**
  * Instantiate the object
  *
  * If the behavior is auto mixed also lazy mix it into related row objects.
  *
  * @param 	KObjectConfigInterface  $config	  A KObjectConfig object with configuration options
  * @param 	KObjectManagerInterface	$manager  A KObjectInterface object
  * @return  KDatabaseBehaviorAbstract
  */
 public static function getInstance(KObjectConfigInterface $config, KObjectManagerInterface $manager)
 {
     $class = $manager->getClass($config->object_identifier);
     $instance = new $class($config);
     //Lazy mix behavior into related row objects. A supported behavior always has one is[Behaviorable] method.
     if ($instance->isSupported() && $instance->getMixer() && count($instance->getMixableMethods()) > 1) {
         $identifier = $instance->getMixer()->getIdentifier()->toArray();
         $identifier['path'] = array('database', 'row');
         $identifier['name'] = KStringInflector::singularize($identifier['name']);
         $manager->registerMixin($identifier, $instance);
     }
     return $instance;
 }
Esempio n. 6
0
 /**
  * Saves the current row and redirects to a new edit form
  *
  * @param KControllerContextInterface $context
  * @return KModelEntityInterface
  */
 protected function _actionSave2new(KControllerContextInterface $context)
 {
     // Cache and lock the referrer since _ActionSave would unset it
     $referrer = $this->getReferrer($context);
     $this->_lockReferrer($context);
     $entity = $this->save($context);
     // Re-set the referrer
     $cookie = $this->getObject('lib:http.cookie', array('name' => $this->_cookie_name, 'value' => (string) $referrer, 'path' => $this->_cookie_path));
     $context->response->headers->addCookie($cookie);
     $identifier = $this->getMixer()->getIdentifier();
     $view = KStringInflector::singularize($identifier->name);
     $url = sprintf('index.php?option=com_%s&view=%s', $identifier->package, $view);
     $context->response->setRedirect($this->getObject('lib:http.url', array('url' => $url)));
     return $entity;
 }
Esempio n. 7
0
 /**
  * Get the list of commands
  *
  * Will attempt to use information from the xml manifest if possible
  *
  * @return  array
  */
 public function getCommands()
 {
     $name = $this->getController()->getIdentifier()->name;
     $package = $this->getIdentifier()->package;
     $manifest = JPATH_ADMINISTRATOR . '/components/com_' . $package . '/' . $package . '.xml';
     if (file_exists($manifest)) {
         $xml = simplexml_load_file($manifest);
         if (isset($xml->administration->submenu)) {
             foreach ($xml->administration->submenu->children() as $menu) {
                 $view = (string) $menu['view'];
                 $this->addCommand((string) $menu, array('href' => 'option=com_' . $package . '&view=' . $view, 'active' => $name == KStringInflector::singularize($view)));
             }
         }
     }
     return parent::getCommands();
 }
Esempio n. 8
0
 /**
  * Constructor
  *
  * @param KObjectConfig $config  An optional KObjectConfig object with configuration options
  */
 public function __construct(KObjectConfig $config)
 {
     parent::__construct($config);
     $this->_table = $config->table;
     //Calculate the aliases based on the location of the table
     $model = $database = $this->getTable()->getIdentifier()->toArray();
     //Create database.rowset -> model.entity alias
     $database['path'] = array('database', 'rowset');
     $model['path'] = array('model', 'entity');
     $this->getObject('manager')->registerAlias($model, $database);
     //Create database.row -> model.entity alias
     $database['path'] = array('database', 'row');
     $database['name'] = KStringInflector::singularize($database['name']);
     $model['path'] = array('model', 'entity');
     $model['name'] = KStringInflector::singularize($model['name']);
     $this->getObject('manager')->registerAlias($model, $database);
     //Behavior depends on the database. Need to add if after database has been set.
     $this->addBehavior('indexable');
 }
Esempio n. 9
0
 /**
  * Method to set a controller object attached to the dispatcher
  *
  * @param   mixed   $controller An object that implements KControllerInterface, KObjectIdentifier object
  *                              or valid identifier string
  * @param  array  $config  An optional associative array of configuration options
  * @return	KDispatcherAbstract
  */
 public function setController($controller, $config = array())
 {
     if (!$controller instanceof KControllerInterface) {
         if (is_string($controller) && strpos($controller, '.') === false) {
             // Controller names are always singular
             if (KStringInflector::isPlural($controller)) {
                 $controller = KStringInflector::singularize($controller);
             }
             $identifier = $this->getIdentifier()->toArray();
             $identifier['path'] = array('controller');
             $identifier['name'] = $controller;
             $identifier = $this->getIdentifier($identifier);
         } else {
             $identifier = $this->getIdentifier($controller);
         }
         //Set the configuration
         $identifier->getConfig()->append($config);
         $controller = $identifier;
     }
     $this->_controller = $controller;
     return $this;
 }
Esempio n. 10
0
 public function getTranslation()
 {
     if (!isset($this->__object_translation)) {
         $identifier = array();
         if ($this->getMixer() instanceof KDatabaseTableInterface) {
             $identifier = $this->getMixer()->getIdentifier()->toArray();
         }
         if ($this->getMixer() instanceof KModelEntityInterface) {
             $identifier = $this->getMixer()->getTable()->getIdentifier()->toArray();
         }
         $identifier['path'] = array('model');
         $identifier['name'] = KStringInflector::singularize($identifier['name']) . '_translations';
         $identifier = new KObjectIdentifier($identifier);
         $this->__object_translation = $this->getObject($identifier);
     }
     return $this->__object_translation;
 }
Esempio n. 11
0
 /**
  * Get an instance of a row object for this table
  *
  * @param array $options An optional associative array of configuration settings.
  * @return  KDatabaseRowInterface
  */
 public function createRow(array $options = array())
 {
     $identifier = $this->getIdentifier()->toArray();
     $identifier['path'] = array('database', 'row');
     $identifier['name'] = KStringInflector::singularize($this->getIdentifier()->name);
     //Force the table
     $options['table'] = $this;
     //Set the identity column if not set already
     if (!isset($options['identity_column'])) {
         $options['identity_column'] = $this->mapColumns($this->getIdentityColumn(), true);
     }
     return $this->getObject($identifier, $options);
 }
Esempio n. 12
0
    public function getAssetName(KModelEntityInterface $entity = null)
    {
        $id      = $entity ? $entity->id : $this->id;
        $section = KStringInflector::singularize($this->getTable()->getIdentifier()->name);
        $package = $this->getTable()->getIdentifier()->package;

        return sprintf('com_%s.%s.%d', $package, $section, $id);
    }
Esempio n. 13
0
 /**
  * Create a new entity for the data source
  *
  * @param KModelContext $context A model context object
  *
  * @return KModelEntityInterface The entity
  */
 protected function _actionCreate(KModelContext $context)
 {
     //Get the data
     $data = KModelContext::unbox($context->entity);
     //Create the entity identifier
     $identifier = $this->getIdentifier()->toArray();
     $identifier['path'] = array('model', 'entity');
     if (!is_numeric(key($data))) {
         $identifier['name'] = KStringInflector::singularize($identifier['name']);
     } else {
         $identifier['name'] = KStringInflector::pluralize($identifier['name']);
     }
     $options = array('data' => $data, 'identity_key' => $context->getIdentityKey());
     return $this->getObject($identifier, $options);
 }
Esempio n. 14
0
<?php

/**
 * @package     DOCman
 * @copyright   Copyright (C) 2011 - 2014 Timble CVBA. (http://www.timble.net)
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.joomlatools.com
 */
defined('KOOWA') or die;
$type = KStringInflector::singularize($entity->getIdentifier()->name);
?>

<?php 
echo helper('behavior.koowa');
echo helper('translator.script', array('strings' => array('Calculating', 'Use default', 'Inherit from selected category', 'Inherit from parent category')));
?>

<ktml:script src="media://com_docman/js/access.js" />

<script>
var DOCman = DOCman || {};
DOCman.viewlevels = <?php 
echo json_encode($viewlevels);
?>
;

kQuery(function() {
    new DOCman.Usergroups('.access-box', {
        category: "<?php 
echo $type === 'document' ? '#docman_category_id' : '#category';
?>
Esempio n. 15
0
 /**
  * Search the mixin method map and call the method or trigger an error
  *
  * This function check to see if the method exists in the mixing map if not it will call the 'listbox' function.
  * The method name will become the 'name' in the config array.
  *
  * This can be used to auto-magically create select filters based on the function name.
  *
  * @param  string   $method The function name
  * @param  array    $arguments The function arguments
  * @throws BadMethodCallException   If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, $arguments)
 {
     if (!in_array($method, $this->getMethods())) {
         $config = $arguments[0];
         if (!isset($config['name'])) {
             $config['name'] = KStringInflector::singularize(strtolower($method));
         }
         return $this->_render($config);
     }
     return parent::__call($method, $arguments);
 }
Esempio n. 16
0
 /**
  * Create a new entity and insert it
  *
  * This function will either clone the entity object, or create a new instance of the entity object for each entity
  * being inserted. By default the entity will be cloned.
  *
  * @param   array   $properties The entity properties
  * @param   string  $status     The entity status
  * @return  KModelEntityComposite
  */
 public function create(array $properties = array(), $status = null)
 {
     if ($this->_prototypable) {
         if (!$this->_prototype instanceof KModelEntityInterface) {
             $identifier = $this->getIdentifier()->toArray();
             $identifier['path'] = array('model', 'entity');
             $identifier['name'] = KStringInflector::singularize($this->getIdentifier()->name);
             //The entity default options
             $options = array('identity_key' => $this->getIdentityKey());
             $this->_prototype = $this->getObject($identifier, $options);
         }
         $entity = clone $this->_prototype;
         $entity->setStatus($status);
         $entity->setProperties($properties, $entity->isNew());
     } else {
         $identifier = $this->getIdentifier()->toArray();
         $identifier['path'] = array('model', 'entity');
         $identifier['name'] = KStringInflector::singularize($this->getIdentifier()->name);
         //The entity default options
         $options = array('data' => $properties, 'status' => $status, 'identity_key' => $this->getIdentityKey());
         $entity = $this->getObject($identifier, $options);
     }
     //Insert the entity into the collection
     $this->insert($entity);
     return $entity;
 }
 /**
  * @dataProvider providePlurals
  */
 public function testSingularize($singular, $plural)
 {
     $this->assertEquals(KStringInflector::singularize($plural), $singular);
 }