/** * Returns all data columns for one or more modules, given the module's slug name. * * @version 1.0 * @since 1.0 * * @param string/array $slug | Single slug as string. Multiple slugs as array of strings. * @return array | Exception on failure. Array of module data arrays on success. */ public function getBySlug($slug) { if (!$this->init) { throw new FOX_exception(array('numeric' => 0, 'text' => "Descendent class must call init() before using class methods", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } if (empty($slug)) { throw new FOX_exception(array('numeric' => 1, 'text' => "Called with empty slug", 'data' => array('slug' => $slug), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => null)); } if (!is_array($slug)) { $slug = array($slug); $single = true; } else { $single = false; } // Build a list of all requested slugs not in the cache // ======================================================== $missing_slugs = array(); foreach ($slug as $slug_name) { if (!FOX_sUtil::keyExists($slug_name, $this->cache["slug"])) { // If the php_class is not present in the class cache, try reloading // the class cache from the persistent cache. if (!$cache_reloaded) { try { self::loadCache(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Cache get error", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } $cache_reloaded = true; // If the php_class is still not present in the class cache after reloading from // the persistent cache, add it to the array of classes to fetch from the db. if (!FOX_sUtil::keyExists($slug_name, $this->cache["slug"])) { $missing_slugs[] = $slug_name; } } else { $missing_slugs[] = $slug_name; } } } unset($slug_name); // Cache all missing requested slugs (uses a single query) // ======================================================== if ($missing_slugs) { try { self::load(array("slug" => $missing_slugs)); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 3, 'text' => "Load error", 'data' => array("slug" => $missing_slugs), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } } if ($single) { if (FOX_sUtil::keyExists($slug[0], $this->cache["slug"])) { $module_id = $this->cache["slug"][$slug[0]]; $result = FOX_sUtil::keyVal($module_id, $this->cache["module_id"]); } else { $result = null; } } else { $result = array(); foreach ($slug as $slug_name) { // Check if the slug_name exists in the slug dictionary if (FOX_sUtil::keyExists($slug_name, $this->cache["slug"])) { $module_id = $this->cache["slug"][$slug_name]; // Check if the module_id exists in the main datastore if (FOX_sUtil::keyExists($module_id, $this->cache["module_id"])) { $result[$slug_name] = $this->cache["module_id"][$module_id]; } } } unset($slug_name, $module_id); } return $result; }