255], [['address', 'locality', 'infos_monday', 'infos_tuesday', 'infos_wednesday', 'infos_thursday', 'infos_friday', 'infos_saturday', 'infos_sunday'], 'string'], [['point_production', 'credit', 'delivery_monday', 'delivery_tuesday', 'delivery_wednesday', 'delivery_thursday', 'delivery_friday', 'delivery_saturday', 'delivery_sunday'], 'boolean'], ['point_production', 'default', 'value' => 0], ['id_producer', 'integer'], ['id_producer', 'required'], [['users', 'users_comment', 'code'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'name' => 'Nom', 'address' => 'Adresse', 'locality' => 'Localité', 'point_production' => 'Point de production', 'infos_monday' => 'Lundi', 'infos_tuesday' => 'Mardi', 'infos_wednesday' => 'Mercredi', 'infos_thursday' => 'Jeudi', 'infos_friday' => 'Vendredi', 'infos_saturday' => 'Samedi', 'infos_sunday' => 'Dimanche', 'restricted_access' => 'Accès restreint', 'credit' => 'Activer le Crédit Pain', 'delivery_monday' => 'Lundi', 'delivery_tuesday' => 'Mardi', 'delivery_wednesday' => 'Mercredi', 'delivery_thursday' => 'Jeudi', 'delivery_friday' => 'Vendredi', 'delivery_saturday' => 'Samedi', 'delivery_sunday' => 'Dimanche', 'code' => 'Code', ]; } /* * Relations */ public function getUserPointSale() { return $this->hasMany( UserPointSale::className(), ['id_point_sale' => 'id'] ); } public function getPointSaleDistribution() { return $this->hasMany( PointSaleDistribution::className(), ['id_point_sale' => 'id'] ); } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => [], 'join_with' => [], 'orderby' => '', 'attribute_id_producer' => 'point_sale.id_producer' ] ; } /** * Initialise les commandes liées au point de vente. * * @param array $ordersArray */ public function initOrders($ordersArray) { $this->orders = []; $this->revenues = 0; if($ordersArray) { foreach ($ordersArray as $order) { if ($this->id == $order->id_point_sale) { $this->orders[] = $order; if(is_null($order->date_delete)) { $this->revenues += (float) $order->amount; } } } } } /** * Retourne les commandes liées à ce point de vente. * * @return array */ public function getOrders() { return $this->orders; } /** * Enregistre le point de vente. * * @param boolean $runValidation * @param array $attributeNames * @return type */ public function save($runValidation = true, $attributeNames = NULL) { $this->id_producer = Producer::getId(); return parent::save($runValidation, $attributeNames); } /** * Traite la mise à jour de l'attribut 'point_production'. */ public function processPointProduction() { if ($this->point_production) { PointSale::updateAll( ['point_production' => 0], ['id_producer' => $this->id_producer] ); $this->point_production = 1; $this->save(); } } /** * Traite les accès restreints d'un point de vente. */ public function processRestrictedAccess() { UserPointSale::deleteAll(['id_point_sale' => $this->id]); if (is_array($this->users) && count($this->users)) { foreach ($this->users as $key => $val) { $user = User::findOne($val); if ($user) { $userPointSale = new UserPointSale; $userPointSale->id_user = $val; $userPointSale->id_point_sale = $this->id; if (isset($this->users_comment[$val]) && strlen($this->users_comment[$val])) { $userPointSale->comment = $this->users_comment[$val]; } $userPointSale->save(); } } } } /** * Retourne le commentaire de l'utilisateur courant lié au point de vente. * * @return string|null */ public function getComment() { if (isset($this->userPointSale)) { foreach ($this->userPointSale as $userPointSale) { if ($userPointSale->id_user == User::getCurrentId()) { return $userPointSale->comment; } } } return null ; } /** * Retourne le nombre de points de vente pour l'établissement courant. * * @return integer */ public static function count() { return self::searchCount(['id_producer' => Producer::getId()]) ; } /** * Vérifie le code d'accès à un point de vente. * * @param string $code * @return boolean */ public function validateCode($code) { if (strlen($this->code)) { if (trim(strtolower($code)) == trim(strtolower($this->code))) { return true; } else { return false; } } return true; } /** * Retourne les jours de livraison du point de vente sous forme d'une chaine * de caractères. * * @return string */ public function getStrDeliveryDays() { $str = '' ; if($this->delivery_monday) $str .= 'lundi, ' ; if($this->delivery_tuesday) $str .= 'mardi, ' ; if($this->delivery_wednesday) $str .= 'mercredi, ' ; if($this->delivery_thursday) $str .= 'jeudi, ' ; if($this->delivery_friday) $str .= 'vendredi, ' ; if($this->delivery_saturday) $str .= 'samedi, ' ; if($this->delivery_sunday) $str .= 'dimanche, ' ; if(strlen($str)) { return substr($str, 0, strlen($str)-2) ; } else { return '' ; } } /** * Retourne un commentaire informant l'utilisateur sur les détails de * livraison d'un point de vente et pour un jour donné. * * @param string $jour * @return string */ public function getStrInfos($day) { $str = '' ; $field = 'infos_'.$day ; if(strlen($this->$field)) { $str = nl2br(Html::encode($this->$field)) ; $str = preg_replace('/\[select_previous_day\](.*?)\[\/select_previous_day\]/', '$1' , $str) ; } return $str ; } }