Esempio n. 1
0
 public function getById($id)
 {
     if (!MongoId::isValid($id)) {
         return null;
     }
     $datas = KLib\MongoDB::findOne(array('_id' => $id), 'kn_block');
     if (is_array($datas) && !empty($datas) && array_key_exists('type', $datas) && is_string($datas['type']) && class_exists($datas['type'])) {
         return KLib\instance::addOne($datas['type'], $datas);
     }
     return null;
 }
Esempio n. 2
0
 public static function getByMenuId($menuId, $lang = null)
 {
     if (!is_string($menuId)) {
         throw new Exception('INVALID MENUID', 500);
     }
     if (!array_key_exists(strtoupper($lang), C::g('LIST_LANGUAGE'))) {
         $lang = C::g('LANG_CURRENT');
     }
     $data = KLib\MongoDB::findOne(array('menuId' => $menuId, 'language' => strtoupper($lang)), 'kn_menu');
     if (is_array($data) && !empty($data)) {
         return new Self($data);
     }
     return null;
 }
Esempio n. 3
0
 public static function getByUrl($host, $uri, $lang = null, $published = null)
 {
     //CLEANUP STRING
     $host = substr($host, -1, 1) == '/' ? substr($host, 0, -1) : $host;
     $uri = substr($uri, 0, 1) != '/' ? '/' . $uri : $uri;
     if (!filter_var('http://' . $host . $uri, FILTER_VALIDATE_URL)) {
         return null;
     }
     if (array_key_exists(strtoupper($lang), C::g('LIST_LANGUAGE'))) {
         $lang = strtoupper($lang);
     } else {
         $lang = C::g('DEFAULT_LANG');
     }
     if (!is_bool($published)) {
         $data = KLib\MongoDB::findOne(array('baseUrl' => $host, 'uri' => $uri, 'language' => $lang), 'kn_page');
     } else {
         $data = KLib\MongoDB::findOne(array('baseUrl' => $host, 'uri' => $uri, 'language' => $lang, 'published' => $published), 'kn_page');
     }
     if (is_array($data) && !empty($data)) {
         return new Self($data);
     }
     return null;
 }