Skip to content

Commit

Permalink
Fix progress bar and duplicate issue button
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Jul 31, 2023
1 parent b408acc commit c43e34f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
23 changes: 7 additions & 16 deletions classes/newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function get_instance(): object {
/**
* Get subscription id of user if $userid = 0 id of current user is returned
*
* @param int userid
* @param int $userid
* @return int|boolean subscriptionid | false if no subscription is found
*/
public function get_subid(int $userid = 0) {
Expand Down Expand Up @@ -274,19 +274,6 @@ public function get_config(): object {
return $this->config;
}

/**
* get all subscribed users for a newsletter instance
*
* @return array of objects with subscription id as key
*/
public function get_subscriptions(): array {
global $DB;
return $DB->get_records(
'newsletter_subscriptions',
array('id' => $this->get_instance()->id)
);
}

/**
* Reset user data
*
Expand Down Expand Up @@ -1137,7 +1124,7 @@ private function view_manage_subscriptions(array $params) {
* @return int
* @throws \dml_exception
*/
public static function get_delivered_issues($userid) {
public static function get_delivered_issues($userid): int {
global $DB;
$delivered = $DB->count_records('newsletter_deliveries', array('userid' => $userid));
return $delivered;
Expand Down Expand Up @@ -1288,6 +1275,10 @@ private function prepare_issue_list($heading, $groupby) {
$dateformat = get_string("week") . " %W/%Y";
$datefromto = "%d. %B %Y";
break;
default:
$from = strtotime("first day of this month", $firstissue->publishon);
$to = strtotime("next month", $from);
$dateformat = "%B %Y";
}

$sectionlist = new \newsletter_section_list($heading);
Expand Down Expand Up @@ -1335,7 +1326,7 @@ private function prepare_issue_list($heading, $groupby) {
if (!($issue->publishon > time() && !$editissue)) { // Do not display issues that
// are not yet published.
$currentissuelist->add_issue_summary(
new \newsletter_issue_summary($issue, $editissue, $deleteissue)
new \newsletter_issue_summary($issue, $editissue, $deleteissue, $duplicateissue)
);
}
} // End if issue in timeslot.
Expand Down
14 changes: 8 additions & 6 deletions renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ public function __construct(stdClass $issue) {
}
}

/**
*
*/
class newsletter_issue_summary extends newsletter_issue {
public $editissue;
public $deleteissue;
public $duplicateissue;


public function __construct(stdClass $issue, $editissue = false, $deleteissue = false, $duplicateissue = false) {
parent::__construct($issue);
$this->editissue = $editissue;
Expand All @@ -138,9 +140,9 @@ public function __construct(stdClass $issue, $editissue = false, $deleteissue =
}

class newsletter_subscription_list implements renderable {
public $cmid;
public $subscriptions;
public $columns;
public int $cmid;
public array $subscriptions;
public array $columns;
public function __construct($cmid, array $subscriptions, array $columns) {
$this->cmid = $cmid;
$this->subscriptions = $subscriptions;
Expand All @@ -166,8 +168,8 @@ public function add_issue_summary(newsletter_issue_summary $issue) {

class newsletter_section_list implements renderable {

public $heading = '';
public $sections = array();
public string $heading = '';
public array $sections = array();

/**
* Constructor
Expand Down
9 changes: 2 additions & 7 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ public function render_newsletter_issue_summary(newsletter_issue_summary $issue)
$output .= $this->render(
new newsletter_progressbar($issue->numnotyetdelivered, $issue->numdelivered));
}

if ($issue->duplicateissue) {
$output .= $this->render(
new newsletter_progressbar($issue->numnotyetdelivered, $issue->numdelivered));
}
} else {
$output .= $this->render(new newsletter_publish_countdown($now, $issue->publishon));
}
Expand Down Expand Up @@ -364,8 +359,8 @@ public function render_newsletter_progressbar(newsletter_progressbar $progressba
}

$output .= html_writer::start_tag('div', array('class' => 'progress'));
$output .= html_writer::div($completed, '',
array('class' => 'progress-bar', 'role' => 'progressbar',
$output .= html_writer::div($completed, 'progress-bar',
array('role' => 'progressbar',
'aria-valuenow' => $value, 'aria-valuemin' => '0', 'aria-valuemax' => '100',
'style' => 'width:' . $value . '%'));
$output .= html_writer::end_tag('div');
Expand Down

0 comments on commit c43e34f

Please sign in to comment.