<?php
namespace front\factory;

class Scontainers
{
  public static function scontainer_details( $scontainer_id )
  {
    global $mdb, $lang;

    $cacheHandler = new \CacheHandler();
    $cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";

    $objectData = $cacheHandler->get($cacheKey);

    if ( !$objectData )
    {
      $scontainer = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$scontainer_id ] );
      $results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'AND' => [ 'container_id' => (int)$scontainer_id, 'lang_id' => $lang[0] ] ] );
      if ( is_array( $results ) ) foreach ( $results as $row )
        $scontainer['languages'] = $row;

      $cacheHandler -> set( $cacheKey, $scontainer );
    }
    else
    {
      return unserialize($objectData);
    }

    return $scontainer;
  }
}
