<?php
namespace Main\CompositePattern;

require_once 'Object.php';
require_once 'AbstractWorker.php';
require_once 'AbstractWorkGroup.php';

use \Main\Object;

class WorkGroup extends  AbstractWorkGroup
{
	// Attributes
	
	// Constructor
	
	public function __construct($workers)
	{
		// Do we have which is not null
		if(is_null($workers) == false)
		{
			// Workers can be added as an array or
			// just the first worker may be provided
			if(is_array($workers))
			{
				$this->AddWorkers(($workers));
			}
			else if($workers instanceof AbstractWorker)
			{
				$this->Add($workers);
			}
		}
	}
	
	// Methods for properties
	// Getters and Setters
	// NONE
	
	// Methods
	public function CalculateCost($hoursWorked)
	{
		$totalCost = 0.0;
		
		// Iterate through nodes belonging to this group,
		// hence use of NodeIterator
		$iter = $this->NodeIterator;		
		foreach($iter as $worker)
		{
			// Note: $worker maybe another WorkGroup, so CalculateCost
			// may result in another call to this method but from
			// within another WorkGroup object.
			$totalCost = $totalCost + $worker->CalculateCost($hoursWorked);
		}
		
		return $totalCost;
	}	
}
?>