public function setFromPost($values, $contenttype) { $values = Input::cleanPostedData($values); if (!$this->id) { // this is a new record: current user becomes the owner. $user = $this->app['users']->getCurrentUser(); $this['ownerid'] = $user['id']; } // If the owner is set explicitly, check if the current user is allowed // to do this. if (isset($values['ownerid'])) { if ($this['ownerid'] != $values['ownerid']) { if (!$this->app['users']->isAllowed("contenttype:{$contenttype['slug']}:change-ownership:{$this->id}")) { throw new \Exception('Changing ownership is not allowed.'); } $this['ownerid'] = intval($values['ownerid']); } } // Make sure we have a proper status. if (!in_array($values['status'], ['published', 'timed', 'held', 'draft'])) { if ($this['status']) { $values['status'] = $this['status']; } else { $values['status'] = 'draft'; } } // Make sure we only get the current taxonomies, not those that were fetched from the DB. $this->taxonomy = []; if (!empty($values['taxonomy'])) { foreach ($values['taxonomy'] as $taxonomytype => $value) { if (isset($values['taxonomy-order'][$taxonomytype])) { foreach ($value as $k => $v) { $value[$k] = $v . '#' . $values['taxonomy-order'][$taxonomytype]; } } $this->taxonomy[$taxonomytype] = $value; } unset($values['taxonomy']); unset($values['taxonomy-order']); } // Get the relations from the POST-ed values. if (!empty($values['relation']) && is_array($values['relation'])) { foreach ($values['relation'] as $key => $relationValues) { $this->clearRelation($key); foreach ($relationValues as $value) { $this->setRelation($key, $value); } } unset($values['relation']); } else { $this->relation = []; } $this->setValues($values); }