/** * @param Set $linkedSet * @returns $this */ public function link(Set $linkedSet) { $bean = $this->getBean(); if ($bean === null) { $bean = $this->newBean(); } $bean->{$this->_('linkedSetId')} = $linkedSet->getBean()->getID(); R::store($bean); return $this; }
public function addTo(Set $set) { $setBean = $set->getBean(); $recordBean = $this->newBean(); foreach ($this->directives as $directive) { $recordBean->{$directive->field->cleanName} = $directive->value; } $setBean->{'own' . ucfirst($this->cleanName) . 'List'}[] = $recordBean; R::storeAll([$recordBean, $setBean]); return $this; }
public function linkedSet() { if ($this->linkedSetId > 0) { return Set::byID($this->linkedSetId, $this->set->keyType); } return null; }
public function getOptions() { $bean = $this->getBean(); if ($bean === null) { return []; } $result = []; $set = Set::get($bean->{$this->_('linkedSetId')}, $this->set->keyType); $field = self::get($bean->{$this->_('linkedFieldId')}, $set); $set->each(function ($values, $recordID, $set, $recordBean, $keyType) use(&$result, $field) { switch ($keyType) { default: case Set::$keysID: $key = $field->getBean()->getID(); break; case Set::$keysClean: $key = $field->cleanName; break; case Set::$keysDirty: $key = $field->name; break; } $result[] = $values[$key]->value; }); return $result; }
public function renderJSON() { $field = Type::Field($this->field); $result = []; if (!empty($this->value)) { $fieldBean = $field->getBean(); $linkedSetId = $fieldBean->{$field->_('linkedSetId')}; if (!empty($linkedSetId)) { $record = Set::byID($linkedSetId)->getRecord($this->value); //TODO: implement throw new \Exception('Not yet implemented'); } } return ''; }
public static function receive() { $slim = new Slim(); $skemaKeys = $slim->request->get('skema'); $sets = []; foreach ($skemaKeys as $skemaKey => $records) { if (!isset($sets[$skemaKey])) { if (is_numeric($skemaKey)) { $id = $skemaKey; $sets[$skemaKey] = Set::byID($id); } else { $cleanName = $skemaKey; $sets[$skemaKey] = Set::byCleanName($cleanName); } } $set = Type::Set($sets[$skemaKey]); foreach ($records as $recordID => $fields) { $recordChanged = false; $record = $set->getRecord($recordID); foreach ($fields as $fieldKey => $fieldValue) { if (is_numeric($fieldKey)) { $id = $fieldKey; $field = $set->fieldsByID[$id]; } else { $cleanName = $fieldKey; $field = $set->fieldsByCleanName[$cleanName]; } $directive = $field->getDirective(); $sanitized = $directive::sanitize($fieldValue); if ($record->{$field->cleanName} !== $sanitized) { $record->{$field->cleanName} = $sanitized; $recordChanged = true; } } if ($recordChanged) { $record->update(); } } } }
public function addToSet(Set $set) { $setBean = $set->getBean(); if (R::count('skemafield', ' name = ? and skemaset_id = ? ', [$this->name, $setBean->getID()]) > 0) { if (Set::$strict) { throw new \Exception('Already exists on set'); } return $this; } $fieldBean = $this->newBean(); $set->fields[$this->cleanName] = $this; $this->set = $set; $setBean->ownSkemafieldList[] = $fieldBean; R::storeAll([$fieldBean, $setBean]); return $this; }