Exemple #1
0
 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);
 }
Exemple #2
0
 /**
  * Executes an authorization action with the passed arguments.
  * 
  * @param string          $name    The command name
  * @param KCommandContext $context The command context
  * 
  * @return bool Can return both true or false.  
  */
 public final function execute($action, KCommandContext $context)
 {
     $method = '_' . KInflector::variablize('authorize.' . $action);
     $result = self::AUTH_NOT_IMPLEMENTED;
     if (method_exists($this, $method)) {
         $this->_entity = $context->mixer;
         $this->_viewer = $context->viewer;
         $result = $this->{$method}($context);
     }
     return $result;
 }
Exemple #3
0
 /**
  * Applies an array of fiters to query by calling each filter as method
  * on the query.
  *
  * @param AnDomainQuery $query   Query Object
  * @param array         $filters An array of filter
  */
 public static function applyFilters($query, $filters)
 {
     foreach ($filters as $filter => $value) {
         $method = KInflector::variablize($filter);
         $value = KConfig::unbox($value);
         if (!is_array($value) || !is_numeric(key($value))) {
             $args = array($value);
         } else {
             $args = $value;
         }
         call_object_method($query, $method, $args);
     }
 }
Exemple #4
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param 	object 	An optional KConfig object with configuration options.
  * @return 	void
  */
 protected function _initialize(KConfig $config)
 {
     $identifier = clone $this->_parent;
     $identifier->name = KInflector::singularize($this->_name);
     $config->append(array('entityset' => 'anahita:domain.entityset.manytomany', 'target' => $identifier, 'target_child_key' => KInflector::variablize($identifier->name), 'target_parent_key' => 'id'));
     if (!$config->as) {
         //keep the as always the same for the two many to many relationship
         $names = array($config->parent->name, KInflector::singularize($config->name));
         sort($names);
         $config->as = $names[0] . ucfirst(KInflector::pluralize($names[1]));
     }
     parent::_initialize($config);
 }
Exemple #5
0
 /** 
  * Constructor.
  *
  * @param KConfig $config An optional KConfig object with configuration options.
  * 
  * @return void
  */
 public function __construct(KConfig $config)
 {
     $this->_initialize($config);
     if (!empty($config->aliases)) {
         foreach ($config->aliases as $alias => $property) {
             $this->setAlias($property, $alias);
         }
     }
     $this->_entity_identifier = $config->entity_identifier;
     $this->_repository = $config->repository;
     if (!$this->_repository) {
         throw new AnDomainDescriptionException("repository [AnDomainRepositoryAbstract] option is required");
     }
     if ($config->inheritance) {
         $this->_inheritance_column = $config->inheritance->column;
         //an object can only be abstract if it's
         //supports single table inheritance
         $this->_is_abstract = $config->inheritance->abstract;
         if ($config->inheritance->ignore) {
             $ignore = (array) $config->inheritance['ignore'];
             foreach ($ignore as $class) {
                 $this->_class_alias[$class] = '';
             }
         }
     }
     if (is_string($this->_inheritance_column)) {
         $this->_inheritance_column = $this->_repository->getResources()->getColumn($this->_inheritance_column);
     }
     $this->_entity_identifier = $this->_repository->getIdentifier($config->entity_identifier);
     if (!$config->identity_property) {
         $columns = $this->_repository->getResources()->main()->getColumns();
         foreach ($columns as $column) {
             if ($column->primary) {
                 $config->identity_property = KInflector::variablize($column->name);
                 break;
             }
         }
     }
     $this->_identity_property = $config->identity_property;
     //try to generate some of the propreties
     //from the database columns
     if ($config->auto_generate) {
         //if auto generate default set the identity property with the primary key
         $config->append(array('attributes' => array($this->_identity_property => array('key' => true))));
         $attributes = $config['attributes'];
         $columns = $this->_repository->getResources()->main()->getColumns();
         foreach ($columns as $column) {
             $name = KInflector::variablize($column->name);
             //merge the existing attributes
             $attributes[$name] = array_merge(array('required' => $column->required, 'column' => $column, 'type' => $column->type, 'default' => $column->default), isset($attributes[$name]) ? $attributes[$name] : array());
         }
         $config['attributes'] = $attributes;
     }
 }
Exemple #6
0
 /**
  * Converts methods to tags. For example $this->h1 will create a h1 tag
  * 	 
  */
 public function __call($method, $args)
 {
     $inflected = strtolower(KInflector::variablize($method));
     if (method_exists($this, $inflected)) {
         return call_user_func_array(array($this, $inflected), $args);
     }
     $content = isset($args[0]) ? $args[0] : '';
     $attributes = isset($args[1]) ? $args[1] : array();
     return $this->tag($method, $content, $attributes);
 }