Jump to content

Header repeated on pilot list [SOLVED]


Imanol

Recommended Posts

Hi everyone,

I am trying to edit the pilot list template adding a header but this is shown repeated on every hub tablet. I want the header to appear just once. Is there any way to solve it? Thanks.

 

Sin título.png

Edited by Imanol
Link to comment
Share on other sites

  • Moderators
1 hour ago, Imanol said:

Hi everyone,

I am trying to edit the pilot list template adding a header but this is shown repeated on every hub tablet. I want the header to appear just once. Is there any way to solve it? Thanks.

 

Sin título.png

Put your <img> tag outside of the "foreach" loop.

Link to comment
Share on other sites

  • Moderators

add the image in the Pilot module, no in the template. (spanish: añade la imagen en el módulo, no en la plantilla para evitar el ciclo y así no se repetirá)

<?php
/**
 * phpVMS - Virtual Airline Administration Software
 * Copyright (c) 2008 Nabeel Shahzad
 * For more information, visit www.phpvms.net
 *	Forums: http://www.phpvms.net/forum
 *	Documentation: http://www.phpvms.net/docs 
 *
 * phpVMS is licenced under the following license:
 *   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
 *   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
 *
 * @author Nabeel Shahzad
 * @copyright Copyright (c) 2008, Nabeel Shahzad
 * @link http://www.phpvms.net
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
 */
 
class Pilots extends CodonModule
{
	
	public $title = 'Pilots';
	/**
	 * Pilots::index()
	 * 
	 * @return
	 */
	public function index()
    { ?>
		// Image here
		<img src="" alt="" />
	<?php
		// Get all of our hubs, and list pilots by hub
		$allhubs = OperationsData::GetAllHubs();
		
		if(!$allhubs) $allhubs = array();
		
		foreach($allhubs as $hub)
		{
			$this->set('title', $hub->name);
			$this->set('icao', $hub->icao);
			
            $pilot_list = PilotData::findPilots(array('p.hub'=>$hub->icao));
			$this->set('allpilots', $pilot_list); # deprecated
            $this->set('pilot_list', $pilot_list);
								
			$this->render('pilots_list.tpl');
		}
		
		$nohub = PilotData::findPilots(array('p.hub'=>''));
		if(!$nohub) {
			return;
		}
		
		$this->set('title', 'No Hub');
		$this->set('icao', '');
		$this->set('allpilots', $nohub); # deprecated
        $this->set('pilot_list', $nohub);
		$this->render('pilots_list.tpl');
	}
	
	/**
	 * Pilots::reports()
	 * 
	 * @param string $pilotid
	 * @return
	 */
	public function reports($pilotid='')
	{
		if($pilotid == '') {
			$this->set('message', 'No pilot specified!');
			$this->render('core_error.tpl');
			return;
		}
		
        $pirep_list = PIREPData::GetAllReportsForPilot($pilotid);
		
        $this->set('pireps', $pirep_list); # deprecated
        $this->set('pireps_list', $pirep_list);
        
		$this->render('pireps_viewall.tpl');
	}
	
	
	/* Stats stuff for charts */
	
	
	/**
	 * Pilots::statsdaysdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsdaysdata($pilotid)
	{
		$data = PIREPData::getIntervalDataByDays(array('p.pilotid'=>$pilotid), 30);
		$this->create_line_graph('Past 30 days PIREPs', $data);
	}
	
	/**
	 * Pilots::statsmonthsdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsmonthsdata($pilotid)
	{
		$data = PIREPData::getIntervalDataByMonth(array('p.pilotid'=>$pilotid), 3);
		$this->create_line_graph('Monthly Flight Stats', $data);
	}
	
	/**
	 * Pilots::statsaircraftdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsaircraftdata($pilotid)
	{
		$data = StatsData::PilotAircraftFlownCounts($pilotid);
		if(!$data) $data = array();
		
		include CORE_LIB_PATH.'/php-ofc-library/open-flash-chart.php';
		
		$d = array();
		foreach($data as $ac) {
			OFCharts::add_data_set($ac->aircraft, floatval($ac->hours));
		}
		
		echo OFCharts::create_pie_graph('Aircraft Flown');
	}
	
	/**
	 * Pilots::create_line_graph()
	 * 
	 * @param mixed $title
	 * @param mixed $data
	 * @return
	 */
	protected function create_line_graph($title, $data)
	{	
		if(!$data) {
			$data = array();
		}
				
		$bar_values = array();
		$bar_titles = array();
		foreach($data as $val) {
			$bar_titles[] = $val->ym;
			$bar_values[] = floatval($val->total);
		}
	
		OFCharts::add_data_set($bar_titles, $bar_values);
		echo OFCharts::create_area_graph($title);
	}
		
	/**
	 * Pilots::RecentFrontPage()
	 * 
	 * @param integer $count
	 * @return
	 */
	public function RecentFrontPage($count = 5)
	{
        $pilot_list = PilotData::getLatestPilots($count);
		$this->set('pilots', $pilot_list);
        $this->set('pilot_list', $pilot_list);
        
		$this->render('frontpage_recentpilots.tpl');
	}
}

 

Edited by ProSkyDesign
Link to comment
Share on other sites

  • Moderators
20 hours ago, Vangelis said:

i have seen that at a lot of clients 

PHPvms is on an MVC framework that means that inserting html "display" code in a Module is bad practise and dificult to maintain and should be avoided.

That is why we have template files.

 

Sure, but other way is break the hub separation (loop) and include the image in the template.

Some people don't wannna break that division.

I'm agree with you but not at all.

We should avoid that when there is other solution or when the solution cause conflict with the syntaxe or more.

Edited by ProSkyDesign
Link to comment
Share on other sites

11 hours ago, ProSkyDesign said:

add the image in the Pilot module, no in the template. (spanish: añade la imagen en el módulo, no en la plantilla para evitar el ciclo y así no se repetirá)


<?php
/**
 * phpVMS - Virtual Airline Administration Software
 * Copyright (c) 2008 Nabeel Shahzad
 * For more information, visit www.phpvms.net
 *	Forums: http://www.phpvms.net/forum
 *	Documentation: http://www.phpvms.net/docs 
 *
 * phpVMS is licenced under the following license:
 *   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
 *   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
 *
 * @author Nabeel Shahzad
 * @copyright Copyright (c) 2008, Nabeel Shahzad
 * @link http://www.phpvms.net
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
 */
 
class Pilots extends CodonModule
{
	
	public $title = 'Pilots';
	/**
	 * Pilots::index()
	 * 
	 * @return
	 */
	public function index()
    { ?>
		// Image here
		<img src="" alt="" />
	<?php
		// Get all of our hubs, and list pilots by hub
		$allhubs = OperationsData::GetAllHubs();
		
		if(!$allhubs) $allhubs = array();
		
		foreach($allhubs as $hub)
		{
			$this->set('title', $hub->name);
			$this->set('icao', $hub->icao);
			
            $pilot_list = PilotData::findPilots(array('p.hub'=>$hub->icao));
			$this->set('allpilots', $pilot_list); # deprecated
            $this->set('pilot_list', $pilot_list);
								
			$this->render('pilots_list.tpl');
		}
		
		$nohub = PilotData::findPilots(array('p.hub'=>''));
		if(!$nohub) {
			return;
		}
		
		$this->set('title', 'No Hub');
		$this->set('icao', '');
		$this->set('allpilots', $nohub); # deprecated
        $this->set('pilot_list', $nohub);
		$this->render('pilots_list.tpl');
	}
	
	/**
	 * Pilots::reports()
	 * 
	 * @param string $pilotid
	 * @return
	 */
	public function reports($pilotid='')
	{
		if($pilotid == '') {
			$this->set('message', 'No pilot specified!');
			$this->render('core_error.tpl');
			return;
		}
		
        $pirep_list = PIREPData::GetAllReportsForPilot($pilotid);
		
        $this->set('pireps', $pirep_list); # deprecated
        $this->set('pireps_list', $pirep_list);
        
		$this->render('pireps_viewall.tpl');
	}
	
	
	/* Stats stuff for charts */
	
	
	/**
	 * Pilots::statsdaysdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsdaysdata($pilotid)
	{
		$data = PIREPData::getIntervalDataByDays(array('p.pilotid'=>$pilotid), 30);
		$this->create_line_graph('Past 30 days PIREPs', $data);
	}
	
	/**
	 * Pilots::statsmonthsdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsmonthsdata($pilotid)
	{
		$data = PIREPData::getIntervalDataByMonth(array('p.pilotid'=>$pilotid), 3);
		$this->create_line_graph('Monthly Flight Stats', $data);
	}
	
	/**
	 * Pilots::statsaircraftdata()
	 * 
	 * @param mixed $pilotid
	 * @return
	 */
	public function statsaircraftdata($pilotid)
	{
		$data = StatsData::PilotAircraftFlownCounts($pilotid);
		if(!$data) $data = array();
		
		include CORE_LIB_PATH.'/php-ofc-library/open-flash-chart.php';
		
		$d = array();
		foreach($data as $ac) {
			OFCharts::add_data_set($ac->aircraft, floatval($ac->hours));
		}
		
		echo OFCharts::create_pie_graph('Aircraft Flown');
	}
	
	/**
	 * Pilots::create_line_graph()
	 * 
	 * @param mixed $title
	 * @param mixed $data
	 * @return
	 */
	protected function create_line_graph($title, $data)
	{	
		if(!$data) {
			$data = array();
		}
				
		$bar_values = array();
		$bar_titles = array();
		foreach($data as $val) {
			$bar_titles[] = $val->ym;
			$bar_values[] = floatval($val->total);
		}
	
		OFCharts::add_data_set($bar_titles, $bar_values);
		echo OFCharts::create_area_graph($title);
	}
		
	/**
	 * Pilots::RecentFrontPage()
	 * 
	 * @param integer $count
	 * @return
	 */
	public function RecentFrontPage($count = 5)
	{
        $pilot_list = PilotData::getLatestPilots($count);
		$this->set('pilots', $pilot_list);
        $this->set('pilot_list', $pilot_list);
        
		$this->render('frontpage_recentpilots.tpl');
	}
}

 

It works perfectly! Thank you!

  • Like 1
Link to comment
Share on other sites

  • Moderators
9 hours ago, Imanol said:

It works perfectly! Thank you!

you're welcome !:)

I guess instead of make a discussion about how mvc works better, we can work to give to Imanol a solution, guys.

15 hours ago, servetas said:

@ProSkyDesign it can be avoided via moving the hub foreach statement into the template file in order to call the template file once. Check this.

No problem servetas but tell me: which of them will make more changes in the phpvms's default syntaxes?

Which of them is easier and faster?

I guess put an image in the top of site with module won't affect in the normal function of phpvms.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...