Guest User

Untitled

a guest
May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. include_once 'PhonebookEntry.php';
  4.  
  5.  
  6. class Phonebook {
  7.  
  8.     private $entries = array();
  9.    
  10.     public function add($entry) {
  11.         $this->entries[] = $entry;
  12.     }
  13.    
  14.     public function getSorted($direction) {
  15.        
  16.         $nameArray = array();
  17.         $firstNameArray = array();
  18.         $familyNameArray = array();
  19.         $mobilePhoneArray = array();
  20.         $homePhoneArray = array();
  21.        
  22.        
  23.         for($i=0;$i<count($this->entries);$i++) {
  24.             $firstNameArray[$i] = $this->entries[$i]->getFirstName();;
  25.         }
  26.        
  27.         for($i=0;$i<count($this->entries);$i++) {
  28.             $familyNameArray[$i] = $this->entries[$i]->getFamilyName();;
  29.         }
  30.        
  31.         for($i=0;$i<count($this->entries);$i++) {
  32.             $nameArray[$i] = "$firstNameArray[$i]". ' ' ."$familyNameArray[$i]<br />";
  33.         }
  34.        
  35.         if($direction == 'asc') {
  36.             asort($nameArray);
  37.         }
  38.        
  39.         if($direction == 'desc') {
  40.             arsort($nameArray);
  41.         }
  42.        
  43.         $i = 0;
  44.        
  45.         for($i=0; $i < count($nameArray);$i++) {
  46.             $mobilePhoneArray[$i] = $this->entries[$i]->getMobilePhone();
  47.             $homePhoneArray[$i] = $this->entries[$i]->getHomePhone();
  48.         }
  49.  
  50.         foreach($nameArray as $key => $value) {
  51.         ?>
  52.             <table style="border: 1px solid black; font-size: 11px; font-family: Tahoma;margin-bottom: 10px;" width="200" border="0" cellpadding="5" cellspacing="0"><tbody>
  53.             <tr><td colspan="2" bgcolor="silver"><b><?php echo $nameArray[$key]; ?></b></td></tr>
  54.            
  55.             <?php if($mobilePhoneArray[$key] > 0){ ?>
  56.             <tr><td>Mobile:</td><td><?php echo $mobilePhoneArray[$key]; ?></td></tr> <?php } ?>
  57.            
  58.             <?php if($homePhoneArray[$key] > 0){ ?>
  59.             <tr><td>Home:</td><td><?php echo $homePhoneArray[$key]; ?></td></tr> <?php } ?>
  60.            
  61.             </tbody></table>
  62.            
  63.         <?php
  64.         }
  65.     }
  66.  
  67.    
  68.     public function getByFirstLetter($letter) {
  69.        
  70.        
  71.  
  72.     }
  73.    
  74.     public function getByPhoneNumber($numberPart) {
  75.    
  76.    
  77.  
  78.     }
  79.    
  80. }
  81.  
  82. ?>
Add Comment
Please, Sign In to add comment