I am inserting a variable called "creditCheck" into a twig template called node--course.html.twig
I start in a class caled FormaRegis which extedns a abstract class called FormaEntity
This is the function:
namespace Drupal\docebo_login;
use Drupal\docebo_login\FormaEntity;
class FormaRegis extends FormaEntity {
.
.
.
public function completionCheck() {
$check = false;
if (parent::accessCheck()) {
$sql = "SELECT count(*) as count FROM learning_courseuser
WHERE DATE_FORMAT(CURDATE(),'%d/%m/%Y') = DATE_FORMAT(date_complete,'%d/%m/%Y')
AND idUser = " . $_SESSION['public_area_idst'];
return $sql;
}
else {
return "";
}
}
In abstract class FormaEntity I have this function which is supposed to take the sql string from the previous function, completionCheck() and executes the mysql query and returns and object. Here is the function:
namespace Drupal\docebo_login;
use Drupal\Core\Access\AccessResult;
abstract class FormaEntity {
.
.
.
public function getCCresult() {
if ($this->completionCheck() == "") {
\Drupal\Core\Database\Database::setActiveConnection();
return false;
}
$result = $this->connection->query($this->completionCheck())->fetch();
\Drupal\Core\Database\Database::setActiveConnection();
if ($result > 5 ) {
$check = "fail";
}
else {
$check = "pass";
}
return $check;
}
In another class called FormaNotification which also extends FormaEntity write function that will be able to calls the function getCCresult() from the abstract class FormaEntity This is the function:
namespace Drupal\docebo_login;
use Drupal\docebo_login\FormaEntity;
class FormaNotification extends FormaEntity {
.
.
.
public function getCreditResult() {
return parent::getCCresult();
}
Lastly in my .theme file I wrote a function called txhs_preprocess_node__course(&$variables) which calls the previous function and is supposed to fetch the information I retrived from the database. But it does not. Here is my theme function:
use Drupal\docebo_login\FormaNotification;
use Drupal\docebo_login\FormaMyCourse;
use Drupal\docebo_login\FormaRegis;
use Drupal\Core\Url;
.
.
.
function txhs_preprocess_node__course(&$variables) {
$noti = new FormaNotification();
var_dump($noti->getCreditResult());
exit;
if ($noti->completionCheck() == "fail") {
$check = "fail";
}
else {
$check = "pass";
}
// $variables['creditCheck'] = "HI";
}
I have tried a whole slew of things such as renaming the functions, moving the functions around the theme file...but I really don't know what I am doing wrong.
I am running php 7.2.11, with mysql 5.0.12 with drupal 8.5.6
I expect an out to be an object with a number, but instead i get an error:
The website encountered an unexpected error. Please try again later. Error: Call to undefined method Drupal\docebo_login\FormaNotification::completionCheck() in Drupal\docebo_login\FormaEntity->getCCresult() (line 106 of modules/custom/docebo_login/src/FormaEntity.php).