This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSeats(percentages) { | |
const totalSeats = 300; // Total number of seats | |
const threshold = 3; // Percentage threshold for proportional allocation | |
const totalVotes = percentages.reduce((sum, percentage) => sum + percentage, 0); | |
const allocatedSeats = []; | |
// Calculate seats for proportional allocation | |
const proportionalSeats = totalSeats - 50; // Remaining seats after allocating 50 for the first party | |
for (let i = 0; i < percentages.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function distributeSeats(percentages, totalSeats, threshold) { | |
const validParties = percentages.filter((percentage) => percentage >= threshold); | |
const totalValidPercentages = validParties.reduce((a, b) => a + b, 0); | |
const seatDistribution = []; | |
validParties.forEach((percentage) => { | |
const seats = Math.floor((percentage / totalValidPercentages) * totalSeats); | |
seatDistribution.push(seats); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If our server has a timezone out of Greece as an example , we can use this function to get the time of that timezone | |
// Supported timezones https://www.php.net/manual/en/timezones.php | |
// Supported time & date formats https://www.php.net/manual/en/datetime.format.php | |
function GetCityTimeDate($format,$timezone) | |
{ | |
$tz = $timezone; | |
$timestamp = time(); | |
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string | |
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getPostOfSpecificDate($date){ | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => -1, | |
'post_status' => 'any', | |
'date_query' => array( | |
array( | |
'year' => $date['year'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function send_email_attachment($to, $subject, $template,$render_object,$attachments) | |
{ | |
$headers = array('Content-Type: text/html; charset=UTF-8', 'From: SiteName <noreply@siteDomain>'); | |
$GLOBALS["use_html_content_type"] = TRUE; | |
ob_start(); | |
require(locate_template($template)); | |
$body = ob_get_contents(); | |
ob_end_clean(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function selectRandom(array) { | |
return array[Math.floor(Math.random() * array.length)]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkAFM(afm) { | |
afm = afm.split("").reverse().join(""); | |
let Num1 = 0; | |
for (var iDigit = 1; iDigit <= 8; iDigit++) { | |
Num1 += afm.charAt(iDigit) << iDigit; | |
} | |
return (Num1 % 11) % 10 == afm.charAt(0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getPostTypeCommentsCount($cpt){ | |
$args = array( | |
'post_type' => $cpt, | |
'posts_per_page' => -1 | |
); | |
$commentCount = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function uploadToAttachmentsFromURL($url) | |
{ | |
$upload_dir = wp_upload_dir(); | |
$image_data = file_get_contents($url); | |
$filename = basename($url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_users_email_by_role($role) | |
{ | |
$args = array( | |
'role' => $role, | |
); | |
$users = get_users($args); | |
$emails = array(); | |
foreach ($users as $user) { |