× Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

Acl utents for table

9 años 6 meses antes #828 por Eduardo Mena
Respuesta de Eduardo Mena sobre el tema Acl utents for table
Let's say you're trying to modify a table called books.
Install the component and then look for this file: yoursite/components/com_yourcomponent/models/books.php
There you'll find the getListQuery() method.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

9 años 6 meses antes - 9 años 6 meses antes #829 por ANTONIO
Respuesta de ANTONIO sobre el tema Acl utents for table
I am attaching the file, because I have not figured out how to change it, Thanks
<?php
/**
 * @version     2.0.0
 * @package     com_fidelitycard
 * @copyright   Copyright (C) 2015. Tutti i diritti riservati.
 * @license     GNU General Public License versione 2 o successiva; vedi LICENSE.txt
 * @author      Glamour caffè <noreply@glamourcaffefidelity.it> - https://www.glamourcaffefidelity.it
 */
// No direct access.
defined('_JEXEC') or die;
jimport('joomla.application.component.modelitem');
jimport('joomla.event.dispatcher');
/**
 * Fidelitycard model.
 */
class FidelitycardModelTransazioni extends JModelItem {
    /**
     * Method to auto-populate the model state.
     *
     * Note. Calling getState in this method will result in recursion.
     *
     * @since   1.6
     */
    protected function populateState() {
        $app = JFactory::getApplication('com_fidelitycard');
        // Load state from the request userState on edit or from the passed variable on default
        if (JFactory::getApplication()->input->get('layout') == 'edit') {
            $id = JFactory::getApplication()->getUserState('com_fidelitycard.edit.transazioni.id');
        } else {
            $id = JFactory::getApplication()->input->get('id');
            JFactory::getApplication()->setUserState('com_fidelitycard.edit.transazioni.id', $id);
        }
        $this->setState('transazioni.id', $id);
        // Load the parameters.
        $params = $app->getParams();
        $params_array = $params->toArray();
        if (isset($params_array['item_id'])) {
            $this->setState('transazioni.id', $params_array['item_id']);
        }
        $this->setState('params', $params);
    }
    /**
     * Method to get an ojbect.
     *
     * @param   integer   The id of the object to get.
     *
     * @return   mixed   Object on success, false on failure.
     */
    public function &getData($id = null) {
        if ($this->_item === null) {
            $this->_item = false;
            if (empty($id)) {
                $id = $this->getState('transazioni.id');
            }
            // Get a level row instance.
            $table = $this->getTable();
            // Attempt to load the row.
            if ($table->load($id)) {
                // Check published state.
                if ($published = $this->getState('filter.published')) {
                    if ($table->state != $published) {
                        return $this->_item;
                    }
                }
                // Convert the JTable to a clean JObject.
                $properties = $table->getProperties(1);
                $this->_item = JArrayHelper::toObject($properties, 'JObject');
            } elseif ($error = $table->getError()) {
                $this->setError($error);
            }
        }
        
      if ( isset($this->_item->utente) ) {
         $this->_item->utente_name = JFactory::getUser($this->_item->utente)->name;
      }
        return $this->_item;
    }
    public function getTable($type = 'Transazioni', $prefix = 'FidelitycardTable', $config = array()) {
        $this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
        return JTable::getInstance($type, $prefix, $config);
    }
    /**
     * Method to check in an item.
     *
     * @param   integer      The id of the row to check out.
     * @return   boolean      True on success, false on failure.
     * @since   1.6
     */
    public function checkin($id = null) {
        // Get the id.
        $id = (!empty($id)) ? $id : (int) $this->getState('transazioni.id');
        if ($id) {
            // Initialise the table
            $table = $this->getTable();
            // Attempt to check the row in.
            if (method_exists($table, 'checkin')) {
                if (!$table->checkin($id)) {
                    $this->setError($table->getError());
                    return false;
                }
            }
        }
        return true;
    }
    /**
     * Method to check out an item for editing.
     *
     * @param   integer      The id of the row to check out.
     * @return   boolean      True on success, false on failure.
     * @since   1.6
     */
    public function checkout($id = null) {
        // Get the user id.
        $id = (!empty($id)) ? $id : (int) $this->getState('transazioni.id');
        if ($id) {
            // Initialise the table
            $table = $this->getTable();
            // Get the current user object.
            $user = JFactory::getUser();
            // Attempt to check the row out.
            if (method_exists($table, 'checkout')) {
                if (!$table->checkout($user->get('id'), $id)) {
                    $this->setError($table->getError());
                    return false;
                }
            }
        }
        return true;
    }
    public function getCategoryName($id) {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query
                ->select('title')
                ->from('#__categories')
                ->where('id = ' . $id);
        $db->setQuery($query);
        return $db->loadObject();
    }
    public function publish($id, $state) {
        $table = $this->getTable();
        $table->load($id);
        $table->state = $state;
        return $table->store();
    }
    public function delete($id) {
        $table = $this->getTable();
        return $table->delete($id);
    }
}
Última Edición: 9 años 6 meses antes por ANTONIO.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

9 años 6 meses antes #830 por Eduardo Mena
Respuesta de Eduardo Mena sobre el tema Acl utents for table
Wrong file
should be transazionis.php

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

9 años 6 meses antes - 9 años 6 meses antes #832 por ANTONIO
Respuesta de ANTONIO sobre el tema Acl utents for table
site/my_component/models/transazionis.php  file 
<?php
/**
 * @version     2.0.0
 * @package     com_fidelitycard
 * @copyright   Copyright (C) 2015. Tutti i diritti riservati.
 * @license     GNU General Public License versione 2 o successiva; vedi LICENSE.txt
 * @author      Glamour caffè <noreply@glamourcaffefidelity.it> - https://www.glamourcaffefidelity.it
 */
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
 * Methods supporting a list of Fidelitycard records.
 */
class FidelitycardModelTransazionis extends JModelList
{
   /**
    * Constructor.
    *
    * @param    array    An optional associative array of configuration settings.
    *
    * @see        JController
    * @since      1.6
    */
   public function __construct($config = array())
   {
      if (empty($config['filter_fields']))
      {
         $config['filter_fields'] = array(
                            'id', 'a.id',
                'codice_cliente', 'a.codice_cliente',
                'carta', 'a.carta',
                'descrizione', 'a.descrizione',
                'data', 'a.data',
                'importo', 'a.importo',
                'punti', 'a.punti',
                'utente', 'a.utente',
         );
      }
      parent::__construct($config);
   }
   /**
    * Method to auto-populate the model state.
    *
    * Note. Calling getState in this method will result in recursion.
    *
    * @since    1.6
    */
   protected function populateState($ordering = null, $direction = null)
   {
      // Initialise variables.
      $app = JFactory::getApplication();
      // List state information
      $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
      $this->setState('list.limit', $limit);
      $limitstart = $app->input->getInt('limitstart', 0);
      $this->setState('list.start', $limitstart);
      if ($list = $app->getUserStateFromRequest($this->context . '.list', 'list', array(), 'array'))
      {
         foreach ($list as $name => $value)
         {
            // Extra validations
            switch ($name)
            {
               case 'fullordering':
                  $orderingParts = explode(' ', $value);
                  if (count($orderingParts) >= 2)
                  {
                     // Latest part will be considered the direction
                     $fullDirection = end($orderingParts);
                     if (in_array(strtoupper($fullDirection), array('ASC', 'DESC', '')))
                     {
                        $this->setState('list.direction', $fullDirection);
                     }
                     unset($orderingParts[count($orderingParts) - 1]);
                     // The rest will be the ordering
                     $fullOrdering = implode(' ', $orderingParts);
                     if (in_array($fullOrdering, $this->filter_fields))
                     {
                        $this->setState('list.ordering', $fullOrdering);
                     }
                  }
                  else
                  {
                     $this->setState('list.ordering', $ordering);
                     $this->setState('list.direction', $direction);
                  }
                  break;
               case 'ordering':
                  if (!in_array($value, $this->filter_fields))
                  {
                     $value = $ordering;
                  }
                  break;
               case 'direction':
                  if (!in_array(strtoupper($value), array('ASC', 'DESC', '')))
                  {
                     $value = $direction;
                  }
                  break;
               case 'limit':
                  $limit = $value;
                  break;
               // Just to keep the default case
               default:
                  $value = $value;
                  break;
            }
            $this->setState('list.' . $name, $value);
         }
      }
      // Receive & set filters
      if ($filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array'))
      {
         foreach ($filters as $name => $value)
         {
            $this->setState('filter.' . $name, $value);
         }
      }
      $ordering = $app->input->get('filter_order');
      if (!empty($ordering))
      {
         $list             = $app->getUserState($this->context . '.list');
         $list['ordering'] = $app->input->get('filter_order');
         $app->setUserState($this->context . '.list', $list);
      }
      $orderingDirection = $app->input->get('filter_order_Dir');
      if (!empty($orderingDirection))
      {
         $list              = $app->getUserState($this->context . '.list');
         $list['direction'] = $app->input->get('filter_order_Dir');
         $app->setUserState($this->context . '.list', $list);
      }
      $list = $app->getUserState($this->context . '.list');
      
      $this->setState('list.ordering', $list['ordering']);
      $this->setState('list.direction', $list['direction']);
   }
   /**
    * Build an SQL query to load the list data.
    *
    * @return    JDatabaseQuery
    * @since    1.6
    */
   protected function getListQuery()
   {
      // Create a new query object.
      $db    = $this->getDbo();
      $query = $db->getQuery(true);
      // Select the required fields from the table.
      $query
         ->select(
            $this->getState(
               'list.select', 'DISTINCT a.*'
            )
         );
      $query->from('`#__transazioni_` AS a');
      
      
      // Filter by search in title
      $search = $this->getState('filter.search');
      if (!empty($search))
      {
         if (stripos($search, 'id:') === 0)
         {
            $query->where('a.id = ' . (int) substr($search, 3));
         }
         else
         {
            $search = $db->Quote('%' . $db->escape($search, true) . '%');
            
         }
      }
      
      // Add the list ordering clause.
      $orderCol  = $this->state->get('list.ordering');
      $orderDirn = $this->state->get('list.direction');
      if ($orderCol && $orderDirn)
      {
         $query->order($db->escape($orderCol . ' ' . $orderDirn));
      }
      return $query;
   }
   public function getItems()
   {
      $items = parent::getItems();
      
      return $items;
   }
   /**
    * Overrides the default function to check Date fields format, identified by
    * "_dateformat" suffix, and erases the field if it's not correct.
    */
   protected function loadFormData()
   {
      $app              = JFactory::getApplication();
      $filters          = $app->getUserState($this->context . '.filter', array());
      $error_dateformat = false;
      foreach ($filters as $key => $value)
      {
         if (strpos($key, '_dateformat') && !empty($value) && !$this->isValidDate($value))
         {
            $filters[$key]    = '';
            $error_dateformat = true;
         }
      }
      if ($error_dateformat)
      {
         $app->enqueueMessage(JText::_("COM_FIDELITYCARD_SEARCH_FILTER_DATE_FORMAT"), "warning");
         $app->setUserState($this->context . '.filter', $filters);
      }
      return parent::loadFormData();
   }
   /**
    * Checks if a given date is valid and in an specified format (YYYY-MM-DD)
    *
    * @param string Contains the date to be checked
    *
    */
   private function isValidDate($date)
   {
      return preg_match("/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/", $date) && date_create($date);
   }
}
admin/my_component/models/transazionis.php file
<?php
/**
 * @version     2.0.0
 * @package     com_fidelitycard
 * @copyright   Copyright (C) 2015. Tutti i diritti riservati.
 * @license     GNU General Public License versione 2 o successiva; vedi LICENSE.txt
 * @author      Glamour caffè <noreply@glamourcaffefidelity.it> - https://www.glamourcaffefidelity.it
 */
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
 * Methods supporting a list of Fidelitycard records.
 */
class FidelitycardModelTransazionis extends JModelList {
    /**
     * Constructor.
     *
     * @param    array    An optional associative array of configuration settings.
     * @see        JController
     * @since    1.6
     */
    public function __construct($config = array()) {
        if (empty($config['filter_fields'])) {
            $config['filter_fields'] = array(
                                'id', 'a.id',
                'codice_cliente', 'a.codice_cliente',
                'carta', 'a.carta',
                'descrizione', 'a.descrizione',
                'data', 'a.data',
                'importo', 'a.importo',
                'punti', 'a.punti',
                'utente', 'a.utente',
            );
        }
        parent::__construct($config);
    }
    /**
     * Method to auto-populate the model state.
     *
     * Note. Calling getState in this method will result in recursion.
     */
    protected function populateState($ordering = null, $direction = null) {
        // Initialise variables.
        $app = JFactory::getApplication('administrator');
        // Load the filter state.
        $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
        $this->setState('filter.search', $search);
        $published = $app->getUserStateFromRequest($this->context . '.filter.state', 'filter_published', '', 'string');
        $this->setState('filter.state', $published);
        
        // Load the parameters.
        $params = JComponentHelper::getParams('com_fidelitycard');
        $this->setState('params', $params);
        // List state information.
        parent::populateState('a.id', 'asc');
    }
    /**
     * Method to get a store id based on model configuration state.
     *
     * This is necessary because the model is used by the component and
     * different modules that might need different sets of data or different
     * ordering requirements.
     *
     * @param   string      $id   A prefix for the store id.
     * @return   string      A store id.
     * @since   1.6
     */
    protected function getStoreId($id = '') {
        // Compile the store id.
        $id.= ':' . $this->getState('filter.search');
        $id.= ':' . $this->getState('filter.state');
        return parent::getStoreId($id);
    }
    /**
     * Build an SQL query to load the list data.
     *
     * @return   JDatabaseQuery
     * @since   1.6
     */
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);
        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'DISTINCT a.*'
                )
        );
        $query->from('`#__transazioni_` AS a');
        
      // Join over the user field 'utente'
      $query->select('utente.name AS utente');
      $query->join('LEFT', '#__users AS utente ON utente.id = a.utente');
        
        // Filter by search in title
        $search = $this->getState('filter.search');
        if (!empty($search)) {
            if (stripos($search, 'id:') === 0) {
                $query->where('a.id = ' . (int) substr($search, 3));
            } else {
                $search = $db->Quote('%' . $db->escape($search, true) . '%');
                
            }
        }
        
        // Add the list ordering clause.
        $orderCol = $this->state->get('list.ordering');
        $orderDirn = $this->state->get('list.direction');
        if ($orderCol && $orderDirn) {
            $query->order($db->escape($orderCol . ' ' . $orderDirn));
        }
        return $query;
    }
    public function getItems() {
        $items = parent::getItems();
        
        return $items;
    }
}

Última Edición: 9 años 6 meses antes por ANTONIO.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

9 años 6 meses antes #833 por Eduardo Mena
Respuesta de Eduardo Mena sobre el tema Acl utents for table
All right. In the site model (not the admin), add this in line 173:
else{$query->where('a.state = 1 AND '.$db->quoteName('a.created_by').' = '.JFactory::getUser()->get('id'));}

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

9 años 6 meses antes #834 por ANTONIO
Respuesta de ANTONIO sobre el tema Acl utents for table
I added the line 173 in "transazionis.php" but it does not work, when I access the website I get blank page. :-(

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Tiempo de carga de la página: 0.058 segundos
Gracias a Foro Kunena

Utilizamos cookies propias y de terceros para mejorar nuestros servicios y mostrarle publicidad relacionada con sus preferencias mediante el análisis de sus hábitos de navegación. Si continua navegando, consideramos que acepta su uso.