Beispiel #1
0
function fillDepartment(Department $department, array $people)
{
    foreach ($people as $value) {
        for ($i = 0; $i < $value[0]; $i++) {
            $department->addEmployee(new $value[1]($value[2]));
        }
    }
}
Beispiel #2
0
 private function fillTheDepartment(Department $department, $addToDepartment)
 {
     foreach ($addToDepartment as $item) {
         foreach ($item as $count => $employee) {
             for ($i = 0; $i < $count; $i++) {
                 $em = new $employee[0]($employee[1], $employee[2]);
                 $department->addEmployee($em);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Declares an association between this object and a Department object.
  *
  * @param      Department $v
  * @return     Employee The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setDepartment(Department $v = null)
 {
     if ($v === null) {
         $this->setDepartmentId(NULL);
     } else {
         $this->setDepartmentId($v->getId());
     }
     $this->aDepartment = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Department object, it will not be re-added.
     if ($v !== null) {
         $v->addEmployee($this);
     }
     return $this;
 }
Beispiel #4
0
{
    private $_name;
    function __construct($name)
    {
        $this->_name = $name;
    }
    function getName()
    {
        return $this->_name;
    }
}
// End of Employee class.
# ***** END OF CLASSES ***** #
// Create a department:
$hr = new Department('Human Resources');
// Create employees:
$e1 = new Employee('Jane Doe');
$e2 = new Employee('John Doe');
// Add the employees to the department:
$hr->addEmployee($e1);
$hr->addEmployee($e2);
// Loop through the department:
echo "<h2>Department Employees</h2>";
foreach ($hr as $e) {
    echo "<p>{$e->getName()}</p>";
}
// Delete the objects:
unset($hr, $e1, $e2);
?>
</body>
</html>