/** * @param $fieldName * @return array|mixed * It is imperative to use bean here */ protected function _getImageField($fieldName) { try { /** @var \Skully\App\Models\BaseModel $this */ return UtilitiesHelper::decodeJson($this->bean->{$fieldName}, true); } catch (\Exception $e) { return array(); } }
public function moveImage() { $id = $this->getParam('id'); $from = (int) $this->getParam('position'); $direction = $this->getParam('direction'); $settingName = $this->getParam('setting'); $fieldName = $this->getParam('field'); if ($direction == 'up') { $to = $from - 1; } else { $to = $from + 1; } $instanceBean = R::findOne($this->model(), 'id = ?', array($id)); $instance = $instanceBean->box(); $images = $instance->get($fieldName); if (!is_array($images)) { $images = UtilitiesHelper::decodeJson($images, true); } $imageFrom = $images[$from]; $images[$from] = $images[$to]; $images[$to] = $imageFrom; $instance->set($fieldName, json_encode($images)); R::store($instance); echo json_encode(array('settingName' => $settingName, 'from' => $from, 'to' => $to)); }