Formulaire d'un composant d'administration Joomla

Réduire
X
 
  • Filtrer
  • Heure
  • Afficher
Tout effacer
nouveaux messages

  • [Problème] Formulaire d'un composant d'administration Joomla

    Bonjour à tous,

    Je suis en train de développer un composant d'administration Joomla pour pouvoir gérer les équipes d'un club de Tennis de Table. Sur la fenêtre d'édition d'une rencontre entre deux équipes, on doit saisir le championnat, les deux équipes et éventuellement le score. Et une équipe peut participer à qu'un seul championnat (voir la capture d'écran n°1).

    Actuellement pour sélectionner une équipe, j'utilise une fenêtre modale qui propose une liste de toutes les équipes, quelques soit le championnat. Et, j'aimerai que lorsque l'utilisateur sélectionne un championnat qu'il puisse sélectionner que des équipes qui participent au championnat sélectionné (voir capture d'écran n°2).

    Et je vois pas comment je peux faire ça sur un composant d'administration Joomla MVC (coté SQL, il me suffit de rajouter une clause where)
    Fichiers joints

  • #2
    Re : Formulaire d'un composant d'administration Joomla

    controllers/teams.php
    Code:
    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');
     
    // import Joomla controlleradmin library
    jimport('joomla.application.component.controlleradmin');
     
    /**
     * HelloWorlds Controller
     */
    class JttcmControllerTeams extends JControllerAdmin
    {
    	/**
    	 * Proxy for getModel.
    	 * @since	1.6
    	 */
    	public function getModel($name = 'Team', $prefix = 'JttcmModel') 
    	{
    		$model = parent::getModel($name, $prefix, array('ignore_request' => true));
    		return $model;
    	}
    }
    models/teams.php
    Code:
    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');
    // import the Joomla modellist library
    jimport('joomla.application.component.modellist');
    /**
     * HelloWorldList Model
     */
    class JttcmModelTeams extends JModelList
    {
    	protected function getListQuery()
    	{
    		$query = 'SELECT A.id,E.name AS club,A.number,B.gender,C.name as division,D.name AS playerCategory,E.own';
    		$query .= ' FROM #__teams A';
    		$query .= ' INNER JOIN #__team_championships B';
    		$query .= ' ON A.championship = B.id';
    		$query .= ' INNER JOIN #__team_divisions C';
    		$query .= ' ON B.division = C.id';
    		$query .= ' INNER JOIN #__player_categories D';
    		$query .= ' ON D.id = B.playerCategory';
    		$query .= ' INNER JOIN #__clubs E';
    		$query .= ' ON A.club = E.id';
    		$query .= ' WHERE B.season = \''.JttcmHelper::getCurrentSeason()->id.'\'';
    		$query .= ' ORDER BY E.own DESC,E.name ASC,A.number ASC';
    		return $query;
    	}
    }
    models/fields/team.php
    Code:
    <?php
    // No direct access
    defined('_JEXEC') or die('Restricted access');
    
    jimport('joomla.form.formfield');
    
    /**
    * Book form field class
    */
    class JFormFieldModal_Team extends JFormField
    {
    	/**
    	 * field type
    	 * @var string
    	 */
    	protected $type = 'Modal_Team';
    
    	/**
       * Method to get the field input markup
       */
      protected function getInput()
      {
    	  // Load modal behavior
    	  JHtml::_('behavior.modal', 'a.modal');
     
    	  // Build the script
    	  $script = array();
    	  $script[] = '    function jSelectTeam_'.$this->id.'(id, title, object) {';
    	  $script[] = '        document.id("'.$this->id.'_id").value = id;';
    	  $script[] = '        document.id("'.$this->id.'_name").value = title;';
    	  $script[] = '        SqueezeBox.close();';
    	  $script[] = '    }';
     
    	  // Add to document head
    	  JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
     
    	  // Setup variables for display
    	  $html = array();
    	  $link = 'index.php?option=com_jttcm&amp;view=teams&amp;layout=modal'.
                      '&amp;tmpl=component&amp;function=jSelectTeam_'.$this->id;
     
    	  $db = JFactory::getDbo();
    	  $query = 'SELECT b.name,a.number FROM #__teams a INNER JOIN #__clubs b ON a.club = b.id WHERE a.id ='.(int)$this->value;
              $db->setQuery($query);
              $title = $db->loadObject();
              if (empty($title)) {
                      $title = JText::_('COM_JTTCM_FIELD_SELECT_TEAM');
              }else{
    	          $title = htmlspecialchars($title->name.' '.$title->number, ENT_QUOTES, 'UTF-8');
    		}
    	  // The current book input field
    	  $html[] = '<div class="fltlft">';
    	  $html[] = '  <input type="text" id="'.$this->id.'_name" value="'.$title.'" disabled="disabled" size="30" />';
    	  $html[] = '</div>';
     
    	  // The book select button
    	  $html[] = '<div class="button2-left">';
    	  $html[] = '  <div class="blank">';
    	  $html[] = '    <a class="modal" title="'.JText::_('COM_JTTCM_SELECT_TEAM_TITLE').'" href="'.$link.
                             '" rel="{handler: \'iframe\', size: {x:800, y:450}}">'.
                             JText::_('COM_JTTCM_BUTTON_SELECT_TEAM').'</a>';
    	  $html[] = '  </div>';
    	  $html[] = '</div>';
     
    	  // The active book id field
    	  if (0 == (int)$this->value) {
    		  $value = '';
    	  } else {
    	  }
    		  $value = (int)$this->value;
     
    	  // class='required' for client side validation
    	  $class = '';
    	  if ($this->required) {
    		  $class = ' class="required modal-value"';
    	  }
     
    	  $html[] = '<input type="hidden" id="'.$this->id.'_id"'.$class.' name="'.$this->name.'" value="'.$value.'" />';
     
    	  return implode("\n", $html);
      }
    
    }
    models/forms/contest.xml
    Code:
    <?xml version="1.0" encoding="utf-8"?>
     
    <form>
        <fieldset addfieldpath="/administrator/components/com_jttcm/models/fields" name="request">
    		<field
    			name="id"
    			type="hidden"
    		/>
            
    		<field name="championship" type="modal_championship"
    			description="COM_JTTCM_CONTEST_FIELD_CHAMPIONSHIP_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_CHAMPIONSHIP"
    			required="true"
    			size="60"
    		/>
    		<field name="round" type="sql"
    			query="SELECT id,name FROM #__rounds ORDER BY `order` ASC"
    			key_field="id" value_field="name"
    			description="COM_JTTCM_CONTEST_FIELD_ROUND_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_ROUND"
    			required="true"
    		/>
    		
    		<field name="homeTeam" type="modal_team"
    			description="COM_JTTCM_CONTEST_FIELD_HOME_TEAM_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_HOME_TEAM"
    			required="true"
    			size="40"
    		/>
    		
    		<field name="guestTeam" type="modal_team"
    			description="COM_JTTCM_CONTEST_FIELD_GUEST_TEAM_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_GUEST_TEAM"
    			required="true"
    			size="40"
    		/>
    		
    		<field name="homeScore" type="text"
    			description="COM_JTTCM_CONTEST_FIELD_HOME_TEAM_DESC_SCORE"
    			label="COM_JTTCM_CONTEST_HEADING_HOME_TEAM_SCORE"
    			size="3"
    		/>
    		
    		<field name="guestScore" type="text"
    			description="COM_JTTCM_CONTEST_FIELD_GUEST_TEAM_SCORE_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_GUEST_TEAM_SCORE"
    			size="3"
    		/>
    		
    		<field name="contestDate" type="text"
    			description="COM_JTTCM_CONTEST_FIELD_DATE_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_DATE"
    			required="true"
    			size="8"
    		/>
    		
    		<field name="contestTime" type="text"
    			description="COM_JTTCM_CONTEST_FIELD_TIME_DESC"
    			label="COM_JTTCM_CONTEST_HEADING_TIME"
    			required="true"
    			size="5"
    		/>
    		
        </fieldset>
    </form>
    view/teams/view.html.php
    Code:
    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');
     
    // import Joomla view library
    jimport('joomla.application.component.view');
     
    /**
     * HelloWorlds View
     */
    class JttcmViewTeams extends JView
    {
    	/**
    	 * HelloWorlds view display method
    	 * @return void
    	 */
    	function display($tpl = null) 
    	{
    		// Get data from the model
    		$items = $this->get('Items');
    		$pagination = $this->get('Pagination');
     
    		// Check for errors.
    		if (count($errors = $this->get('Errors'))) 
    		{
    			JError::raiseError(500, implode('<br />', $errors));
    			return false;
    		}
    		// Assign data to the view
    		$this->items = $items;
    		$this->pagination = $pagination;
     
    		// Set the toolbar
    		$this->addToolBar();
     
    		// Display the template
    		parent::display($tpl);
    	}
     
    	/**
    	 * Setting the toolbar
    	 */
    	protected function addToolBar() 
    	{
    		JToolBarHelper::title(JText::_('COM_JTTCM_MANAGER_TEAMS'));
    		JToolBarHelper::deleteList('', 'teams.delete');
    		JToolBarHelper::editList('team.edit');
    		JToolBarHelper::addNew('team.add');
    	}
    }
    view/teams/tmpl/modal.php
    Code:
    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted Access');
    // load tooltip behavior
    JHtml::_('behavior.tooltip');
    
     $function = JRequest::getCmd('function', 'jSelectTeam');
    ?>
    <form action="<?php echo $this->action; ?>" method="post" name="adminForm">
    	<table class="adminlist">
    		<thead>
    			<tr>
    				<th width="5">
    					<?php echo JText::_('COM_JTTCM_TEAM_HEADING_ID'); ?>
    				</th>			
    				<th>
    					<?php echo JText::_('COM_JTTCM_TEAM_CHAMPIONSHIP'); ?>
    				</th>
    				<th>
    					<?php echo JText::_('COM_JTTCM_TEAM_CLUB'); ?>
    				</th>
    			</tr>		
    		</thead>
    		<tfoot>
    			<tr>
    				<td colspan="3"><?php echo $this->pagination->getListFooter(); ?></td>
    			</tr>
    		</tfoot>
    		<tbody>
    			<?php foreach($this->items as $i => $item): ?>
    				<tr class="row<?php echo $i % 2; ?>">
    					<td>
    						<?php echo $item->id; ?>
    					</td>
    					<td>
    						<?php 
    							if($item->gender == 'F')
    								echo 'Dames '.$item->playerCategory.' '.$item->division; 
    							else
    								echo 'Messieurs '.$item->playerCategory.' '.$item->division; 
    						?>
    					</td>
    					<td>
    						 <a class="pointer" onclick="if (window.parent) window.parent.<?php echo $this->escape($function);?>('<?php echo $item->id; ?>', '<?php echo $this->escape(addslashes($item->club.' '.$item->number)); ?>');"><?php echo $this->escape($item->club.' '.$item->number); ?></a>
    					</td>
    				</tr>
    			<?php endforeach; ?>
    		</tbody>
    	</table>
    	<div>
    		<input type="hidden" name="task" value="" />
    		<input type="hidden" name="boxchecked" value="0" />
    		<?php echo JHtml::_('form.token'); ?>
    	</div>
    </form>

    Commentaire


    • #3
      Re : Formulaire d'un composant d'administration Joomla

      view/contest/view.html.php
      Code:
      <?php
      // No direct access to this file
      defined('_JEXEC') or die('Restricted access');
       
      // import Joomla view library
      jimport('joomla.application.component.view');
       
      /**
       * HelloWorld View
       */
      class JttcmViewContest extends JView
      {
      	/**
      	 * display method of Hello view
      	 * @return void
      	 */
      	public function display($tpl = null) 
      	{
      		// get the Data
      		$form = $this->get('Form');
      		$item = $this->get('Item');
       
      		// Check for errors.
      		if (count($errors = $this->get('Errors'))) 
      		{
      			JError::raiseError(500, implode('<br />', $errors));
      			return false;
      		}
      		// Assign the Data
      		$this->form = $form;
      		$this->item = $item;
       
      		// Set the toolbar
      		$this->addToolBar();
       
      		// Display the template
      		parent::display($tpl);
      	}
       
      	/**
      	 * Setting the toolbar
      	 */
      	protected function addToolBar() 
      	{
      		JRequest::setVar('hidemainmenu', true);
      		$isNew = ($this->item->id == 0);
      		JToolBarHelper::title($isNew ? JText::_('COM_JTTCM_MANAGER_CONTEST_NEW') : JText::_('COM_JTTCM_MANAGER_CONTEST_EDIT'));
      		JToolBarHelper::save('contest.save');
      		JToolBarHelper::cancel('contest.cancel', $isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
      	}
      }
      view/contest/tmpl/edit.php
      Code:
      <?php
      // No direct access
      defined('_JEXEC') or die('Restricted access');
      JHtml::_('behavior.tooltip');
      ?>
      <form action="<?php echo JRoute::_('index.php?option=com_jttcm&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="contest-form">
      	<fieldset class="adminform">
      		<legend><?php echo JText::_( 'COM_JTTCM_CONTEST_DETAILS' ); ?></legend>
      		<ul class="adminformlist">
      <?php foreach($this->form->getFieldset() as $field): ?>
      			<li><?php echo $field->label;echo $field->input;?></li>
      <?php endforeach; ?>
      		</ul>
      	</fieldset>
      	<div>
      		<input type="hidden" name="task" value="contest.edit" />
      		<?php echo JHtml::_('form.token'); ?>
      	</div>
      </form>

      Commentaire

      Annonce

      Réduire
      Aucune annonce pour le moment.

      Partenaire de l'association

      Réduire

      Hébergeur Web PlanetHoster
      Travaille ...
      X