KataoNode.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class KataoNode extends BaseKataoNode {
  3. const ID_LAFRANCAISE = 2;
  4. const ID_MONTAUBAN = 3;
  5. public function __toString() {
  6. return $this->getCity();
  7. }
  8. public function getResponsibleLink($with_link = false) {
  9. $result = '';
  10. if (null != $katao_user = $this->getKataoUser()) {
  11. if (null != $katao_member = $katao_user->getKataoMember()) {
  12. if ($with_link) {
  13. $result = link_to($katao_member->getFullName(), '@katao_member_show?id=' . $katao_member->getId());
  14. } else {
  15. $result = $katao_member->getFullName();
  16. }
  17. }
  18. }
  19. return $result;
  20. }
  21. public function updateAvailableProducts($katao_period_id, $serialized_suppliers_data = '', $product_ids = array()) {
  22. $criteria = new Criteria();
  23. $criteria->add(KataoNodeSupplierPeer::KATAO_NODE_ID, $this->getId());
  24. $criteria->add(KataoNodeSupplierPeer::KATAO_PERIOD_ID, $katao_period_id);
  25. KataoNodeSupplierPeer::doDelete($criteria);
  26. $suppliers_data = Utils::parseOrderedData($serialized_suppliers_data);
  27. if (!empty($suppliers_data['middle_col'])) {
  28. foreach ($suppliers_data['middle_col'] as $supplier_id) {
  29. $katao_node_supplier = new KataoNodeSupplier();
  30. $katao_node_supplier->setKataoNode($this);
  31. $katao_node_supplier->setKataoPeriodId($katao_period_id);
  32. $katao_node_supplier->setKataoSupplierId(Utils::sanitizeSupplierId($supplier_id));
  33. $katao_node_supplier->setIncludeAllProducts(true);
  34. $katao_node_supplier->save();
  35. }
  36. }
  37. if (!empty($suppliers_data['right_col'])) {
  38. foreach ($suppliers_data['right_col'] as $supplier_id) {
  39. $katao_node_supplier = new KataoNodeSupplier();
  40. $katao_node_supplier->setKataoNode($this);
  41. $katao_node_supplier->setKataoPeriodId($katao_period_id);
  42. $katao_node_supplier->setKataoSupplierId(Utils::sanitizeSupplierId($supplier_id));
  43. $katao_node_supplier->setIncludeAllProducts(false);
  44. $katao_node_supplier->save();
  45. }
  46. }
  47. $criteria = new Criteria();
  48. $criteria->add(KataoNodeProductPeer::KATAO_NODE_ID, $this->getId());
  49. $criteria->add(KataoNodeProductPeer::KATAO_PERIOD_ID, $katao_period_id);
  50. KataoNodeProductPeer::doDelete($criteria);
  51. if (0 < count($product_ids)) {
  52. foreach ($product_ids as $product_id) {
  53. $katao_node_product = new KataoNodeProduct();
  54. $katao_node_product->setKataoNode($this);
  55. $katao_node_product->setKataoPeriodId($katao_period_id);
  56. $katao_node_product->setKataoProductId((int)$product_id);
  57. $katao_node_product->save();
  58. }
  59. }
  60. }
  61. public function getBeginAtStr() {
  62. return CatalyzDate::formatShort($this->getBeginAt(null));
  63. }
  64. public function isDeletable() {
  65. return (0 == $this->countKataoCarts()) && (0 == $this->countKataoOrders()) && (0 == $this->countKataoInvoices()) && (0 == $this->countKataoMembersRelatedByKataoNodeId()) && (0 == $this->countKataoMembersRelatedByNextKataoNodeId());
  66. }
  67. }