/**
  * Short description of method getRdfTriples
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @return \core_kernel_classes_ContainerCollection
  */
 public function getRdfTriples(\core_kernel_classes_Resource $resource)
 {
     $returnValue = null;
     $returnValue = new \core_kernel_classes_ContainerCollection(new \common_Object(__METHOD__));
     $referencer = ResourceReferencer::singleton();
     $tableName = $referencer->resourceLocation($resource);
     if (!empty($tableName)) {
         try {
             $tblmgr = new TableManager($tableName);
             $propertiesTableName = $tblmgr->getPropertiesTable();
             $dbWrapper = \core_kernel_classes_DbWrapper::singleton();
             // We get the triples for cardinality = multiple or lg dependent properties
             // as usual...
             $quotedUri = $dbWrapper->quote($resource->getUri());
             $propsQuery = 'SELECT "b"."id", "b"."uri", "p"."property_uri" AS "property_uri", COALESCE("p"."property_value", "p"."property_foreign_uri") as "property_value", "p"."l_language"  FROM "' . $tableName . '" "b" ';
             $propsQuery .= 'INNER JOIN "' . $propertiesTableName . '" "p" ON ("b"."id" = "p"."instance_id") WHERE "b"."uri" = ' . $quotedUri;
             $propertyColumns = $tblmgr->getPropertyColumns();
             $baseQuery = '';
             if (!empty($propertyColumns)) {
                 // But if we have properties as columns in the 'base table' we
                 // have to be crafty...
                 $baseQueries = array();
                 foreach ($propertyColumns as $k => $pC) {
                     $quotedPropUri = $dbWrapper->quote($pC);
                     $baseQueries[] = 'SELECT "b"."id", "b"."uri", ' . $quotedPropUri . ' AS "property_uri", "b"."' . $k . '" AS "property_value", \'\' AS "l_language" FROM "' . $tableName . '" "b" WHERE "b"."uri" = ' . $quotedUri . ' AND "b"."' . $k . '" IS NOT NULL';
                 }
                 $baseQuery = implode(' UNION ', $baseQueries);
             }
             $query = $propsQuery . ' UNION ' . $baseQuery . ' ORDER BY "property_uri"';
             try {
                 $result = $dbWrapper->query($query);
                 while ($row = $result->fetch()) {
                     if ($row['property_value'] != null) {
                         $triple = new \core_kernel_classes_Triple();
                         $triple->subject = $row['uri'];
                         $triple->predicate = $row['property_uri'];
                         $triple->object = $row['property_value'];
                         $triple->lg = $row['l_language'];
                         $returnValue->add($triple);
                     }
                 }
                 // In hard mode, the rdf:type given to resources is defined by
                 // 'the table' their are belonging to. In this case, we need to
                 // manually add these triples to the end result.
                 $types = $resource->getTypes();
                 foreach ($types as $class) {
                     $triple = new \core_kernel_classes_Triple();
                     $triple->subject = $resource->getUri();
                     $triple->predicate = RDF_TYPE;
                     $triple->object = $class->getUri();
                     $triple->lg = '';
                     $returnValue->add($triple);
                 }
             } catch (\PDOException $e) {
                 $uri = $resource->getUri();
                 throw new Exception("Unable to retrieve RDF triples of resource '{$uri}': " . $e->getMessage());
             }
         } catch (HardapiException $e) {
             throw new Exception("Unable to access data from table '{$tableName}: " . $e->getMessage());
         }
     }
     return $returnValue;
 }