@param Mage_Core_Model_Abstract $model

@return string
@throws RuntimeException
515695
public function getDeleteUrl($model = null)
    {
        if (!$model instanceof Mage_Core_Model_Abstract) {
            $model = $this->getCurrentRecord();
        } else {
            $expectedClass = get_class($this->getModel());
            if (!is_a($model, $expectedClass)) {
                throw new RuntimeException($this->__('Invalid model class. Expected:%1$s Passed:%2$s', $expectedClass, get_class($model)));
            }
        }

        return $this->_getUrl($this->getDeleteRoute(), [$model->getIdFieldName() => $model->getId()]);
    }
766505
public function hydrate(AbstractModel $model, $row)
    {
        if (!$row) {
            return $model;
        }

        $p = (array) get_object_vars($row);
        $reflection = new \ReflectionClass($model);
        foreach ($p as $property => $value) {
            try {
                $property = $reflection->getProperty($property);
                $property->setAccessible(true);
                $property->setValue($model, $value);
            } catch (\Exception $e) {
                $this->log(ILog::T_ERROR, $e->getMessage());
                continue;
            }
        }

        $this->hydrateRelations($model);

        return $model;
    }
1115950
public static function introspectModel($model) {
        return self::cache(array(__METHOD__, $model), function() use ($model) {
            list($plugin, $model, $id, $class) = Admin::parseName($model);
            $core = Configure::read('Admin.coreName');

            $pluginPath = ($plugin !== $core) ? $plugin . '.' : '';
            $object = ClassRegistry::init($pluginPath . $model);

            // Exit early if disabled
            if (!$object || empty($object->useTable) || (isset($object->admin) && $object->admin === false)) {
                return null;
            }

            // Override model
            $object->Behaviors->load('Containable');
            $object->Behaviors->load('Utility.Cacheable');
            $object->cacheQueries = false;
            $object->recursive = -1;

            if ($plugin !== $core) {
                $object->plugin = $plugin;
            }

            // Inherit enums from parent classes
            if ($object->Behaviors->hasMethod('enum')) {
                $object->enum = $object->enum();
            }

            // Generate readable names
            $object->urlSlug = Inflector::underscore($id);
            $object->qualifiedName = $id;
            $object->singularName = Inflector::humanize(Inflector::underscore($model));
            $object->pluralName = Inflector::pluralize($object->singularName);

            // Generate a list of field (database column) data
            $fields = $object->schema();
            $hideFormFields = array();
            $hideTableFields = array();
            $hideReadFields = array();

            foreach ($fields as $field => &$data) {
                if ($field === 'id') {
                    $data['title'] = 'ID';
                } else {
                    $data['title'] = Inflector::humanize(Inflector::underscore(str_replace('_id', '', $field)));
                }

                if (isset($object->enum[$field])) {
                    $data['type'] = 'enum';
                }

                // Hide counter cache and auto-date fields
                if (in_array($field, array('created', 'modified')) || mb_substr($field, -6) === '_count') {
                    $hideFormFields[] = $field;
                }
            }

            foreach ($object->belongsTo as $alias => $assoc) {
                $fields[$assoc['foreignKey']]['type'] = 'relation';
                $fields[$assoc['foreignKey']]['belongsTo'][$alias] = $assoc['className'];
            }

            $object->fields = $fields;

            // Apply default admin settings
            $settings = isset($object->admin) ? $object->admin : array();
            $defaultSettings = Configure::read('Admin.modelDefaults');

            // @version 1.3.0 - Backwards compatibility with old hideFields field
            if (!empty($settings['hideFields'])) {
                $settings['hideFormFields'] = $settings['hideFields'];
                unset($settings['hideFields']);
            }

            if (is_array($settings)) {
                $settings = Hash::merge($defaultSettings, $settings);
                $settings['fileFields'] = array_merge($settings['fileFields'], $settings['imageFields']);
                $settings['hideFormFields'] = array_merge($settings['hideFormFields'], $hideFormFields);
                $settings['hideTableFields'] = array_merge($settings['hideTableFields'], $hideTableFields);
                $settings['hideReadFields'] = array_merge($settings['hideReadFields'], $hideReadFields);

                $object->admin = $settings;
            } else {
                $object->admin = $defaultSettings;
            }

            // Update associated settings
            foreach ($object->hasAndBelongsToMany as &$assoc) {
                $assoc = array_merge(array('showInForm' => true), $assoc);
            }

            return $object;
        });
    }
622739
public function generateSignature()
    {
        if ($this->isFinal() === true && $this->isAbstract() === true) {
            throw new RuntimeException('A method can not be "abstract" and "final".');
        }

        if ($this->isAbstract() === true && $this->getVisibility() === Modifiers::VISIBILITY_PRIVATE) {
            throw new RuntimeException('A method can not be "abstract" and "private".');
        }

        $signature = $this->getIndentation();
        if ($this->isFinal() === true) {
            $signature .= 'final ';
        } elseif ($this->isAbstract()) {
            $signature .= 'abstract ';
        }

        $signature .= $this->getVisibility();

        if ($this->isStatic() === true) {
            $signature .= ' static';
        }

        return $signature . ' function ' . $this->name . '(' . implode(', ', $this->parameters) . ')';
    }
269819
public function setModel($model, $display_field = null)
    {
        if ($model instanceof Model) {
            return AbstractObject::setModel($model);
        }

        $this->model_name = is_string($model) ? $model : get_class($model);
        $this->model_name = (string) $this->app->normalizeClassName($this->model_name, 'Model');

        if ($display_field) {
            $this->display_field = (string) $display_field;
        }

        if ($display_field !== false) {
            $this->owner->addExpression($this->getDereferenced())
                ->set(array($this, 'calculateSubQuery'))
                ->caption((string) $this->caption());
        }

        $this->system(true);
        $this->editable(true);
        $this->visible(false);

        return $this;
    }
846988
public function get(AbstractModel $model, $param = null)
    {
        if ($this->contains($model)) {
            return $this->storage[md5($this->generateHash($model) . json_encode($param))]->getModel();
        }

        return null;
    }
338113
public function findOneBy(AbstractModel $model, $param = [])
    {

        $result = $this->findBy($model, $param);
        $result->rewind();

        return $result->current();
    }
200327
public function hydrateRelations(AbstractModel $model)
    {
        if (!$this->queryBuilder->fetchCacheData($model)) {
            return $model;
        }
        $reflection = new \ReflectionClass($model);

        foreach ($this->queryBuilder->fetchCacheData($model)['relationList'] as $relation) {
            $injectionModel = new $relation['model']();
            try {
                $property = $reflection->getProperty($relation['target']);
            } catch (\Exception $e) {
                $this->log(ILog::T_ERROR, $e->getMessage());
                continue;
            }

            $property->setAccessible(true);

            /**
             * @todo implement dynamic mappings from doc head
             */
            if (!$this->lazyLoading) {
                $mappingProperty = $reflection->getProperty($relation['mapping_id']);
                $mappingProperty->setAccessible(true);
                $this->findOneBy($injectionModel, ['id' => $mappingProperty->getValue($model)]);
                unset($mappingProperty);
            }
            $property->setValue($model, $injectionModel);
        }

        return $model;
    }
234582
private function generateProxyClass(): string
    {
        $class = $this->reflectionClass;

        if ($class->isFinal()) {
            throw new \RuntimeException(sprintf(
                'Can not generate proxy for final class "%s".',
                $class->getName()
            ));
        }

        if ($class->isAbstract()) {
            throw new \RuntimeException(sprintf(
                'Can not generate proxy for abstract class "%s".',
                $class->getName()
            ));
        }

        $methodCodes = [];

        $uses = $this->getAllUseStatementsMarkedAsAnnotation($class);
        $uses[] = 'FiveLab\Component\Transactional\Proxy\ProxyInterface as FiveLabTransactionalProxyInterface';

        $uses = \array_map(function ($use) {
            return 'use '.$use.';';
        }, $uses);

        $interfaces = [
            'FiveLabTransactionalProxyInterface',
        ];

        foreach ($this->getProxyMethods() as $method) {
            $methodCodes[] = $this->generateProxyMethod($method);
        }

        $docComment = $class->getDocComment();

        $templateVariables = [
            'uses'           => \implode("\n", $uses),
            'namespace'      => $class->getNamespaceName(),
            'docComment'     => $docComment,
            'proxyClassName' => $class->getShortName().'Proxy',
            'className'      => '\\'.$class->getName(),
            'proxyMethods'   => \implode("\n\n", $methodCodes),
            'interfaces'     => \implode(', ', $interfaces),
            'realClassName'  => $class->getName(),
        ];

        $template = $this->getTemplateForProxyClass();
        $code = $this->replaceVariables($template, $templateVariables);

        $lines = \explode("\n", $code);
        $lines = \array_map('rtrim', $lines);

        return \implode("\n", $lines);
    }
635111
public function getMainField($model)
    {
        // describe the model
        $desc = $this->desc($model);

        // search by fields for primary key
        foreach (array_keys($desc[$model]) as $field) {
            return $field;
        }
    }
1082688
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
    {
        if (is_array($object->getConfig())) {
            $object->setConfig($this->serializer->serialize($object->getConfig()));
        }

        $rule = $this->ruleFactory->create();
        $ruleCondition = $object->getRuleCondition();

        if (is_object($ruleCondition)) {
            $rule = $ruleCondition;
        } elseif (is_array($ruleCondition)) {
            $rule->getConditions()->loadArray($ruleCondition);
        }
        $object->setRuleCondition($this->serializer->serialize($rule->getConditions()->asArray()));

        return parent::_beforeSave($object);
    }
1296618
public static function parseName($model) {
        return self::cache(array(__METHOD__, $model), function() use ($model) {
            list($plugin, $model) = pluginSplit($model);
            $core = Configure::read('Admin.coreName');

            if (!$plugin) {
                $plugin = $core;
            }

            $plugin = Inflector::camelize($plugin);
            $model = Inflector::camelize($model);
            $class = $model;

            if ($plugin !== $core) {
                $class = $plugin . '.' . $class;
            }

            return array(
                $plugin, // plugin name, includes Core
                $model, // model class name
                $plugin . '.' . $model, // plugin and model, includes Core
                $class // plugin and model, excludes Core
            );
        });
    }
1109053
public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }
1323938
protected function serializeModel($model)
    {
        if ($this->request->getIsHead()) {
            return null;
        }

        [$fields, $expand] = $this->getRequestedFields();
        return $model->toArray($fields, $expand);
    }
587828
public function getSchema(): AbstractTable
    {
        return $this->database->getDriver(DatabaseInterface::WRITE)->getSchema($this->name,
            $this->database->getPrefix());
    }
792012
public function getIdentifierMade($model)
    {
        if (!is_object($model)) {
            throw new \InvalidArgumentException(sprintf('You must give a object, "%s" given.', gettype($model)));
        }

        $methodMadeBy = 'get' . ucfirst($this->definition->getMadeBy());
        if (!method_exists($model, $methodMadeBy)) {
            throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($model), $methodMadeBy));
        }

        $modelMade = $model->$methodMadeBy();
        if (!is_object($modelMade)) {
            throw new \RuntimeException(sprintf('Model "%s::%s()" must already return object, "%s" given.', get_class($model), $methodMadeBy, gettype($modelMade)));
        }

        $methodMadeField = 'get' . ucfirst($this->definition->getMadeField());
        if (!method_exists($model->{'get'.$this->definition->getMadeBy()}(), $modelMade)) {
            throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($modelMade), $methodMadeField));
        }

        return $model->{'get'.ucfirst($this->definition->getMadeBy())}()->{'get'.ucfirst($this->definition->getMadeField())}();
    }
999510
public function getControllerName(Model $model) {
		$modelNamePlural = $this->getModelNamePlural($model, false);
		$controllerName = mb_strtolower(Inflector::underscore($modelNamePlural));

		return $controllerName;
	}