/** * Create a new url rewite information * * @param Core_Model_Abstract $object * @param string $idpath * @param string $requestPath * @param string $targetPath * @return Core_Model_Url_Rewrite */ public function newUrlRewite(Core_Model_Abstract $object, $idpath = null, $requestPath = null, $targetPath = null) { if (empty($requestPath)) { if (!$object->getRequestPath()) { if ($object->getRequestPathPrepend()) { $requestPath .= trim($object->getRequestPathPrepend(), '/') . '/'; } if ($object->getUrlKey()) { $requestPath .= $object->getUrlKey(); } else { $requestPath .= $object->getId(); } } else { $requestPath = $object->getRequestPath(); } } $data['request_path'] = mb_strtolower($requestPath, 'UTF-8'); if (empty($targetPath)) { if (!$object->getTargetPath()) { if ($object->getTargetPathPrepend()) { $targetPath .= trim($object->getTargetPathPrepend(), '/') . '/'; } $targetPath .= $object->getId(); } else { $targetPath = $object->getTargetPath(); } } $data['target_path'] = $targetPath; if (empty($idpath)) { if (!$object->getIdPath()) { if ($object->getIdPathPrepend()) { $idpath .= rtrim($object->getIdPathPrepend(), '/') . '/'; } $idpath .= $object->getId(); } else { $idpath = $object->getIdPath(); } } $data['id_path'] = $idpath; $this->setData($data); $this->loadByIdPath($data['id_path']); if (!$this->getId()) { $this->loadByRequestPath($data['request_path']); } $this->save(); return $this; }