public function all() { $blocks = array_values(KLib\MongoDB::find(array(), 'kn_block', 'array', array('label' => true, 'language' => true, 'key' => true))); $blocks = array_map(function ($i) { return array('id' => (string) $i['_id'], 'key' => $i['key'], 'label' => $i['label'], 'language' => $i['language'], 'labelFull' => $i['language'] . ' - ' . $i['label']); }, $blocks); return $blocks; }
public static function allMenus() { $datas = KLib\MongoDB::find(array(), 'kn_menu', 'cursor'); if (!is_a($datas, 'MongoCursor') || $datas->count() <= 0) { return array(); } return KLib\instance::massAdd('Menu', $datas); }
public function languageMenuParent() { $ret = array(); $pageParent = KLib\MongoDB::find(array('languageParentId' => null), 'kn_menu', 'cursor', array('_id' => true, 'label' => true, 'language' => true)); if (is_a($pageParent, 'MongoCursor') && $pageParent->count() > 0) { foreach ($pageParent as $k => $page) { $ret[] = array('key' => (string) $k, 'value' => $page['language'] . ' ' . $page['label']); } } return $ret; }
public static function getByPageId($pageId) { if (!MongoId::isValid($pageId)) { throw new Exception('INVALID PAGEID', 500); } $datas = KLib\MongoDB::find(array('items.pageId' => (string) $pageId), 'menu', 'cursor'); if (is_a($datas, 'MongoCursor') && $datas->count() > 0) { return KLib\instance::massAdd('Menu', $datas); } return array(); }
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; }
public static function allPages($published = null) { $query = array(); if (is_bool($published)) { $query['published'] = $published; } $pages = KLib\MongoDB::find($query, 'kn_page', 'cursor'); if (is_a($pages, 'MongoCursor') && $pages->count() > 0) { return KLib\instance::massAdd('Page', $pages); } return array(); }
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; }
public function getLanguageChildren() { $main = $this->getLanguageParent(); if (!is_a($main, 'Page') && is_null($this->languageParentId)) { $main = $this; } elseif (!is_a($main, 'Page')) { throw new Exception('INVALID LANGUAGEPARENTID', 500); } $datas = KLib\MongoDB::find(array('languageParentId' => $this->id), 'kn_page', 'cursor'); return KLib\instance::massAdd('Page', $datas); }