public function fetch(TaskSearchCommand $command)
 {
     if ($command->getFilter() != null) {
         if (strlen($command->getFilter()) < 2) {
             $command->setFilter(null);
             //we don't search when lower than 2 chars.. wtf
         }
     }
     $dateDiff = 'P1D';
     if (strcmp($command->getTipCursa(), "scurt") == 0) {
         //for tip cursa scurt we also save the hours in the timestamp. no need to do -1 in search
         $dateDiff = 'P0D';
     }
     if ($command->getStartDate() != null) {
         $command->setDateStartDate($command->getStartDate()->sub(new DateInterval('P0D')));
     } else {
         $today = new \DateTime('now');
         $command->setDateStartDate($today->sub(new DateInterval($dateDiff)));
     }
     $tasksList = $this->getTaskRepository()->fetchFutureTasks($command);
     $total = $this->getTaskRepository()->fetchCountFutureTasks($command);
     $result = array();
     $result["recordsTotal"] = $total;
     $result["recordsFiltered"] = $total;
     $data = array();
     foreach ($tasksList as $task) {
         $haveWePushed = false;
         if ($command->getSplitDetails()) {
             $multiDetails = explode(";", $task->getDetalii());
             $count = sizeof($multiDetails);
             foreach ($multiDetails as $detail) {
                 if ($count > 1 && strlen($detail) > 0) {
                     $task->setBani("");
                     $task->setDetalii($detail);
                     if (str_contains($detail, " ")) {
                         $codBaniList = explode(" ", $detail);
                         foreach ($codBaniList as $codBani) {
                             if (is_numeric($codBani)) {
                                 $task->setBani($codBani);
                             }
                         }
                     }
                     $row = $this->createRow($task);
                     array_push($data, $row);
                     $haveWePushed = true;
                 }
             }
         }
         if (!$haveWePushed) {
             $row = $this->createRow($task);
             array_push($data, $row);
         }
     }
     $result["data"] = $data;
     return $result;
 }
 /**
  * @param \Doctrine\ORM\QueryBuilder $qb
  * @param TaskSearchCommand $command
  * @return \Doctrine\ORM\QueryBuilder
  */
 private function addFilters(\Doctrine\ORM\QueryBuilder $qb, TaskSearchCommand $command)
 {
     if ($command->showOnlyFuture()) {
         $qb->andWhere($qb->expr()->gte('t.dateTime', "CURRENT_TIMESTAMP()"));
     } else {
         $qb = $this->addStartEndDateFilters($qb, $command);
     }
     if ($command->getTipCursa() != null) {
         $qb->andWhere($qb->expr()->eq("t.cursa", ":tipCursa"));
         $qb->setParameter(":tipCursa", $command->getTipCursa());
     }
     if ($command->getFilter() != null) {
         if (is_numeric($command->getFilter())) {
             $qb->andWhere($qb->expr()->eq("t.id", $command->getFilter()));
             //it's nice to have a search by id
         } else {
             $filter = "%" . $command->getFilter() . "%";
             $qb->setParameter(":filter", $filter);
             $qb->andWhere($qb->expr()->like("t.fullTask", ":filter"));
         }
     }
     return $qb;
 }
 public function fetch()
 {
     $start = Input::get("start");
     $length = Input::get("length");
     $searchArray = Input::get("search");
     $startDate = Input::get("startDate");
     $endDate = Input::get("endDate");
     $search = "";
     if (isset($searchArray)) {
         $search = $searchArray["value"];
     }
     $command = new TaskSearchCommand();
     $command->setFilter($search);
     $command->setLowerLimit($start);
     $command->setNoResults($length);
     $command->setStartDate($startDate);
     $command->setEndDate($endDate);
     $command->setTipCursa(Input::get("tipCursa"));
     if (strlen(Input::get("splitDetails")) > 0) {
         $command->setSplitDetails(true);
     }
     return json_encode($this->taskService->fetch($command), 0);
 }