Skip to content

Commit

Permalink
solve editora utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
aponscat committed Aug 2, 2022
1 parent d3df790 commit a2efcbc
Showing 1 changed file with 44 additions and 118 deletions.
162 changes: 44 additions & 118 deletions src/Omatech/Editora/Utils/Editora.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,77 +32,19 @@ static function set_connection($conn) {

static function other_languages_url($inst_id, $lang)
{// return an array of language, niceurl
$sql="select language, niceurl
from omp_niceurl
where inst_id=:inst_id
and language!=:lang
";

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':lang', $lang, PDO::PARAM_STR);
$prepare->bindParam(':inst_id', $inst_id, PDO::PARAM_INT);
$prepare->execute();
return $prepare->fetchAll();
$sql="select language, niceurl
from omp_niceurl
where inst_id=:inst_id
and language!=:lang
";

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':lang', $lang, PDO::PARAM_STR);
$prepare->bindParam(':inst_id', $inst_id, PDO::PARAM_INT);
$resultSet = $prepare->executeQuery();
$rows=$resultSet->fetchAllAssociative();
return $rows;
}

/* Moved to DBInterfaceBase
static function get_url_data($language, $nice_url) {
if (!isset($language)) {
return ['type' => 'Home', 'class_tag' => 'Home'];
} else {// tenim idioma
if (!isset($nice_url))
{
$sql="select count(*) num
from omp_niceurl n
where n.language=:language
";
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':language', $language, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
if ($row['num']==0)
{// error language not found!
return ['type' => 'Error', 'language' => $language];
}
else
{// change language ok
return ['type' => 'Home', 'class_tag' => 'Home', 'language' => $language];
//return ['type' => 'ChangeLanguage', 'language' => $language];
}
} else {// check valid urlnice
$sql = "select n.inst_id, n.niceurl, i.class_id, c.tag, i.key_fields nom_intern
from omp_niceurl n
, omp_instances i
, omp_classes c
where n.language = :language
and n.niceurl = :nice_url
and i.id=n.inst_id
and i.class_id=c.id
";
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':language', $language, PDO::PARAM_STR);
$prepare->bindParam(':nice_url', $nice_url, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
if ($row) {
return ['type' => 'Instance'
, 'id' => $row['inst_id']
, 'class_tag' => ucfirst($row['tag'])
, 'class_id' => $row['class_id']
, 'nom_intern' => $row['nom_intern']
, 'language' => $language
];
} else {
return ['type' => 'Error', 'language' => $language];
}
}
}
}
*/

static function control_objecte($obj, $lg) {
$inst_id_from_url = self::get_inst_id_from_url($obj, $lg);
Expand All @@ -125,10 +67,11 @@ static function default_object_accio($obj, $lg) {
where i.id = :id
and i.class_id = c.id";

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':id', $id, PDO::PARAM_INT);
$prepare->execute();
$row=$prepare->fetch();
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':id', $id, PDO::PARAM_INT);

$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if ($row) {
return $row['tag'];
Expand All @@ -149,11 +92,11 @@ static function control_sortida($out) {
static function get_nice_from_id($id = null, $lg = null) {
$sql = "select niceurl as id from omp_niceurl n, omp_instances i where i.id=inst_id and inst_id=:id and language=:language";

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':id', $id, PDO::PARAM_INT);
$prepare->bindParam(':language', $lg, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':id', $id, PDO::PARAM_INT);
$prepare->bindParam(':language', $lg, PDO::PARAM_STR);
$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if (isset($row['id']))
return $row['id'];
Expand All @@ -178,14 +121,12 @@ static function get_inst_id_from_url($url, $lg) {
$sql = "select inst_id as id, class_id, niceurl from omp_niceurl n, omp_instances i where language=:language and n.inst_id=:url and inst_id=i.id";
if ($_REQUEST['req_info'] == 0)
$sql.=" and i.status = 'O'";
//$result = mysql_query($sql,$dbh);
//if (!$result) return -2;
//$row = mysql_fetch_array($result, MYSQL_ASSOC);
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->bindParam(':language', $lg, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->bindParam(':language', $lg, PDO::PARAM_STR);
$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if ($row) {
// Permanent redirection
Expand All @@ -199,20 +140,11 @@ static function get_inst_id_from_url($url, $lg) {
if ($_REQUEST['req_info'] == 0)
$sql.=" and status = 'O'";

/* $result = mysql_query($sql,$dbh);
if (!$result) return -2;
$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$_REQUEST['inst_id_from_url']=$row['id'];
return $row['id'];
}
*/

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
if ($row) {
$_REQUEST['inst_id_from_url'] = $row['id'];
return $row['id'];
Expand All @@ -223,20 +155,13 @@ static function get_inst_id_from_url($url, $lg) {
$sql = "select distinct inst_id as id from omp_niceurl n, omp_instances i where n.niceurl=:url and inst_id=i.id";
if (isset($_REQUEST['req_info']) && $_REQUEST['req_info'] == 0)
$sql.=" and i.status = 'O'";
//echo $sql;
// $result = mysql_query($sql,$dbh);
// if (!$result) return -2;
//
// if (mysql_num_rows($result) == 1) {
// $row = mysql_fetch_array($result, MYSQL_ASSOC);
// $_REQUEST['inst_id_from_url']=$row['id'];
// return $row['id'];
// }

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();


$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);

$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();;

if ($row) {
$_REQUEST['inst_id_from_url'] = $row['id'];
Expand Down Expand Up @@ -308,8 +233,9 @@ static function get_class_from_url($url, $lg) {

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if ($row) {
$_REQUEST['class_from_url'] = $row['class'];
return $row['class'];
Expand All @@ -325,8 +251,8 @@ static function get_class_from_url($url, $lg) {

$prepare = self::$conn->prepare($sql);
$prepare->bindParam(':url', $url, PDO::PARAM_STR);
$prepare->execute();
$row=$prepare->fetch();
$resultSet = $prepare->executeQuery();
$row=$resultSet->fetch();

if ($row) {
$_REQUEST['class_from_url'] = $row['class'];
Expand Down

0 comments on commit a2efcbc

Please sign in to comment.