Your IP : 216.73.216.170


Current Path : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_poll/models/
Upload File :
Current File : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_poll/models/question.php

<?php

// No direct access
defined( '_JEXEC' ) or die;

// Подключаем библиотеку modeladmin Joomla.
jimport('joomla.application.component.modeladmin');


/**
 * Модель редактирования текущего элемента
 * @author kirdinyuri
 */
class PollModelQuestion extends JModelAdmin {

	
	/**
	 * загрузка текущей формы
	 * @param Array $data
	 * @param Boolean $loadData
	 * @return Object form data
	 */
	public function getForm( $data = array( ), $loadData = true ) {
		// Получаем форму.
		$form = $this->loadForm('com_poll.question', 'question',
								array('control' => 'jform', 'load_data' => $loadData));
		if (empty($form))
		{
			return false;
		}
		 $id = JFactory::getApplication()->input->get('id', 0);
		$user = JFactory::getUser();
	 
		// Изменяем форму исходя из доступов пользователя.
		if ($id != 0 && (!$user->authorise('core.edit.state', $this->option . '.#__pollquestions.' . (int) $id))
			|| ($id == 0 && !$user->authorise('core.edit.state', $this->option)))
		{
			// Модифицируем поля.
			$form->setFieldAttribute('state', 'disabled', 'true');
		}

		return $form;
	}

	/**
	 * @param Int $id (object identifier)
	 * @return Object (current item)
	 */
	public function getItem( $id = null ) {
		if ( $item = parent::getItem( $id ) ) {
			//$item->text = trim( $item->fulltext ) != '' ? $item->introtext . '<hr id="system-readmore" />' . $item->fulltext : $item->introtext;
		}
		return $item;
	}

	/**
	 * @param string $type
	 * @param string $prefix
	 * @param array $config
	 * @return JTable|mixed
	 */
	public function getTable( $type = 'pollquestions', $prefix = 'Table', $config = array( ) ) {
		return JTable::getInstance( $type, $prefix, $config );
	}

	/**
	 * Загрузка данных в форму
	 * @return Object
	 */
	protected function loadFormData() {
		$data = JFactory::getApplication()->getUserState( 'com_poll.edit.question.data', array() );
		if ( empty( $data ) ) {
			$data = $this->getItem();
		}
		return $data;
	}

	/**
	 * Запрет удаления записи
	 * @param object $record
	 * @return bool
	 */
	protected function canDelete( $record )
	{
		if ( !empty( $record->id ) ) {
			return JFactory::getUser()->authorise( 'core.delete', '#__table1.' . (int)$record->id );
		}
	}

	/**
	 * Запрет изменения состояния
	 * @param object $record
	 * @return bool
	 */
	protected function canEditState( $record )
	{
		$user = JFactory::getUser();

		// Check for existing article.
		if ( !empty( $record->id ) ) {
			return $user->authorise( 'core.edit.state', '#__pollquestions.' . (int)$record->id );
		} // New article, so check against the category.
		elseif ( !empty( $record->catid ) ) {
			return $user->authorise( 'core.edit.state', '#__pollquestions.' . (int)$record->catid );
		} // Default to component settings if neither article nor category known.
		else {
			return parent::canEditState( 'com_poll' );
		}
	}


		/*protected function canEditState($record)
	{
		$user = JFactory::getUser();
	 
		if (!empty($record->id))
		{
			return $user->authorise('core.edit.state', $this->option . '.message.' . (int) $record->id);
		}
		elseif (!empty($record->catid))
		{
			return $user->authorise('core.edit.state', $this->option . '.category.' . (int) $record->catid);
		}
		else
		{
			return parent::canEditState($record);
		}
	}*/
}