public static function getMenusByCategory($category, $fromCache = true) { $cachekey = self::CachePrefix . $category; $values = $fromCache ? LuLu::getCache($cachekey) : false; if ($values === false) { $values = self::getArrayTreeInternal($category, 0, 0); LuLu::setCache($cachekey, $values); } return $values; }
public static function getModel($id, $fromCache = true) { $cacheKey = self::CachePrefix . $id; $value = $fromCache ? LuLu::getCache($cacheKey) : false; if ($value === false) { $value = Config::findOne(['id' => $id]); if ($value !== null) { LuLu::setCache($cacheKey, $value); } } return $value; }
public static function getData($code, $other = [], $fromCache = true) { $cacheKey = self::CachePrefix . $code; $values = $fromCache ? LuLu::getCache($cacheKey) : false; if ($values === false) { $fragment = self::findOne(['code' => $code]); if ($fragment == null) { return []; } $query = $fragment->type === 1 ? Fragment1Data::find() : Fragment2Data::find(); $query->where(['fragment_id' => $fragment->id, 'status' => 1]); $query->orderBy('sort_num asc'); $values = $query->all(); LuLu::setCache($cacheKey, $values); } $offset = isset($other['offset']) ? $other['offset'] : 0; $limit = isset($other['limit']) ? $other['limit'] : count($values) - $offset; return array_slice($values, $offset, $limit, true); }
public static function getTaxonomyById($id, $fromCache = true) { if ($id < 0 || empty($id)) { return null; } $cacheKey = self::CachePrefix . $id; $value = $fromCache ? LuLu::getCache($cacheKey) : false; if ($value === false) { $value = self::findOne(['id' => $id]); if ($value !== null) { LuLu::setCache($cacheKey, $value); } } return $value; }
public function getPermissionsByRole($role, $fromCache = true) { $cacheKey = self::CachePrefix . $role; $value = $fromCache ? LuLu::getCache($cacheKey) : false; if ($value === false) { $query = new Query(); $query->select(['p.id', 'p.category', 'p.name', 'p.description', 'p.form', 'p.default_value', 'p.rule', 'p.sort_num', 'r.role', 'r.value']); $query->from(['p' => $this->permissionTable, 'r' => $this->relationTable]); $query->where('r.permission=p.id'); $query->andWhere(['r.role' => $role]); $rows = $query->all(); $value = $this->convertPermissionValue($rows); LuLu::setCache($cacheKey, $value); } return $value; }