���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /var/www/dev-kft.petruch.de/classes/product.class.php
���ѧ٧ѧ�
<?php class Product{ private $sql = false; public $path = 'files/calibration/'; function __construct() { global $sql; $this->sql = $sql; } /** * Add Product * @param object $p * @return boolean */ public function add($p) { $color = generateLightColor(); return $this->sql->insert('product', 'customerID,name,color,icon,batchSize,exactBatchSize,machinePieceCounter,buttonSmallAmount,buttonBigAmount,sidesAmount,briefing,created,changed', [$p->customerID,$p->name, $color, $p->icon, $p->batchSize, $p->exactBatchSize, $p->machinePieceCounter, $p->buttonSmallAmount, $p->buttonBigAmount, $p->sidesAmount, $p->briefing, NOW, NOW]); } /** * Change Product * @param object $p * @return boolean */ public function change($p) { return $this->sql->update('product', 'customerID,name,color,icon,batchSize,exactBatchSize,machinePieceCounter,buttonSmallAmount,buttonBigAmount,sidesAmount,briefing,changed', [$p->customerID,$p->name, $p->color, $p->icon, $p->batchSize, $p->exactBatchSize, $p->machinePieceCounter, $p->buttonSmallAmount,$p->buttonBigAmount, $p->sidesAmount, $p->briefing, NOW], 'id=?', $p->productID); } /** * Get all Products * @param int $customerID * @return array */ public function getAll($customerID=false,$toolingID=false) { if($toolingID !== false && $customerID) return $this->sql->select('p.id,p.exactBatchSize,p.machinePieceCounter,p.name,p.color,p.icon,p.batchSize,p.buttonSmallAmount,p.buttonBigAmount,p.sidesAmount,p.briefing,p.customerID,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow', 'product p, customer c','p.customerID = ? AND p.id IN (SELECT productID FROM product_tooling WHERE toolingID = ?) AND c.id = p.customerID ORDER BY name ASC',[$customerID,$toolingID]); if($customerID && $toolingID === false) return $this->sql->select('p.id,p.exactBatchSize,p.machinePieceCounter,p.name,p.color,p.icon,p.batchSize,p.buttonSmallAmount,p.buttonBigAmount,p.sidesAmount,p.briefing,p.customerID,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow', 'product p, customer c','p.customerID = ? AND c.id = p.customerID ORDER BY name ASC',[$customerID]); return $this->sql->select('p.id,p.exactBatchSize,p.machinePieceCounter,p.name,p.color,p.icon,p.batchSize,p.buttonSmallAmount,p.buttonBigAmount,p.sidesAmount,p.briefing,p.customerID,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow', 'product p, customer c WHERE c.id = p.customerID ORDER BY name ASC'); } /** * Get Single Product * @param number $productID * @return object */ public function getSingle($productID) { $r = $this->sql->select('p.id,p.name,p.color,p.icon,p.batchSize,p.exactBatchSize,p.machinePieceCounter,p.buttonSmallAmount,p.buttonBigAmount,p.sidesAmount,p.briefing,p.customerID,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow', 'product p, customer c','c.id = p.customerID AND p.id=?',$productID,1); if(!$r) return false; $r->calibrations = $this->getCalibrationsByProduct($productID); $r->todos = $this->getTodoByProduct($productID); return $r; } /** * Get Product Calibration * @param number $productID * @return array */ public function getCalibrationsByProduct($productID) { return $this->sql->select('c.id,c.productID,c.name,c.description,c.optimum,c.deviationNegative,c.deviationPositive,c.decimals,c.image,c.unitID, u.name AS unitName', 'product_calibration c, unit u', 'c.unitID = u.id AND c.productID=?', $productID); } /** * Get single Calibration * @param number $calibrationID * @return object */ public function getCalibration($calibrationID) { return $this->sql->select('c.id,c.productID,c.name,c.description,c.optimum,c.deviationNegative,c.deviationPositive,c.decimals,c.image,c.unitID, u.name AS unitName', 'product_calibration c, unit u', 'c.unitID = u.id AND c.id=?', $calibrationID, 1); } /** * Add Product Calibration * @param object $p * @return boolean */ public function addCalibration($p,$f,$copyImage=false) { $calibrationID = $this->sql->insert('product_calibration', 'productID,name,description,optimum,deviationNegative,deviationPositive,decimals,unitID,created,changed', [$p->productID,$p->name,$p->description,($p->optimum),($p->deviationNegative),($p->deviationPositive),$p->decimals,$p->unitID,NOW,NOW]); if($calibrationID && $f && is_uploaded_file($f->image->tmp_name)){ // Create Dir if not exists if(!is_dir(DIR.$this->path)) mkdir(DIR.$this->path, 0777, true); $imagick = new Imagick($f->image->tmp_name); $imagick->scaleImage(1000, 1000, true); $imagick->setImageFormat("webp"); $imagick->setImageCompressionQuality(90); $imagick->setCompressionQuality(90); $imagick->setOption('webp:method', '6'); $imagick->writeImage(DIR.$this->path.$calibrationID.'.webp'); $image = $this->path.$calibrationID.'.webp'; $r = $this->sql->update('product_calibration','image,imageChanged',[$image,NOW],'id=?',$calibrationID); } if($copyImage){ $r = $this->sql->update('product_calibration','image,imageChanged',[$copyImage,NOW],'id=?',$calibrationID); } return $calibrationID; } /** * Change Product Calibration * @param object $p * @return boolean */ public function changeCalibration($p,$f) { $r = $this->sql->update('product_calibration', 'productID,name,description,optimum,deviationNegative,deviationPositive,decimals,unitID,changed', [$p->productID,$p->name,$p->description,($p->optimum),($p->deviationNegative),($p->deviationPositive),$p->decimals,$p->unitID,NOW], 'id=?', $p->calibrationID); if($r && $f && is_uploaded_file($f->image->tmp_name)){ // Create Dir if not exists if(!is_dir(DIR.$this->path)) mkdir(DIR.$this->path, 0777, true); $imagick = new Imagick($f->image->tmp_name); $imagick->scaleImage(1000, 1000, true); $imagick->setImageFormat("webp"); $imagick->setImageCompressionQuality(90); $imagick->setCompressionQuality(90); $imagick->setOption('webp:method', '6'); $imagick->writeImage(DIR.$this->path.$p->calibrationID.'.webp'); $image = $this->path.$p->calibrationID.'.webp'; $r = $this->sql->update('product_calibration','image,imageChanged',[$image,NOW],'id=?',$p->calibrationID); } return $r; } /** * Delete Product Calibration * @param object $p * @return boolean */ public function deleteCalibration($p) { $r = $this->sql->delete('product_calibration', 'id=? AND productID=?', [$p->calibrationID,$p->productID]); if($r){ // Delete Image if(file_exists(DIR.$this->path.$p->calibrationID.'.webp')) unlink(DIR.$this->path.$p->calibrationID.'.webp'); } return $r; } /** * Get Material for Product */ public function getMaterialByProduct($productID) { return $this->sql->select('id, nameShort, name, amount', 'product_material', 'productID=?', $productID); } /** * Get single Material * @param number $materialID * @return object */ public function getMaterial($materialID) { return $this->sql->select('id, productID, nameShort, name, amount', 'product_material', 'id=?', $materialID, 1); } /** * Add Material To Product * @param object $p * @return boolean */ public function addMaterial($p) { return $this->sql->insert('product_material', 'productID,nameShort, name,amount,created,changed', [$p->productID,$p->nameShort,$p->name,$p->amount,NOW,NOW]); } /** * Change Material To Product * @param object $p * @return boolean */ public function changeMaterial($p) { return $this->sql->update('product_material', 'nameShort,name,amount,changed', [$p->nameShort,$p->name,$p->amount,NOW], 'id=?', $p->materialID); } /** * Delete Material To Product * @param object $p * @return boolean */ public function deleteMaterial($p) { return $this->sql->delete('product_material', 'id=? AND productID=?', [$p->materialID,$p->productID]); } /** Get bad Parts of Product * @param number $productID * @return array */ public function getBadpartByProduct($productID) { return $this->sql->select('id, name, reportingAmount, sort', 'product_badpart', 'productID=? ORDER BY sort DESC', $productID); } /** * Get single Badpart * @param number $badpartID * @return object */ public function getBadpart($badpartID) { return $this->sql->select('id, productID, name, reportingAmount, sort', 'product_badpart', 'id=?', $badpartID, 1); } /** * Add Badpart To Product * @param object $p * @return boolean */ public function addBadpart($p) { return $this->sql->insert('product_badpart', 'productID,name,reportingAmount,sort,created,changed', [$p->productID,$p->name,$p->reportingAmount,$p->sort,NOW,NOW]); } /** * Change Badpart To Product * @param object $p * @return boolean */ public function changeBadpart($p) { return $this->sql->update('product_badpart', 'name,reportingAmount,sort,changed', [$p->name,$p->reportingAmount,$p->sort,NOW], 'id=?', $p->badpartID); } /** * Delete Badpart To Product * @param object $p * @return boolean */ public function deleteBadpart($p) { return $this->sql->delete('product_badpart', 'id=? AND productID=?', [$p->badpartID,$p->productID]); } /** * Get Todo for Product * @param number $productID * @return array */ public function getTodoByProduct($productID) { return $this->sql->select('p.id, p.name, p.description, p.todoMainID, t.name AS todoName, t.color AS todoColor, p.sort', 'product_todo p, todo t', 't.id = p.todoMainID AND p.productID=? ORDER BY p.todoMainID, p.sort ASC', $productID); } /** * Get single Todo * @param number $todoID * @return object */ public function getTodo($todoID) { return $this->sql->select('id, productID, name, description, todoMainID, sort', 'product_todo', 'id=?', $todoID, 1); } /** * Add Todo To Product * @param object $p * @return boolean */ public function addTodo($p) { return $this->sql->insert('product_todo', 'productID,name,description,todoMainID, sort,created,changed', [$p->productID,$p->name,$p->description,$p->todoMainID,$p->sort,NOW,NOW]); } /** * Change Todo To Product * @param object $p * @return boolean */ public function changeTodo($p) { return $this->sql->update('product_todo', 'name,description,todoMainID, sort,changed', [$p->name,$p->description,$p->todoMainID,$p->sort,NOW], 'id=?', $p->todoID); } /** * Delete Todo To Product * @param object $p * @return boolean */ public function deleteTodo($p) { return $this->sql->delete('product_todo', 'id=? AND productID=?', [$p->todoID,$p->productID]); } /** * Get Todos */ public function getTodoAll() { return $this->sql->select('id, name, color', 'todo ORDER BY sort ASC, id ASC'); } /** * Get all Units * @return array */ public function getUnitAll() { return $this->sql->select('id,name', 'unit ORDER BY id ASC'); } /** * Get ToolingIDs of Product * @param number $productID * @return array */ private function getToolingByProduct($productID){ return $this->sql->select('toolingID', 'product_tooling', 'productID=?', $productID); } /** * Add Tooling to Product * @param object $p * @return boolean */ public function addProductTooling($p){ return $this->sql->insert('product_tooling', 'productID,toolingID,created', [$p->productID,$p->toolingID,NOW]); } /** * Delete Tooling from Product * @param object $p * @return boolean */ public function deleteProductTooling($p){ return $this->sql->delete('product_tooling', 'toolingID=? AND productID=?', [$p->toolingID,$p->productID]); } /** * Copy Product * @param number $productID * @return boolean | int */ public function copy($p){ $product = $this->getSingle($p->productID); $new = new stdClass; $new->customerID= $product->customerID; $new->name = $p->name; $new->icon = $product->icon; $new->batchSize = $product->batchSize; $new->exactBatchSize = $product->exactBatchSize; $new->buttonSmallAmount = $product->buttonSmallAmount; $new->buttonBigAmount = $product->buttonBigAmount; $new->sidesAmount = $product->sidesAmount; $new->briefing = $product->briefing; $new->machinePieceCounter = $product->machinePieceCounter; $newID = $this->add($new); if(!$newID) return false; if(isset($p->material)){ $materials = $this->getMaterialByProduct($p->productID); foreach($materials AS $m){ $new = new stdClass; $new->productID = $newID; $new->nameShort = $m->nameShort; $new->name = $m->name; $new->amount = $m->amount; $this->addMaterial($new); } } if(isset($p->badpart)){ $badparts = $this->getBadpartByProduct($p->productID); foreach($badparts AS $b){ $new = new stdClass; $new->productID = $newID; $new->name = $b->name; $new->reportingAmount = $b->reportingAmount; $new->sort = $b->sort; $this->addBadpart($new); } } if(isset($p->calibration)){ $calibrations = $this->getCalibrationsByProduct($p->productID); foreach($calibrations AS $c){ $new = new stdClass; $new->productID = $newID; $new->name = $c->name; $new->description = $c->description; $new->optimum = $c->optimum; $new->deviationNegative = $c->deviationNegative; $new->deviationPositive = $c->deviationPositive; $new->decimals = $c->decimals; $new->unitID = $c->unitID; $new->image = $c->image; $this->addCalibration($new,false,$new->image); } } if(isset($p->todos)){ $todos = $this->getTodoByProduct($p->productID); foreach($todos AS $t){ $new = new stdClass; $new->productID = $newID; $new->name = $t->name; $new->description = $t->description; $new->todoMainID = $t->todoMainID; $new->sort = $t->sort; $this->addTodo($new); } } if(isset($p->tooling)){ $toolings = $this->getToolingByProduct($p->productID); foreach($toolings AS $t){ $new = new stdClass; $new->productID = $newID; $new->toolingID = $t->toolingID; $this->addProductTooling($new); } } return $product->customerID.'/'.$newID; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0.01 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�