Δευτέρα 22 Οκτωβρίου 2018

Διαχείριση προσωπικών δεδομένων & επικοινωνιών.

Όλοι δεχόμαστε άπειρα τηλεφωνήματα για προώθηση προϊοντων και προσφορές του παρόχου μας ή ανταγωνιστών. Αυτό όμως γινόταν ασύστολα μέχρι που εμφανίστηκε το GDPR.

Το GDPR είναι ο φόβος και ο τρόμος των προωθήσεων καθώς πρέπει να έχουν την ενεργητική συνένεση του καταναλωτή ώστε να μπορούν να του προωθούν προϊόντα. Αυτός ο ευρωπαϊκός κανονισμός ανάγκασε όλες τις μεγάλες εταιρείες να δώσουν την δυνατότητα στους πελάτες να επιλέγουν αν και ποιες ενέργειες "παρακολούθησης" και "επικοινωνίας" επιτρέπονται.

Μια πάρα πολύ ωραία υλοποίηση, είναι αυτή που έχει γίνει στην εφαρμογή του Vodafone CU. Πραγματικά με ενθουσίασε το πόσο αναλυτικά έχουν τις επιλογές, αλλά και ότι σου βγάζει ένα τίμιο μήνυμα ότι μπορεί να χρειαστούν 24 ώρες για να ενεργοποιηθούν οι ρυθμίσεις.

Long Story Short:
  1. Εχεις Vodafone CU?
  2. Σε ενοχλούν με διαφημίσεις;
  3. Κατέβασε την εφαρμογή (Google Play, Apple App Store
  4. Ανοιξε την
  5. Συνδεσου
  6. Πηγαινε Μενου > Ρυθμίσεις > Διαχείριση προσωπικών δεδομένων & επικοινωνιών
  7. Επέλεξε τι θέλεις και αποθήκευσε τις ρυθμίσεις σου


Σημειωση: Το έκανα σήμερα, οποτε τις επόμενες ημέρες θα δω αν θα με ενοχλήσουν ή οχι! Ελπίζω να μην με ενοχλήσουν και να επιβεβαιώσει η Vodafone ότι ειναι σοβαρη εταιρεια που σέβεται τον καταναλωτη!

Τετάρτη 11 Ιουλίου 2018

[Laravel Hack] venturecraft/revisionable to include details

As a backend development, you might have been asked to keep a history of changes. A very good library that does so in Laravel, with minimum configuration, is the venturecraft/revisionable. A limitation of this library is that it is limited to whatever is stored in the table that is related to each model. 

There are several situations that this is not enough. For instance, you might have a Model "PriceTable" that is related to many "ServiceTypePrice" where "ServiceTypePrice" is stored in a separate table and they have a One-to-Many relationship.

My simplest solution was to convert define the relationship in the model class using "hasMany" and also create a function that converts the data of hasMany into a readable string. So I override method preSave that Revisionable uses, in order to include the result of getDetails() as if it is was a actual attribute of the table "PriceTable".

It should be noted that I have decided this solution since I have pretty small number of entries in the table "ServieTypePrice" for each "PriceTable", otherwise I would select a more sophisticated solution that I have already though of but I might test and document in a future post!

preSave code included in my "PriceTable" Model class is the following:
 
use \Venturecraft\Revisionable\RevisionableTrait; 
public function preSave() {
        if (!isset($this->revisionEnabled) || $this->revisionEnabled) {
            // if there's no revisionEnabled. Or if there is, if it's true
            $this->originalData = $this->original;
            $this->updatedData = $this->attributes;

            /**
             * Append details
             */
            if ($this->originalData) {
                $originalModel = static::find($this->originalData["id"]);
                $this->originalData["details"] = $originalModel->getDetails();
            }
            $this->updatedData["details"] = $this->getDetails();

            // we can only safely compare basic items,
            // so for now we drop any object based items, like DateTime
            foreach ($this->updatedData as $key => $val) {
                if (gettype($val) == 'object' && !method_exists($val, '__toString')) {
                    unset($this->originalData[$key]);
                    unset($this->updatedData[$key]);
                    array_push($this->dontKeep, $key);
                }
            }
            // the below is ugly, for sure, but it's required so we can save the standard model
            // then use the keep / dontkeep values for later, in the isRevisionable method
            $this->dontKeep = isset($this->dontKeepRevisionOf) ?
                array_merge($this->dontKeepRevisionOf, $this->dontKeep) : $this->dontKeep;
            $this->doKeep = isset($this->keepRevisionOf) ?
                array_merge($this->keepRevisionOf, $this->doKeep) : $this->doKeep;
            unset($this->attributes['dontKeepRevisionOf']);
            unset($this->attributes['keepRevisionOf']);
            $this->dirtyData = $this->getDirty();
            /**
             * Check Details
             */
            if ($this->originalData == NULL || strcmp((string) $this->updatedData["details"], (string) $this->originalData["details"]) !== 0) {
                $this->dirtyData["details"] = $this->updatedData["details"];
            }
            $this->updating = $this->exists;
        }
    }

LinkWithin

Blog Widget by LinkWithin

Mobile edition