english/administrator/components/com_templates/models/style.php
/**
	 * Method to save the form data.
	 *
	 * @param	array	The form data.
	 * @return	boolean	True on success.
	 */
Method to save the form data.
@param       array   The form data.
@return      boolean True on success.
Method to save the form data . @param array The form data . @return boolean True on success .
public function save($data)
	{
		$extension = JTable::getInstance('Extension');
		if ($extension->load(array('enabled' => 0, 'type' => 'template', 'element' => $data['template'], 'client_id' => $data['client_id']))) {
			$this->setError(JText::_('COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE'));
			return false;
		}
		$dispatcher = JDispatcher::getInstance();
		$table		= $this->getTable();
		$pk			= (!empty($data['id'])) ? $data['id'] : (int)$this->getState('style.id');
		$isNew		= true;
		JPluginHelper::importPlugin('extension');
		if ($pk > 0) {
			$table->load($pk);
			$isNew = false;
		}
		if (JRequest::getVar('task') == 'save2copy') {
		$data['title'] .= ' '.JText::_('JGLOBAL_COPY');
		$data['home'] = 0;
		$data['assigned'] ='';
		}
		if (!$table->bind($data)) {
			$this->setError($table->getError());
			return false;
		}
		$this->prepareTable($table);
		if (!$table->check()) {
			$this->setError($table->getError());
			return false;
		}
		$result = $dispatcher->trigger('onExtensionBeforeSave', array('com_templates.style', &$table, $isNew));
		if (in_array(false, $result, true)) {
			$this->setError($table->getError());
			return false;
		}
		if (!$table->store()) {
			$this->setError($table->getError());
			return false;
		}
		$user = JFactory::getUser();
		if ($user->authorise('core.edit','com_menus') && $table->client_id==0) {
			$n		= 0;
			$db		= JFactory::getDbo();
			$user	= JFactory::getUser();
			if (!empty($data['assigned']) && is_array($data['assigned'])) {
				JArrayHelper::toInteger($data['assigned']);
				$query = $db->getQuery(true);
				$query->update('#__menu');
				$query->set('template_style_id='.(int)$table->id);
				$query->where('id IN ('.implode(',', $data['assigned']).')');
				$query->where('template_style_id!='.(int) $table->id);
				$query->where('checked_out in (0,'.(int) $user->id.')');
				$db->setQuery($query);
				$db->query();
				$n += $db->getAffectedRows();
			}
			$query = $db->getQuery(true);
			$query->update('#__menu');
			$query->set('template_style_id=0');
			if (!empty($data['assigned'])) {
				$query->where('id NOT IN ('.implode(',', $data['assigned']).')');
			}
			$query->where('template_style_id='.(int) $table->id);
			$query->where('checked_out in (0,'.(int) $user->id.')');
			$db->setQuery($query);
			$db->query();
			$n += $db->getAffectedRows();
			if ($n > 0) {
				$app = JFactory::getApplication();
				$app->enQueueMessage(JText::plural('COM_TEMPLATES_MENU_CHANGED',$n));
			}
		}
		$this->cleanCache();
		$dispatcher->trigger('onExtensionAfterSave', array('com_templates.style', &$table, $isNew));
		$this->setState('style.id', $table->id);
		return true;
	}
public function save ( $ data ) { $ extension = JTable :: getInstance ( 'Extension' ) ; if ( $ extension -> load ( array ( 'enabled' => 0 , 'type' => 'template' , 'element' => $ data [ 'template' ] , 'client_id' => $ data [ 'client_id' ] ) ) ) { $ this -> setError ( JText :: _ ( 'COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE' ) ) ; return false ; } $ dispatcher = JDispatcher :: getInstance ( ) ; $ table = $ this -> getTable ( ) ; $ pk = ( ! empty ( $ data [ 'id' ] ) ) ? $ data [ 'id' ] : ( int ) $ this -> getState ( 'style.id' ) ; $ isNew = true ; JPluginHelper :: importPlugin ( 'extension' ) ; if ( $ pk > 0 ) { $ table -> load ( $ pk ) ; $ isNew = false ; } if ( JRequest :: getVar ( 'task' ) == 'save2copy' ) { $ data [ 'title' ] .= ' ' . JText :: _ ( 'JGLOBAL_COPY' ) ; $ data [ 'home' ] = 0 ; $ data [ 'assigned' ] = '' ; } if ( ! $ table -> bind ( $ data ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } $ this -> prepareTable ( $ table ) ; if ( ! $ table -> check ( ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } $ result = $ dispatcher -> trigger ( 'onExtensionBeforeSave' , array ( 'com_templates.style' , & $ table , $ isNew ) ) ; if ( in_array ( false , $ result , true ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } if ( ! $ table -> store ( ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } $ user = JFactory :: getUser ( ) ; if ( $ user -> authorise ( 'core.edit' , 'com_menus' ) && $ table -> client_id == 0 ) { $ n = 0 ; $ db = JFactory :: getDbo ( ) ; $ user = JFactory :: getUser ( ) ; if ( ! empty ( $ data [ 'assigned' ] ) && is_array ( $ data [ 'assigned' ] ) ) { JArrayHelper :: toInteger ( $ data [ 'assigned' ] ) ; $ query = $ db -> getQuery ( true ) ; $ query -> update ( '#__menu' ) ; $ query -> set ( 'template_style_id=' . ( int ) $ table -> id ) ; $ query -> where ( 'id IN (' . implode ( ',' , $ data [ 'assigned' ] ) . ')' ) ; $ query -> where ( 'template_style_id!=' . ( int ) $ table -> id ) ; $ query -> where ( 'checked_out in (0,' . ( int ) $ user -> id . ')' ) ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ n += $ db -> getAffectedRows ( ) ; } $ query = $ db -> getQuery ( true ) ; $ query -> update ( '#__menu' ) ; $ query -> set ( 'template_style_id=0' ) ; if ( ! empty ( $ data [ 'assigned' ] ) ) { $ query -> where ( 'id NOT IN (' . implode ( ',' , $ data [ 'assigned' ] ) . ')' ) ; } $ query -> where ( 'template_style_id=' . ( int ) $ table -> id ) ; $ query -> where ( 'checked_out in (0,' . ( int ) $ user -> id . ')' ) ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ n += $ db -> getAffectedRows ( ) ; if ( $ n > 0 ) { $ app = JFactory :: getApplication ( ) ; $ app -> enQueueMessage ( JText :: plural ( 'COM_TEMPLATES_MENU_CHANGED' , $ n ) ) ; } } $ this -> cleanCache ( ) ; $ dispatcher -> trigger ( 'onExtensionAfterSave' , array ( 'com_templates.style' , & $ table , $ isNew ) ) ; $ this -> setState ( 'style.id' , $ table -> id ) ; return true ; }
Method to save the form data.
Method to save the form data .
// Detect disabled extension // Initialise variables; // Include the extension plugins for the save events. // Load the row if saving an existing record. // Bind the data. // Prepare the row for saving // Check the data. // Trigger the onExtensionBeforeSave event. // Store the data. // Update the mapping for menu items that this style IS assigned to. // Remove style mappings for menu items this style is NOT assigned to. // If unassigned then all existing maps will be removed. // Clean the cache. // Trigger the onExtensionAfterSave event.