function actionSaveClient($currentUser) { $backUrl = $this->context->getFlowScopeAttr("backUrl"); $client = new Client(); $clientErrs = array(); $client->setId($this->context->getRequestAttr("id")); $client->setPid($this->context->getRequestAttr("projectID")); $client->setName($this->context->getRequestAttr("name")); if (!is_null($client->getName())) { $client->setName(trim($client->getName())); if (strlen($client->getName()) < 1) { $client->setName(null); } } if (is_null($client->getName())) { $clientErrs["name"] = "field.error.empty"; } $client->setEmail($this->context->getRequestAttr("email")); if (!is_null($client->getEmail())) { $client->setEmail(trim($client->getEmail())); if (strlen($client->getEmail()) < 1) { $client->setEmail(null); } } if (is_null($client->getEmail())) { $clientErrs["email"] = "field.error.empty"; } $client->setTelephone($this->context->getRequestAttr("telephone")); if (!is_null($client->getTelephone())) { $client->setTelephone(trim($client->getTelephone())); if (strlen($client->getTelephone()) < 1) { $client->setTelephone(null); } } $client->setCustomer($this->context->getRequestAttr("customer")); if (!is_null($client->getCustomer())) { $client->setCustomer(trim($client->getCustomer())); if (strlen($client->getCustomer()) < 1) { $client->setCustomer(null); } } $client->setComment($this->context->getRequestAttr("comment")); if (!is_null($client->getComment())) { $client->setComment(trim($client->getComment())); if (strlen($client->getComment()) < 1) { $client->setComment(null); } } $periodicalID = $this->context->getRequestAttr("periodicalid"); $periodical = $this->context->getRequestAttr("periodCustomer"); $client->setPeriodical($periodical == 1 ? true : false); $timeZone = new DateTimeZone("Europe/Vilnius"); $time = new DateTime("now", $timeZone); $client->setR_date($time->format("Y-m-d H:i:s")); $client->setR_user($currentUser->getId()); $client->setActive(true); if (!is_null($periodicalID) && !$client->isPeriodical()) { $this->clientPeriodicalDao->delete($periodicalID); $this->clientDaol->resetPeriodicalClients($periodicalID); $client->setPeriodicalid(0); } if ($client->isPeriodical()) { $clientPeriodical = new ClientPeriodical(); $clientPeriodical->setId($periodicalID); $clientPeriodical->setPid($client->getPid()); $clientPeriodical->setName($client->getName()); $clientPeriodical->setEmail($client->getEmail()); $clientPeriodical->setCustomer($client->getCustomer()); $clientPeriodical->setTelephone($client->getTelephone()); $clientPeriodical->setComment($client->getComment()); $clientPeriodical->setR_date($time->format("Y-m-d H:i:s")); $clientPeriodical->setR_user($currentUser->getId()); $clientPeriodical->setPeriod_type($this->context->getRequestAttr("period_type")); $clientPeriodical->setWeek_day($this->context->getRequestAttr("week_day")); $clientPeriodical->setMonth_day($this->context->getRequestAttr("month_day")); $clientPeriodical->setHour($this->context->getRequestAttr("hour")); } else { $clientPeriodical = new ClientPeriodical(); } $this->context->setFlashScopeAttr("client", $client); $this->context->setFlashScopeAttr("clientPeriodical", $clientPeriodical); $this->context->setFlashScopeAttr("clientErrs", $clientErrs); $projectID = $client->getPid(); if (!$this->setStoreProject($projectID, "clientProject")) { $this->cancelClientEdit(); if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } if (count($clientErrs) >= 1) { if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } $insert = false; if (is_null($client->getId())) { $insert = true; } $periodicalStore = false; $clientStore = false; // Jei klientas periodinis - sukuriam periodini klienta atskirai if ($client->isPeriodical()) { $storePeriodical = $this->storeClientPeriodical($clientPeriodical); if (!$storePeriodical) { if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } $client->setPeriodicalid($clientPeriodical->getId()); $periodicalStore = true; } if ($client->isPeriodical() && !$insert || !$client->isPeriodical()) { $store = $this->storeClient($client); if (!$store) { if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } if ($insert) { $eventHistory = new EventHistory(); $eventHistory->setPid($client->getPid()); $eventHistory->setCid($client->getId()); $eventHistory->setR_date($client->getR_date()); $eventHistory->setDescription("Sukurtas projekto vadovo"); $this->storeEventHistory($eventHistory); } $clientStore = true; } if ($periodicalStore && !$clientStore) { $this->context->setRequestScopeAttr("success", "Periodinis klientas suskurtas sėkmingai."); } $this->cancelClientEdit(); if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; }
function find($criteria = null, $order = null, $limit = 1000, $from = 0) { $result = $this->database->query($this->buildFindQuery($criteria, $order, $limit, $from)); if (!is_null($result->getError())) { return $result->getError(); } $clientPeriodicals = array(); while ($row = $result->fetchRow()) { $clientPeriodical = new ClientPeriodical(); $value = $row[0]; $clientPeriodical->setId($value); $value = $row[1]; $clientPeriodical->setPid($value); $value = $row[2]; $clientPeriodical->setName($value); $value = $row[3]; $clientPeriodical->setEmail($value); $value = $row[4]; $clientPeriodical->setTelephone($value); $value = $row[5]; $clientPeriodical->setCustomer($value); $value = $row[6]; $clientPeriodical->setComment($value); $value = $row[7]; $clientPeriodical->setPeriod_type($value); $value = $row[8]; $clientPeriodical->setWeek_day($value); $value = $row[9]; $clientPeriodical->setMonth_day($value); $value = $row[10]; $clientPeriodical->setHour($value); $value = $row[11]; $clientPeriodical->setR_date($value); $value = $row[12]; $clientPeriodical->setR_user($value); if ($order != null) { array_push($clientPeriodicals, $clientPeriodical); } else { $clientPeriodicals[$clientPeriodical->getId()] = $clientPeriodical; } } return $clientPeriodicals; }