Esempio n. 1
0
 private static function get_next_position($block)
 {
     $column = 'MAX(position) + 1 AS newPosition';
     $condition = 'WHERE block=:block AND enabled=1';
     $parameters = array('block' => $block);
     return (int) self::$querier->get_column_value(DB_TABLE_MENUS, $column, $condition, $parameters);
 }
 /**
  * {@inheritDoc}
  */
 public function authenticate()
 {
     $data = $this->get_fb_user_data();
     $fb_id = $data['id'];
     try {
         $condition = 'WHERE method=:method AND identifier=:identifier';
         $parameters = array('method' => self::AUTHENTICATION_METHOD, 'identifier' => $fb_id);
         return $this->querier->get_column_value(DB_TABLE_AUTHENTICATION_METHOD, 'user_id', $condition, $parameters);
     } catch (RowNotFoundException $e) {
         $email_exists = $this->querier->row_exists(DB_TABLE_MEMBER, 'WHERE email=:email', array('email' => $data['email']));
         if ($email_exists) {
             $this->error_msg = LangLoader::get_message('external-auth.account-exists', 'user-common');
         } else {
             $user = new User();
             $user->set_display_name(utf8_decode($data['name']));
             $user->set_level(User::MEMBER_LEVEL);
             $user->set_email($data['email']);
             $auth_method = new FacebookAuthenticationMethod();
             $fields_data = array('user_avatar' => 'https://graph.facebook.com/' . $fb_id . '/picture');
             return UserService::create($user, $auth_method, $fields_data);
         }
     }
 }
 private function delete_old_menus()
 {
     $menus_folder = new Folder(Url::to_rel('/menus'));
     if ($menus_folder->exists()) {
         foreach ($menus_folder->get_folders() as $menu) {
             $menu_id = 0;
             try {
                 $menu_id = self::$db_querier->get_column_value(DB_TABLE_MENUS, 'id', 'WHERE title LIKE :title', array('title' => $menu->get_name() . '%'));
             } catch (RowNotFoundException $e) {
             }
             if (!empty($menu_id)) {
                 self::$db_querier->delete(DB_TABLE_MENUS, 'WHERE id = :id', array('id' => $menu_id));
                 $this->add_information_to_file('menu ' . $menu->get_name(), 'has been uninstalled because : incompatible with new version');
             }
         }
     }
 }
 /**
  * @desc Update category and items position.
  * @param Category $category
  * @param int $id_parent
  * @param int $position
  */
 public function update_position(Category $category, $id_parent, $position)
 {
     $id = $category->get_id();
     if ($this->get_categories_cache()->category_exists($id) && $this->get_categories_cache()->category_exists($id_parent) && !($category->get_id_parent() == $id_parent && $category->get_order() == $position)) {
         $options = new SearchCategoryChildrensOptions();
         $childrens = $this->get_childrens($id, $options);
         $childrens[$id] = $category;
         if (!array_key_exists($id_parent, $childrens)) {
             $max_order = $this->db_querier->get_column_value($this->table_name, 'MAX(c_order)', 'WHERE id_parent=:id_parent', array('id_parent' => $id_parent));
             $max_order = NumberHelper::numeric($max_order);
             if ($position <= 0 || $position > $max_order) {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $max_order + 1), 'WHERE id=:id', array('id' => $id));
             } else {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $position), 'WHERE id=:id', array('id' => $id));
             }
             $this->regenerate_cache();
         }
     }
 }