/** * Search one confirmation by one similar name * * @author Jonathan Sandoval <*****@*****.**> * @param Confirmation $confirmation Pseudo-confirmation with the data to search * @param string $operator To search with 'or' or 'and' * @param string $order The type of sort of the Confirmation * @param integer $begin The number of page to display the registry * @return Array[Confirmation] $confirmations Confirmation with the similar name or null */ static function advancedSearchConfirmation($confirmation = null, $operator = 'AND', $order = 'id', $begin = 0) { if ($confirmation === null) { return null; } $tableConfirmation = DatabaseManager::getNameTable('TABLE_CONFIRMATION'); $tablePerson = DatabaseManager::getNameTable('TABLE_PERSON'); $tableChurch = DatabaseManager::getNameTable('TABLE_CHURCH'); $celebrationDate = $confirmation->getCelebrationDate(); $queryOwner = "("; $posibleOwner = $confirmation->getIdOwner()[0]; $queryFather = "("; $posibleFather = $confirmation->getIdOwner()[1]; $queryMother = "("; $posibleMother = $confirmation->getIdOwner()[2]; $queryChurch = "("; $posibleChurch = $confirmation->getIdChurch(); if ($posibleOwner !== NULL) { for ($i = 0; $i < sizeof($posibleOwner) - 1; $i++) { $queryOwner = $queryOwner . $posibleOwner[$i]->getId() . ","; } $queryOwner = $queryOwner . $posibleOwner[sizeof($posibleOwner) - 1]->getId() . ")"; $queryOwner = "(o.id IN " . $queryOwner . ")"; } if ($posibleFather !== NULL) { for ($i = 0; $i < sizeof($posibleFather) - 1; $i++) { $queryFather = $queryFather . $posibleFather[$i]->getId() . ","; } $queryFather = $queryFather . $posibleFather[sizeof($posibleFather) - 1]->getId() . ")"; $queryFather = "((fa.id IN " . $queryFather . ") OR fa.id IS NULL)"; } if ($posibleMother !== NULL) { for ($i = 0; $i < sizeof($posibleMother) - 1; $i++) { $queryMother = $queryMother . $posibleMother[$i]->getId() . ","; } $queryMother = $queryMother . $posibleMother[sizeof($posibleMother) - 1]->getId() . ")"; $queryMother = "((mo.id IN " . $queryMother . ") OR mo.id IS NULL)"; } if ($posibleChurch !== NULL) { for ($i = 0; $i < sizeof($posibleChurch) - 1; $i++) { $queryChurch = $queryChurch . $posibleChurch[$i]->getId() . ","; } $queryChurch = $queryChurch . $posibleChurch[sizeof($posibleChurch) - 1]->getId() . ")"; $queryChurch = "(c.id IN " . $queryChurch . ")"; } if ($confirmation->getId() == 0) { $id = ''; } else { $id = $confirmation->getId(); } if ($confirmation->getIdBookRegistry() == 0) { $idBookRegistry = ''; } else { $idBookRegistry = $confirmation->getIdBookRegistry()->getId(); } $query = "SELECT b.* \r\n FROM {$tableConfirmation} AS b LEFT JOIN {$tablePerson} AS o ON b.idOwner = o.id \r\n LEFT JOIN {$tablePerson} AS fa ON o.idFather = fa.id\r\n LEFT JOIN {$tablePerson} AS mo ON o.idMother = mo.id\r\n JOIN {$tableChurch} AS c ON b.idChurch = c.id\r\n WHERE b.id LIKE '%{$id}%' {$operator}\r\n b.confirmationDate LIKE '%{$celebrationDate}%' {$operator} "; //Join the Query with the posibiitation query if ($queryOwner != '(') { $query = $query . $queryOwner . " " . $operator . " "; } else { $query = $query . "(o.id IN ())" . $operator . " "; } if ($queryFather != '(') { $query = $query . $queryFather . " " . $operator . " "; } else { $query = $query . "(fa.id IN ())" . $operator . " "; } if ($queryMother != '(') { $query = $query . $queryMother . " " . $operator . " "; } else { $query = $query . "(mo.id IN ())" . $operator . " "; } if ($queryChurch != '(') { $query = $query . $queryChurch . " " . $operator . " "; } else { $query = $query . "(c.id IN ())" . $operator . " "; } if ($idBookRegistry !== NULL) { $query = $query . "b.idConfirmationRegistry LIKE '%{$idBookRegistry}%'"; } else { $query = $query . "b.idConfirmationRegistry LIKE '%%'"; } if ($order == 'nameChild') { $query = $query . " ORDER BY o.names"; } else { if ($order == 'nameChurch') { $query = $query . " ORDER BY c.name"; } else { $query = $query . " ORDER BY b.id DESC"; } } $query = $query . " LIMIT " . strval($begin * 10) . ", 11 "; $arrayConfirmations = DatabaseManager::multiFetchAssoc($query); $confirmations = array(); if ($arrayConfirmations !== NULL) { $i = 0; foreach ($arrayConfirmations as $confirmation) { if ($i == 10) { continue; } $confirmations[] = self::ArrayToConfirmation($confirmation); $i++; } return $confirmations; } else { return null; } }