0, 'name' => '1 Label per page', 'width' => 50, 'height' => 20, 'around' => 0.0000, 'across' => 0.0000, 'marginLeft' => 0.0000, 'marginRight' => 0.0000, 'marginTop' => 0.0000, 'marginBottom' => 0.0000, 'aroundCount' => 1, 'acrossCount' => 1, ); public static function calculateDefaultMarginBySize($size, $units) { $margin = self::DEFAULT_MARGIN_RATIO * $size; return $units === 'mm' ? intval($margin) : round($margin, 4); } public static function calculateSizeByPaperSizeAndMargin($paperSize, $margin, $units) { $size = $paperSize - 2 * $margin; return $units === 'mm' ? intval($size) : round($size, 4); } public function __construct() { global $wpdb; $this->wpdb = $wpdb; $this->tableLabelSheets = Database::$tableLabelSheets; $this->tablePaperFormats = Database::$tablePaperFormats; } public function add($params) { unset($params['id']); $params = array_merge($this->defaultLabelSheetParams, $params); $result = $this->wpdb->insert("{$this->wpdb->prefix}{$this->tableLabelSheets}", $params); return false !== $result ? $this->wpdb->insert_id : false; } public function get($id, $isObject = false) { return $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->prefix}{$this->tableLabelSheets} where id='%d'", $id ), $isObject ? OBJECT : ARRAY_A ); } public function getByPaperIdAndName($paperId, $name) { return $this->wpdb->get_row( $this->wpdb->prepare(" SELECT * FROM {$this->wpdb->prefix}{$this->tableLabelSheets} WHERE `name`='%s' AND `paperId` = '%d' AND `is_removed` = 0 ", $name, $paperId ) ); } public function update($id, $data) { $result = $this->wpdb->update("{$this->wpdb->prefix}{$this->tableLabelSheets}", $data, array('id' => $id)); return false !== $result; } public function delete($id) { $result = $this->wpdb->delete("{$this->wpdb->prefix}{$this->tableLabelSheets}", array('id' => $id), array('%d')); return !empty($result); } public function getAll() { return $this->wpdb->get_results(" SELECT * FROM {$this->wpdb->prefix}{$this->tableLabelSheets} WHERE `is_removed` = 0 ", ARRAY_A); } public function getByPaperId($paperId, $isObject = false) { return $this->wpdb->get_results( $this->wpdb->prepare(" SELECT sf.*, pf.units FROM {$this->wpdb->prefix}{$this->tableLabelSheets} as sf, {$this->wpdb->prefix}{$this->tablePaperFormats} AS pf WHERE pf.id = sf.paperId AND sf.paperId='%d' AND sf.`is_removed` = 0 ", $paperId), $isObject ? OBJECT : ARRAY_A ); } public function getByPaperIdAndLabelId($paperId, $labelId) { return $this->wpdb->get_results( $this->wpdb->prepare(" SELECT sf.*, pf.units FROM {$this->wpdb->prefix}{$this->tableLabelSheets} as sf, {$this->wpdb->prefix}{$this->tablePaperFormats} AS pf WHERE pf.id = sf.paperId AND sf.paperId='%d' AND sf.id='%d' AND sf.`is_removed` = 0 ", $paperId, $labelId), ARRAY_A ); } }