/** * Save element structure to datasource * * @param \Menu\Model\Menu\Structure\ProxyAbstract $structure * @return int Number of affected rows */ public function save(&$structure) { if (!$structure instanceof Structure\ProxyAbstract || empty($structure->type)) { return 0; } $data = ArrayUtils::iteratorToArray($structure->getBaseIterator()); $label = empty($data['label']) ? '' : $data['label']; unset($data['label']); $result = parent::save($data); if ($result > 0) { if (empty($structure->id)) { $structure->setOption('id', $id = $data['id']); } else { $id = $structure->id; } $result += $this->saveLabel($id, $label); foreach ($structure->getPropertiesIterator() as $property => $value) { $result += $this->saveProperty($id, $property, $value); } } return $result; }
/** * Save element structure to datasource * * @param array|\Customize\Model\Rule\Structure $structure * @return int Number of affected rows */ public function save(&$structure) { $id = $this->getSaveProperty($structure, 'id'); if (empty($id)) { $selector = $this->getSaveProperty($structure, 'selector', ''); $media = $this->getSaveProperty($structure, 'media', ''); $rootId = $this->getSaveProperty($structure, 'rootParagraphId'); $sql = $this->sql(); $select = $sql->select()->columns(array('id'))->where(array('selector' => $selector, 'media' => $media, 'rootParagraphId' => $rootId))->limit(1); $result = $sql->prepareStatementForSqlObject($select)->execute(); if ($result->getAffectedRows()) { foreach ($result as $row) { $this->setSaveProperty($structure, 'id', $row['id']); } } } $result = parent::save($structure); $id = $this->getSaveProperty($structure, 'id'); if ($result > 0 && !empty($id)) { switch (true) { case $structure instanceof Structure: $properties = $structure->getRawProperties(); break; case is_array($structure): $properties = isset($structure['properties']) ? $structure['properties'] : array(); break; case is_object($structure): $properties = isset($structure->properties) ? $structure->properties : array(); break; default: return $result; } $sql = $this->sql($this->getTableInSchema(static::$propertyTableName)); if (empty($properties)) { $delete = $sql->delete()->where(array('ruleId' => $id)); $result += $sql->prepareStatementForSqlObject($delete)->execute()->getAffectedRows(); } else { $propNames = array(); foreach ($properties as $name => $spec) { $propNames[] = $propName = empty($spec['name']) ? $name : $spec['name']; $result += $this->saveProperty($id, $propName, $spec['value'], $spec['priority']); } $delete = $sql->delete()->where(array('ruleId' => $id, new NotIn('name', $propNames))); $result += $sql->prepareStatementForSqlObject($delete)->execute()->getAffectedRows(); } } return $result; }
/** * Save paragraph form raw data * * @param array $data * @return int|null */ public function saveRawData(array $data) { if (!parent::save($data)) { return null; } return isset($data['id']) ? $data['id'] : null; }
/** * Save element structure to datasource * * @param \Grid\Banner\Model\Banner\Structure\ProxyAbstract $structure * @return int Number of affected rows */ public function save(&$structure) { if ($structure instanceof Structure) { $data = $structure->toArray(); } else { $data = (array) $structure; } if (isset($data['tagBanners'])) { $tagBanners = (array) $data['tagBanners']; unset($data['tagBanners']); } if (isset($data['localeBanners'])) { $localeBanners = (array) $data['localeBanners']; unset($data['localeBanners']); } if (isset($data['globalBanners'])) { $globalBanners = (array) $data['globalBanners']; unset($data['globalBanners']); } $result = parent::save($data); if ($result > 0) { if (empty($structure->id)) { $structure->setOption('id', $id = $data['id']); } else { $id = $structure->id; } if (isset($tagBanners)) { $result += $this->saveTagBanners($id, $tagBanners); } if (isset($localeBanners)) { $result += $this->saveLocaleBanners($id, $localeBanners); } if (isset($globalBanners)) { $result += $this->saveGlobalBanners($id, $globalBanners); } } return $result; }