Example #1
0
 public function validate()
 {
     if (empty($this->title)) {
         $this->setError('Title is required');
     }
     return parent::validate();
 }
Example #2
0
 protected function beforeSave()
 {
     // if all the items are fulfilled, the order is fulfilled
     if ($this->status == \Shop\Constants\OrderStatus::open && $this->fulfillment_status != \Shop\Constants\OrderFulfillmentStatus::fulfilled) {
         $all_fulfilled = true;
         foreach ($this->items as $item) {
             if (\Dsc\ArrayHelper::get($item, 'fulfillment_status') != \Shop\Constants\OrderFulfillmentStatus::fulfilled) {
                 $all_fulfilled = false;
             }
         }
     }
     if (empty($this->source)) {
         $this->source = array('id' => 'shop', 'title' => 'Online');
     }
     return parent::beforeSave();
 }
Example #3
0
 protected function beforeSave()
 {
     $googleProfilePhoto = $this->{'social.google.profile.photoURL'};
     if (strlen($googleProfilePhoto) && strpos($googleProfilePhoto, 'sz=50') !== false) {
         $this->{'social.google.profile.photoURL'} = str_replace('sz=50', '', $googleProfilePhoto);
     }
     if (!empty($this->__groups)) {
         if (is_string($this->__groups)) {
             $this->__groups = \Base::instance()->split($this->__groups);
         }
         $groups = array();
         foreach ($this->__groups as $key => $id) {
             $item = (new \Users\Models\Groups())->setState('filter.id', $id)->getItem();
             $groups[] = array("id" => $item->id, "title" => $item->title, "slug" => $item->slug);
         }
         $this->groups = $groups;
     }
     if (isset($this->__groups) && empty($this->__groups)) {
         $this->groups = array();
     }
     // ensure that groups are unique
     if (!empty($this->groups)) {
         $groups = array();
         foreach ($this->groups as $key => $id) {
             if (is_array($id)) {
                 if (!empty($id['id'])) {
                     $group_id = $id['id'];
                     if (!array_key_exists((string) $group_id, $groups)) {
                         $groups[(string) $group_id] = $id;
                     }
                 }
             } elseif (is_string($id)) {
                 if (!array_key_exists((string) $id, $groups)) {
                     $item = (new \Users\Models\Groups())->setState('filter.id', $id)->getItem();
                     if (!empty($item->id)) {
                         $groups[(string) $item->id] = array("id" => $item->id, "title" => $item->title, "slug" => $item->slug);
                     }
                 }
             }
         }
         $this->groups = array_values($groups);
     }
     if (!empty($this->admin_tags) && !is_array($this->admin_tags)) {
         $this->admin_tags = trim($this->admin_tags);
         if (!empty($this->admin_tags)) {
             $this->admin_tags = array_map(function ($el) {
                 return strtolower($el);
             }, \Base::instance()->split((string) $this->admin_tags));
         }
     } elseif (empty($this->admin_tags) && !is_array($this->admin_tags)) {
         $this->admin_tags = array();
     }
     return parent::beforeSave();
 }