/**
  * Search one church by one similar name
  * 
  * @author Jonathan Sandoval <*****@*****.**>
  * @param  Church        $church      Pseudo-church with the data to search
  * @param  string        $order       The type of sort of the Church
  * @param  integer       $begin       The number of page to display the registry
  * @param  string        $operator    To search with 'or' or 'and'
  * @return Array[Church] $churchs     Church objects with the similar name or null
  */
 static function advancedSearchChurch($church = null, $order = 'id', $begin = -1, $operator = 'AND')
 {
     if ($church === null) {
         return null;
     }
     $tableChurch = DatabaseManager::getNameTable('TABLE_CHURCH');
     $tableVicar = DatabaseManager::getNameTable('TABLE_VICAR');
     $tableDean = DatabaseManager::getNameTable('TABLE_DEAN');
     $tableCity = DatabaseManager::getNameTable('TABLE_CITY');
     $church->getId() <= 0 ? $id = '' : ($id = $church->getId());
     $name = $church->getName();
     $type = $church->getType();
     $church->getCode() <= 0 ? $code = '' : ($code = $church->getCode());
     $address = $church->getAddress();
     $colony = $church->getColony();
     $church->getPostalCode() <= 0 ? $postalCode = '' : ($postalCode = $church->getPostalCode());
     $phoneNumber = $church->getPhoneNumber();
     $vicar = $church->getIdVicar();
     $dean = $church->getIdDean();
     $city = $church->getIdCity();
     $query = "SELECT {$tableChurch}.*\r\n                          FROM {$tableChurch} \r\n                                LEFT JOIN {$tableDean}  ON {$tableChurch}.idDean  = {$tableDean}.id\r\n                                LEFT JOIN {$tableVicar} ON {$tableChurch}.idVicar = {$tableVicar}.id\r\n                                LEFT JOIN {$tableCity}  ON {$tableChurch}.idCity  = {$tableCity}.id\r\n                          WHERE {$tableChurch}.id          LIKE '%{$id}%'          {$operator}\r\n                                {$tableChurch}.name        LIKE '%{$name}%'        {$operator}\r\n                                {$tableChurch}.type        LIKE '%{$type}%'        {$operator}\r\n                                {$tableChurch}.code        LIKE '%{$code}%'        {$operator}\r\n                                {$tableChurch}.address     LIKE '%{$address}%'     {$operator}\r\n                                {$tableChurch}.colony      LIKE '%{$colony}%'      {$operator}\r\n                                {$tableChurch}.postalCode  LIKE '%{$postalCode}%'  {$operator}\r\n                                {$tableChurch}.phoneNumber LIKE '%{$phoneNumber}%' {$operator}\r\n                                ({$tableDean}.id           LIKE '%{$dean}%'        OR\r\n                                 {$tableDean}.name         LIKE '%{$dean}%'      ) {$operator}\r\n                                ({$tableVicar}.id          LIKE '%{$vicar}%'       OR\r\n                                 {$tableVicar}.name        LIKE '%{$vicar}%'     ) {$operator}\r\n                                ({$tableCity}.id           LIKE '%{$city}%'        OR\r\n                                 {$tableCity}.name         LIKE '%{$city}%'      )\r\n                                ORDER BY {$order}";
     $query = $query . " LIMIT " . strval($begin * 10) . ", 11 ";
     $arrayChurchs = DatabaseManager::multiFetchAssoc($query);
     if ($arrayChurchs === null) {
         return null;
     } else {
         $i = 0;
         foreach ($arrayChurchs as $church) {
             if ($i == 10) {
                 continue;
             }
             $churchs[] = self::ArrayToChurch($church);
             $i++;
         }
         return $churchs;
     }
 }