TemKa_SD Posted October 24, 2018 Share Posted October 24, 2018 Здравствуйте. У меня есть готовый модуль, мне нужно реализовать в нем выборку по месяцам или другим данным. Сначала по месяцам нужно сделать. Подскажите пожалуйста, с чего начать?toplist.php Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 24, 2018 Author Share Posted October 24, 2018 Сделал основу фильтра, он тоже нужен будет потом: http://prntscr.com/la0racКак лучше выборку по дате делать? Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 24, 2018 Author Share Posted October 24, 2018 http://prntscr.com/la0xgi такое бы сделать, вообще супер. Link to comment Share on other sites More sharing options...
newbie Posted October 25, 2018 Share Posted October 25, 2018 http://prntscr.com/la0xgi такое бы сделать, вообще супер. Так откройте файл и посмотрите, как реализовано Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 25, 2018 Author Share Posted October 25, 2018 Так и сделал, я не могу вывести нужны мне переменные с $table. Сейчас в шаблон данные выводятся тегами: $table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('tables', 'sharedstats', 'front'), 'games' ); \IPS\Output::i()->output = (string) $table; Куда мне вставить переменную $dates? Link to comment Share on other sites More sharing options...
newbie Posted October 25, 2018 Share Posted October 25, 2018 Создайте новый шаблон и в него добавьте\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('tables', 'sharedstats', 'front')->someTemplate($table, $dates); Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 28, 2018 Author Share Posted October 28, 2018 Ничего не получилось. Не отображается информация из нового шаблона. Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 1, 2018 Author Share Posted November 1, 2018 У меня получилось, вроде работает )) Кому надо будет: /* Figure out dates */ $dates = array(); $timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone ); $endDate = \IPS\DateTime::ts( time() )->setTimezone( $timezone ); $firstRepDate = \IPS\DB::i('stats')->select( 'MIN(UNIX_TIMESTAMP(datetime))', 'stats_games' )->first(); $firstIndexDate = \IPS\Content\Search\Index::i()->firstIndexDate(); $dates[ 'oldest' ] = \IPS\DateTime::ts( ( $firstRepDate > $firstIndexDate ) ? $firstRepDate : $firstIndexDate ); $oldestStamp = $dates[ 'oldest' ]->getTimeStamp(); $date = $dates[ 'oldest' ]; $aYearAgo = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P1Y' ) ); $month = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P1M' ) )->setTime( 0, 0 ); $week = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P7D' ) )->setTime( 0, 0 ); $today = \IPS\DateTime::create()->setTimezone( $timezone )->setTime( 0, 0 ); if ( $aYearAgo->getTimeStamp() > $oldestStamp ) { $dates[ 'year' ] = $aYearAgo; } if ( $month->getTimeStamp() > $oldestStamp ) { $dates[ 'month' ] = $month; } if ( $week->getTimeStamp() > $oldestStamp ) { $dates[ 'week' ] = $week; } if ( $today->getTimeStamp() > $oldestStamp ) { $dates[ 'today' ] = $today; } /* Got a date? */ if ( isset( \IPS\Request::i()->time ) and isset( $dates[ \IPS\Request::i()->time ] ) ) { $date = $dates[ \IPS\Request::i()->time ]; } else if ( isset( $dates[ 'month' ] ) ) { /* Set the default to month */ \IPS\Request::i()->time = 'month'; $date = $dates[ 'month' ]; } $form = new \IPS\Helpers\Form( 'popular_date', 'continue' ); $form->class = 'ipsForm_vertical'; $customStart = isset( \IPS\Request::i()->custom_date_start ) ? \IPS\Request::i()->custom_date_start : NULL; $customEnd = isset( \IPS\Request::i()->custom_date_end ) ? \IPS\Request::i()->custom_date_end : NULL; $form->add( new \IPS\Helpers\Form\DateRange( 'custom_date', array( 'start' => $customStart, 'end' => $customEnd ), FALSE, array( 'start' => array( 'min' => $dates[ 'oldest' ], 'time' => false ) ) ) ); if ( $values = $form->values() ) { $url = \IPS\Request::i()->url()->stripQueryString( 'time' ); if ( isset( $values[ 'custom_date' ][ 'start' ] ) and $values[ 'custom_date' ][ 'start' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_start', $values[ 'custom_date' ][ 'start' ]->getTimeStamp() ); } if ( isset( $values[ 'custom_date' ][ 'end' ] ) and $values[ 'custom_date' ][ 'end' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_end', $values[ 'custom_date' ][ 'end' ]->getTimeStamp() ); } \IPS\Output::i()->redirect( $url ); } else { if ( $customStart ) { $date = \IPS\DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 ); } if ( $customEnd ) { $endDate = \IPS\DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 ); } } /* Get top rated contributors */ $topContributors = array(); $innerQueryWhere[] = array( 'id>0 and UNIX_TIMESTAMP(datetime) BETWEEN ' . intval( $date->getTimeStamp() ) . ' AND ' . intval( $endDate->getTimeStamp() ) ); foreach( \IPS\Db::i('stats')->select( '*', 'stats_games', $innerQueryWhere, 'id DESC', 4 ) as $member ) { $topContributors[] = $member; } /* Display */ \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->games( $topContributors, $dates, $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) ) ); Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 @newbie помогите плиз с пагинацией. Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 @newbie помогите плиз с пагинацией. Link to comment Share on other sites More sharing options...
newbie Posted November 2, 2018 Share Posted November 2, 2018 @newbie помогите плиз с пагинацией. foreach( \IPS\Db::i('stats')->select( '*', 'stats_games', $innerQueryWhere, 'id DESC', 4 ) as $member ) { $topContributors[] = $member; }заменить на $page = isset(\IPS\Request::i()->page) ? intval(\IPS\Request::i()->page) : 1; if ($page < 1) { $page = 1; } $perPage = 4; $select = \IPS\Db::i('stats')->select('*', 'stats_games', $innerQueryWhere, 'id DESC', array(($page - 1) * $perPage, $perPage), null, null, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS); foreach ($select as $member) { $topContributors[] = $member; } $pagination = \IPS\Theme::i()->getTemplate('global', 'core', 'global')->pagination($url, ceil($select->count(true) / $perPage), $page, $perPage); Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 Спасибо, я уже нашел в другом модуле и реализовал, только есть баги: http://prntscr.com/ldfxnn какой код по лучше будет? Баг в том, что когда идешь по страницам, зачем выбираешь дату, нажимаешь опять на пагинацию - всё сбрасывается. Но это тут я понимаю: if ( $values = $form->values() ) { } else { if ( $customStart ) { $date = \IPS\DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 ); } if ( $customEnd ) { $endDate = \IPS\DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 ); } } щас буду копать. Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 Что скажете? До: if ( $values = $form->values() ) { $url = \IPS\Request::i()->url()->stripQueryString( 'time' ); if ( isset( $values[ 'custom_date' ][ 'start' ] ) and $values[ 'custom_date' ][ 'start' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_start', $values[ 'custom_date' ][ 'start' ]->getTimeStamp() ); } if ( isset( $values[ 'custom_date' ][ 'end' ] ) and $values[ 'custom_date' ][ 'end' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_end', $values[ 'custom_date' ][ 'end' ]->getTimeStamp() ); } \IPS\Output::i()->redirect( $url ); } else { if ( $customStart ) { $date = \IPS\DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 ); } if ( $customEnd ) { $endDate = \IPS\DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 ); } } $page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1; if( $page < 1 ) { $page = 1; } После: $page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1; if( $page < 1 ) { $page = 1; } if ( $values = $form->values() ) { $url = \IPS\Request::i()->url()->stripQueryString( 'time' ); if ( isset( $values[ 'custom_date' ][ 'start' ] ) and $values[ 'custom_date' ][ 'start' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_start', $values[ 'custom_date' ][ 'start' ]->getTimeStamp() ); } if ( isset( $values[ 'custom_date' ][ 'end' ] ) and $values[ 'custom_date' ][ 'end' ] instanceof \IPS\DateTime ) { $url = $url->setQueryString( 'custom_date_end', $values[ 'custom_date' ][ 'end' ]->getTimeStamp() ); } \IPS\Output::i()->redirect( $url ); } else { $url = \IPS\Request::i()->url()->stripQueryString( 'page', $page ); if ( $customStart ) { $date = \IPS\DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 ); } if ( $customEnd ) { $endDate = \IPS\DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 ); } } Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 Да вроде всё супер, единственное, когда идешь по пагинации, затем выбираешь дату -> url такой: controller=games&page=3&time=week Затем нажимаешь на пагинацию, url такой: controller=games&time=week&page=4 Местами меняется, как это пофиксить? не могу найти ( Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 2, 2018 Author Share Posted November 2, 2018 Еще бы AJAX подрубить сюда, и в принципе готово. Сегодня буду еще категории добавлять в фильтр. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now