コード例 #1
0
 /**
  * Search one communion by one similar name
  * 
  * @author Jonathan Sandoval <*****@*****.**>
  * @param  Communion        $communion      Pseudo-communion with the data to search
  * @param  string         $operator     To search with 'or' or 'and'
  * @param  string         $order        The type of sort of the Communion
  * @param  integer        $begin        The number of page to display the registry
  * @return Array[Communion] $communions     Communion objects with the similar name or null
  */
 static function advancedSearchCommunion($communion = null, $operator = 'AND', $order = 'id', $begin = 0)
 {
     if ($communion === null) {
         return null;
     }
     $tableCommunion = DatabaseManager::getNameTable('TABLE_COMMUNION');
     $tablePerson = DatabaseManager::getNameTable('TABLE_PERSON');
     $tableChurch = DatabaseManager::getNameTable('TABLE_CHURCH');
     $celebrationDate = $communion->getCelebrationDate();
     $queryOwner = "(";
     $posibleOwner = $communion->getIdOwner()[0];
     $queryFather = "(";
     $posibleFather = $communion->getIdOwner()[1];
     $queryMother = "(";
     $posibleMother = $communion->getIdOwner()[2];
     $queryChurch = "(";
     $posibleChurch = $communion->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 ($communion->getId() == 0) {
         $id = '';
     } else {
         $id = $communion->getId();
     }
     if ($communion->getIdBookRegistry() == 0) {
         $idBookRegistry = '';
     } else {
         $idBookRegistry = $communion->getIdBookRegistry()->getId();
     }
     $query = "SELECT b.* \r\n                        FROM {$tableCommunion} 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.CommunionDate    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.idCommunionRegistry LIKE '%{$idBookRegistry}%'";
     } else {
         $query = $query . "b.idCommunionRegistry 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 ";
     $arrayCommunions = DatabaseManager::multiFetchAssoc($query);
     $communions = array();
     if ($arrayCommunions !== NULL) {
         $i = 0;
         foreach ($arrayCommunions as $communion) {
             if ($i == 10) {
                 continue;
             }
             $communions[] = self::ArrayToCommunion($communion);
             $i++;
         }
         return $communions;
     } else {
         return null;
     }
 }
コード例 #2
0
require_once __DIR__ . "/../../../Backend/CommunionManager.php";
require_once __DIR__ . "/../../../Backend/PersonManager.php";
if (!isset($_POST)) {
    echo "KO";
    die;
}
$church = ChurchManager::getSingleChurch('name', $_POST["celebrationChurch"]);
$child = new Person();
if ($_POST["idChild"] !== '0' && $_POST["idChild"] !== '') {
    $child = PersonManager::getSinglePerson('id', $_POST["idChild"]);
}
$child->setId($_POST["idChild"]);
$child->setNames($_POST["nameChild"]);
$child->setLastname1($_POST["lastname1Child"]);
$child->setLastname2($_POST["lastname2Child"]);
$communion = new Communion();
$communion->setId($_POST["idCommunion"]);
$celb = DatabaseManager::singleDateToDatabaseDate($_POST["celebrationDate"]);
$communion->setCelebrationDate($celb);
$communion->setIdChurch($church->getId());
$communion->setIdRector($_POST["rectorId"]);
//Data Process for the Father
$father = new Person();
if ($_POST["idFather"] !== '0' && $_POST["idFather"] !== '') {
    $father = PersonManager::getSinglePerson('id', $_POST["idFather"]);
    $father->setId($_POST["idFather"]);
    $father->setNames($_POST["nameFather"]);
    $father->setLastname1($_POST["lastname1Father"]);
    $father->setLastname2($_POST["lastname2Father"]);
    $father->setGender('M');
    PersonManager::updatePerson($father);
コード例 #3
0
$numberPage = intval($_GET["page"]);
$sortType = $_GET["sort"];
$simpleKeyword = $_GET["keyword"];
$kid = $_GET["kid"];
if ($sortType == NULL || $sortType == '') {
    $sortType = 'id';
}
if ($numberPage === NULL || $numberPage < 0) {
    echo "<script src='../JS/functions.js'></script><script>nextPage('set', '0')</script>";
}
//Getting all registries
if ($simpleKeyword !== NULL) {
    $communionRegistries = CommunionManager::simpleSearchCommunion($simpleKeyword, $sortType, $numberPage);
} else {
    if ($kid !== NULL) {
        $communionSearch = new Communion();
        $kcelebration = DatabaseManager::singleDateToDatabaseDate($_GET["kcelebration"]);
        $knamec = $_GET["knamec"];
        $klastname1c = $_GET["klastname1c"];
        $klastname2c = $_GET["klastname2c"];
        $knamef = $_GET["knamef"];
        $klastname1f = $_GET["klastname1f"];
        $klastname2f = $_GET["klastname2f"];
        $knamem = $_GET["knamem"];
        $klastname1m = $_GET["klastname1m"];
        $klastname2m = $_GET["klastname2m"];
        $kchurch = $_GET["kchurch"];
        $kbook = $_GET["kbook"];
        $knumber = $_GET["knumber"];
        $kpape = $_GET["kpape"];
        $communionSearch->setId($kid);