'Distribution', 'id_point_sale' => 'Point de vente', 'delivery' => 'Livraison', ]; } /* * Relations */ public function getDistribution() { return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']); } public function getPointSale() { return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']); } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => ['distribution', 'pointSale'], 'join_with' => [], 'orderby' => '', 'attribute_id_producer' => '' ] ; } /** * Définit les jours de livraisons des points de vente pour un jour de * production donné. * * @param integer $id_production * @param boolean $bool_livraison */ public static function setAll($idDistribution, $boolDelivery) { $countPointSaleDistribution = self::searchCount([ 'id_distribution' => $idDistribution ]) ; if (!$countPointSaleDistribution) { $arrPointsSale = PointSale::searchAll() ; foreach ($arrPointsSale as $pointSale) { $pointSaleDistribution = new PointSaleDistribution(); $pointSaleDistribution->id_distribution = $idDistribution; $pointSaleDistribution->id_point_sale = $pointSale->id; $pointSaleDistribution->save(); } } $distribution = Distribution::findOne($idDistribution); if ($distribution) { $day = date('N', strtotime($distribution->date)); $arrPointsSaleDistribution = self::searchAll([ 'id_distribution' => $idDistribution ]) ; foreach ($arrPointsSaleDistribution as $pointSaleDistribution) { if ($boolDelivery && (($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) || ($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) || ($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) || ($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) || ($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) || ($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) || ($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday) || $pointSaleDistribution->pointSale->point_production )) { $pointSaleDistribution->delivery = 1; } else { $pointSaleDistribution->delivery = 0; } $pointSaleDistribution->save(); } } } }