public function patch(\Archive\Port\Adaptor\Data\Archive\Documents\Document $doc, \Archive\Port\Adaptor\Data\Archive\Documents\Document $old) { $app = \App::getInstance(); $handler = new \Happymeal\Port\Adaptor\Data\ValidationHandler(); $doc->validateType($handler); if ($handler->hasErrors()) { $errors = $handler->getErrors(); foreach ($errors as $code => $err) { $app->throwError(new \Exception(implode(";", $err), $code)); } } else { $conn = $app->DB_CONNECT; $old->setYear($doc->getYear()); $old->setType($doc->getType()); $old->setPublished($doc->getPublished()); $old->setComments($doc->getComments()); $params = array(); $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); $query = $qb->update()->t("resources")->set()->c("xmlview")->eq()->val($old->toXmlStr())->where()->c("id")->eq()->val($old->getID())->fi(); $sth1 = $conn->prepare($query); $sth1->execute($params); $params = []; $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); $query = $qb->update()->t("documents_keys")->set()->c("type")->eq()->val($old->getType(), $qb::NOT_NULL)->c("year")->eq()->val($old->getYear(), $qb::NOT_NULL)->c("published")->eq()->val($old->getPublished(), $qb::NOT_NULL)->where()->c("documentId")->eq()->val($old->getID())->fi(); $sth2 = $conn->prepare($query); $sth2->execute($params); return $old; } }
public function execute() { $app = \App::getInstance(); $conn = $app->DB_CONNECT; $links = new \Archive\Port\Adaptor\Data\School\Archive(); $params = array(); $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); //print( \PDO::PARAM_INT );exit; $query = $qb->select()->c("*")->from()->t("links", "d")->where()->c("type")->eq()->val(isset($app->QUERY["type"]) ? $app->QUERY["type"] : null, $qb::NOT_NULL)->andTrue()->c("source")->eq()->val(isset($app->QUERY["source"]) ? $app->QUERY["source"] : null, $qb::NOT_NULL)->andTrue()->c("destination")->eq()->val(isset($app->QUERY["destination"]) ? $app->QUERY["destination"] : null, $qb::NOT_NULL)->limit(isset($app->QUERY["start"]) ? (int) $app->QUERY["start"] : 0, isset($app->QUERY["count"]) ? (int) $app->QUERY["count"] : 100)->fi(); //error_log($query); $sth = $conn->prepare($query); $sth->execute($params); while ($row = $sth->fetch()) { $link = new \Archive\Port\Adaptor\Data\Archive\Links\Link(); $link->fromXmlStr($row["xmlview"]); $links->setLink($link); } return $links; }
public function delete(\Archive\Port\Adaptor\Data\School\Persons\Person $person) { $app = \App::getInstance(); $conn = $app->DB_CONNECT; $params = []; $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); $query = $qb->delete()->from()->t("resources")->where()->c("id")->eq()->val($person->getID())->fi(); $sth = $conn->prepare($query); $sth->execute($params); // delete person keys $params = []; $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); $query = $qb->delete()->from()->t("persons_keys")->where()->c("id")->eq()->val($person->getID())->fi(); $sth1 = $conn->prepare($query); $sth1->execute($params); // delete all person links $params = []; $sth2 = $conn->prepare("DELETE FROM `links` WHERE `source`=? OR `destination`=?;"); $sth2->execute($params); return $person; }
public function patch(\School\Port\Adaptor\Data\Archive\Links\Link $link, \Archive\Port\Adaptor\Data\Archive\Links\Link $old) { $app = \App::getInstance(); if ($link->getSource() !== null) { $old->setSource($link->getSource()); } if ($link->getDestination() !== null) { $old->setDestination($link->getDestination()); } if ($link->getType() !== null) { $old->setType($link->getType()); } if ($link->getDtStart() !== null) { $old->setDtStart($link->getDtStart()); } if ($link->getDtEnd() !== null) { $old->setDtEnd($link->getDtEnd()); } if ($link->getComments() !== null) { $old->setComments($link->getComments()); } // check linked resources if (!$this->checkRefs($old)) { throw new \Exception("Link references not found", 450); } $handler = new \Happymeal\Port\Adaptor\Data\ValidationHandler(); $old->validateType($handler); if ($handler->hasErrors()) { $errors = $handler->getErrors(); foreach ($errors as $code => $err) { $app->throwError(new \Exception(implode(";", $err), $code)); } } else { $conn = $app->DB_CONNECT; $params = array(); $qb = new \Archive\Port\Adaptor\Persistence\QueryBuilder($params); $query = $qb->update()->t("links")->set()->c("type")->eq()->val($old->getType(), $qb::NOT_NULL)->c("source")->eq()->val($old->getSource(), $qb::NOT_NULL)->c("destination")->eq()->val($old->getDestination(), $qb::NOT_NULL)->c("dt_start")->eq()->val($old->getDtStart(), $qb::NOT_NULL)->c("dt_end")->eq()->val($old->getDtEnd(), $qb::NOT_NULL)->c("xmlview")->eq()->val($old->toXmlStr())->where()->c("id")->eq()->val($old->getID())->fi(); //print($query);print_r($params);exit; $sth = $conn->prepare($query); $sth->execute($params); return $old; } }