Ejemplo n.º 1
0
 /**
  * Method to auto-populate the model state.
  *
  * @access	public
  * @param	string	$ordering	
  * @param	string	$direction	
  * @return	void
  */
 public function populateState($ordering = null, $direction = null)
 {
     $jinput = JFactory::getApplication()->input;
     $layout = $jinput->get('layout', null, 'CMD');
     $render = $jinput->get('render', '', 'CMD');
     if ($layout == 'ajax') {
         $this->setState('context', 'ajax' . ($render ? '.' . $render : ''));
     }
     $globalParams = JComponentHelper::getParams('com_rtiprint', true);
     $this->setState('params', $globalParams);
     // If the context is set, assume that stateful lists are used.
     if ($this->context) {
         $app = JFactory::getApplication();
         // FILTERS
         foreach ($this->filter_vars as $var => $varType) {
             /*
             		//1. First read the Request in URL
             		//2. Then read the persistant value for THIS context
             		//3. Finaly read the state var sent by the caller
             		$value = $this->getUserStateFromRequest(
             			$this->context . '.filter.' . $var, 
             			'filter_' . $var, 
             			$this->state->get('filter.' . $var), 
             			$varType
             		);
             */
             //1. Read the state var sent by the caller
             //2. Then read the Request in URL
             //3. Finally read the persistant value for THIS context
             $value = $this->state->get('filter.' . $var, $this->getUserStateFromRequest($this->context . '.filter.' . $var, 'filter_' . $var, null, $varType));
             //Convert datetime entries back from a custom format
             if ($value && preg_match("/^date:(.+)/", $varType, $matches)) {
                 $date = RtiprintHelperDates::timeFromFormat($value, $matches[1]);
                 if ($date) {
                     jimport('joomla.utilities.date');
                     $jdate = new JDate($date);
                     $value = RtiprintHelperDates::toSql($jdate);
                 } else {
                     continue;
                 }
             }
             $this->setState('filter.' . $var, $value);
         }
         // FILTERS : SEARCHES
         foreach ($this->search_vars as $var => $varType) {
             //see Filters
             /*
             $value = $this->getUserStateFromRequest(
             	$this->context . '.search.' . $var, 
             	'filter_' . $var, 
             	$this->state->get('search.' . $var), 
             	$varType);
             */
             //1. Read the state var sent by the caller
             //2. Then read the Request in URL
             //3. Finally read the persistant value for THIS context
             $value = $this->state->get('search.' . $var, $this->getUserStateFromRequest($this->context . '.search.' . $var, 'search_' . $var, null, $varType));
             $this->setState('search.' . $var, $value);
         }
         // PAGINATION : LIMIT
         //1. First read the state var sent by the caller
         //2. Then read the Request in URL
         //3. Then read the default limit value for THIS context
         //4. Finally read the list limit value from the Joomla configuration
         $value = $this->state->get('list.limit', $app->getUserStateFromRequest('global.list.limit', 'limit', $this->state->get('list.limit.default', $app->getCfg('list_limit'))));
         $limit = $value;
         $this->setState('list.limit', $limit);
         // PAGINATION : LIMIT START
         //1. First read the Request in URL
         //2. Then read the state var sent by the caller
         $value = $app->getUserStateFromRequest($this->context . '.limitstart', 'limitstart', $this->state->get('list.limitstart'));
         $limitstart = $limit != 0 ? floor($value / $limit) * $limit : 0;
         $this->setState('list.start', $limitstart);
         // SORTING : ORDERING (Vocabulary confusion in Joomla. This is a SORTING. Ordering is an index value in the item.)
         //1. First read the Request in URL
         //2. Then read the default sorting value sent trough the args (called 'ordering')
         $value = $app->getUserStateFromRequest($this->context . '.ordercol', 'filter_order', $ordering);
         if (!in_array($value, $this->filter_fields)) {
             $value = $ordering;
             $app->setUserState($this->context . '.ordercol', $value);
         }
         $this->setState('list.ordering', $value);
         // SORTING : DIRECTION
         //1. First read the Request in URL
         //2. Then read the default direction value sent trough the args.
         $value = $app->getUserStateFromRequest($this->context . '.orderdirn', 'filter_order_Dir', $direction);
         if (!in_array(strtoupper($value), array('ASC', 'DESC', ''))) {
             $value = $direction;
             $app->setUserState($this->context . '.orderdirn', $value);
         }
         $this->setState('list.direction', $value);
     } else {
         $this->setState('list.start', 0);
         $this->state->set('list.limit', 0);
     }
     if (defined('JDEBUG')) {
         $_SESSION["Rtiprint"]["Model"][$this->getName()]["State"] = $this->state;
     }
 }
Ejemplo n.º 2
0
 /**
  * Save an item.
  *
  * @access	public
  * @param	array	$data	The post values.
  *
  * @return	boolean	True on success.
  */
 public function save($data)
 {
     //Convert from a non-SQL formated date (created)
     $data['created'] = RtiprintHelperDates::getSqlDate($data['created'], array('Y-m-d'), true);
     //Convert from a non-SQL formated date (modified)
     $data['modified'] = RtiprintHelperDates::getSqlDate($data['modified'], array('Y-m-d'), true);
     //Some security checks
     $acl = RtiprintHelper::getActions();
     //Secure the published tag if not allowed to change
     if (isset($data['published']) && !$acl->get('core.edit.state')) {
         unset($data['published']);
     }
     //Secure the author key if not allowed to change
     if (isset($data['created_by']) && !$acl->get('core.edit')) {
         unset($data['created_by']);
     }
     if (parent::save($data)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Method to validate the form data. 
  *  This override handle the inputs of files types, (Joomla issue when they
  * are required)
  *
  * @access	public
  * @param	object	$form	The form to validate against.
  * @param	array	$data	The data to validate.
  * @param	string	$group	The name of the field group to validate.
  *
  * @return	mixed	Array of filtered data if valid, false otherwise.
  */
 public function validate($form, $data, $group = null)
 {
     //Get the posted files if this model is concerned by files submission
     // JOOMLA FIX : if missing fields in $_POST -> issue in partial update when required
     $currentData = $this->getItem();
     foreach ($currentData as $fieldName => $value) {
         $field = $form->getField($fieldName, $group, $value);
         //Skip the ID data (and other fields not in the form)
         if (!$field) {
             continue;
         }
         //Missing in $_POST and required
         if (!in_array($fieldName, array_keys($data)) && $field->required) {
             //Insert the current object value. (UPDATE)
             $data[$fieldName] = $currentData->{$fieldName};
         }
     }
     //JOOMLA FIX : Reformate some field types not handled properly
     foreach ($form->getFieldset($group) as $field) {
         $value = null;
         if (isset($data[$field->fieldname])) {
             $value = $data[$field->fieldname];
         }
         switch ($field->type) {
             //JOOMLA FIX : Reformate the date/time format comming from the post
             case 'ckcalendar':
                 //cimport('helpers.dates');
                 if ($value && (string) $field->format && !RtiprintHelperDates::isNull((string) $value)) {
                     $time = RtiprintHelperDates::getSqlDate($value, array($field->format));
                     if ($time === null) {
                         JError::raiseWarning(1203, JText::sprintf('RTIPRINT_VALIDATOR_WRONG_DATETIME_FORMAT_FOR_PLEASE_RETRY', $field->label));
                         $valid = false;
                     } else {
                         $data[$field->fieldname] = RtiprintHelperDates::toSql($time);
                     }
                 }
                 break;
                 //JOOMLA FIX : Apply a null value if the field is in the form
             //JOOMLA FIX : Apply a null value if the field is in the form
             case 'ckcheckbox':
                 if (!$value) {
                     $data[$field->fieldname] = 0;
                 }
                 break;
         }
     }
     // JOOMLA FIX : always missing file names in $_POST -> issue when required
     //Get the posted files if this model is concerned by files submission
     if (count($this->fileFields)) {
         $fileInput = new JInput($_FILES);
         $files = $fileInput->get('jform', null, 'array');
         if (count($files['name'])) {
             foreach ($files['name'] as $fieldName => $value) {
                 //For required files, temporary insert the value comming from $_FILES
                 if (!empty($value)) {
                     $field = $form->getField($fieldName, $group);
                     if ($field->required) {
                         $data[$fieldName] = $value;
                     }
                 }
             }
         }
     }
     //Exec the native PHP validation (rules)
     $result = parent::validate($form, $data, $group);
     //check the result before to go further
     if ($result === false) {
         return false;
     }
     //ID key follower (in some case, ex : save2copy task)
     if (isset($data['id'])) {
         $result['id'] = $data['id'];
     }
     return $result;
 }