123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- class myUser extends sfBasicSecurityUser {
- /**
- * myUser::getInstance()
- *
- * @return KataoUser
- */
- public function getInstance() {
- return $this->getAttribute('katao_user_instance', null);
- }
- public function setInstance(KataoUser $instance) {
- $this->setAttribute('katao_user_instance', $instance);
- }
- /**
- * myUser::getActivePeriod()
- *
- * @return KataoPeriod
- */
- public function getActivePeriod() {
- return $this->getAttribute('katao_period_instance', KataoPeriodPeer::getActivePeriod());
- }
- public function setActivePeriod(KataoPeriod $instance = null) {
- $this->setAttribute('katao_period_instance', $instance);
- }
- /**
- * myUser::getActiveNode()
- *
- * @return KataoNode
- */
- public function getActiveNode() {
- return $this->getAttribute('katao_node_instance', null);
- }
- public function setActiveNode(KataoNode $instance = null) {
- $this->setAttribute('katao_node_instance', $instance);
- $this->initAvailableProducts();
- }
- /**
- * myUser::getDisplayOnlyActiveProducts()
- *
- * @return boolean
- */
- public function getDisplayOnlyActiveProducts() {
- return $this->getAttribute('katao_display_only_active_products', true);
- }
- public function setDisplayOnlyActiveProducts($value) {
- $this->setAttribute('katao_display_only_active_products', $value);
- $this->initAvailableProducts();
- }
- public function getAvailableProducts() {
- if (-1 == $this->getAttribute('katao_available_products', -1)) {
- $this->initAvailableProducts();
- }
- return $this->getAttribute('katao_available_products', array());
- }
- public function getCartableProducts() {
- return $this->getAttribute('katao_cartable_products', array());
- }
- public function initAvailableProducts() {
- $active_products = array();
- $all_products = array();
- $katao_node_id = $this->getActiveNode()?$this->getActiveNode()->getId():false;
- $katao_period_id = $this->getActivePeriod()?$this->getActivePeriod()->getId():false;
- $display_only_active_products = $this->getDisplayOnlyActiveProducts();
- /* Retrieve all products from complete suppliers */
- $criteria = new Criteria();
- $criteria->addSelectColumn(KataoProductPeer::ID);
- $criteria->addSelectColumn(KataoNodeSupplierPeer::KATAO_PERIOD_ID);
- $criteria->addJoin(KataoProductPeer::KATAO_SUPPLIER_ID, KataoSupplierPeer::ID);
- $criteria->addJoin(KataoSupplierPeer::ID, KataoNodeSupplierPeer::KATAO_SUPPLIER_ID);
- if ($katao_node_id) {
- $criteria->add(KataoNodeSupplierPeer::KATAO_NODE_ID, $katao_node_id);
- }
- $criteria->add(KataoNodeSupplierPeer::INCLUDE_ALL_PRODUCTS, true);
- $rs = KataoProductPeer::doSelectRS($criteria);
- while ($rs->next()) {
- if (!$display_only_active_products) {
- $all_products[$rs->getInt(1)] = true;
- if ($rs->getInt(2) == $katao_period_id) {
- $active_products[$rs->getInt(1)] = true;
- }
- } elseif ($rs->getInt(2) == $katao_period_id) {
- $all_products[$rs->getInt(1)] = true;
- $active_products[$rs->getInt(1)] = true;
- }
- }
- /* Retrieve selected products from incomplete suppliers */
- $criteria = new Criteria();
- $criteria->addSelectColumn(KataoNodeProductPeer::KATAO_PRODUCT_ID);
- $criteria->addSelectColumn(KataoNodeProductPeer::KATAO_PERIOD_ID);
- if ($katao_node_id) {
- $criteria->add(KataoNodeProductPeer::KATAO_NODE_ID, $katao_node_id);
- }
- $rs = KataoNodeProductPeer::doSelectRS($criteria);
- while ($rs->next()) {
- if (!$display_only_active_products) {
- $all_products[$rs->getInt(1)] = true;
- if ($rs->getInt(2) == $katao_period_id) {
- $active_products[$rs->getInt(1)] = true;
- }
- } elseif ($rs->getInt(2) == $katao_period_id) {
- $all_products[$rs->getInt(1)] = true;
- $active_products[$rs->getInt(1)] = true;
- }
- }
- $this->setAttribute('katao_available_products', array_keys($all_products));
- $this->setAttribute('katao_cartable_products', array_keys($active_products));
- }
- }
|