-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCmsCore\Classes\Model; | ||
|
||
class Redirect extends Model | ||
{ | ||
public const TABLE = 'cms_redirect'; | ||
public const ALIAS = 'r'; | ||
|
||
public const FIELD_ID = 'id'; | ||
public const FIELD_PATH_FROM = 'path_from'; | ||
public const FIELD_PATH_TO = 'path_to'; | ||
public const FIELD_PAGE_LANGUAGE_ID = 'page_language_id'; | ||
|
||
/** | ||
* Initialize relations | ||
*/ | ||
public function initialize() | ||
{ | ||
parent::initialize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCMS\Classes\WebForm\DataForm\DataForm; | ||
|
||
class RedirectForm extends DataForm | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getModel(): string | ||
{ | ||
return Redirect::class; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function initialize() | ||
{ | ||
// add form code... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCmsCore\Classes\ObjectList; | ||
|
||
class RedirectList extends ObjectList | ||
{ | ||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function current() | ||
{ | ||
return parent::current(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function get($key) | ||
{ | ||
return parent::get($key); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function getFirst() | ||
{ | ||
return parent::getFirst(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function getLast() | ||
{ | ||
return parent::getLast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCmsCore\Classes\ObjectMap; | ||
|
||
class RedirectMap extends ObjectMap | ||
{ | ||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function current() | ||
{ | ||
return parent::current(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function get($key) | ||
{ | ||
return parent::get($key); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function getFirst() | ||
{ | ||
return parent::getFirst(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return Redirect|false | ||
*/ | ||
public function getLast() | ||
{ | ||
return parent::getLast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCMS\Classes\Phalcon\Injectable; | ||
use Phalcon\Mvc\Model\Query\Builder; | ||
|
||
class RedirectService extends Injectable | ||
{ | ||
/** | ||
* @param string $previousUrlPath | ||
* @param string $urlPath | ||
* @param int $pageLanguageId | ||
* @return void | ||
*/ | ||
public function add(string $previousUrlPath, string $urlPath, int $pageLanguageId) | ||
{ | ||
$redirectMap = $this->getByPageLanguageId($pageLanguageId); | ||
|
||
$redirect = new Redirect(); | ||
|
||
$redirect->path_from = $previousUrlPath; | ||
$redirect->path_to = $urlPath; | ||
$redirect->page_language_id = $pageLanguageId; | ||
|
||
$redirect->save(); | ||
|
||
foreach ($redirectMap as $redirect) { | ||
$redirect->path_to = $urlPath; | ||
$redirect->save(); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $pageLanguageId | ||
* @return RedirectMap | ||
*/ | ||
public function getByPageLanguageId(int $pageLanguageId): RedirectMap | ||
{ | ||
$query = (new Builder) | ||
->from(Redirect::class) | ||
->inWhere(Redirect::FIELD_PAGE_LANGUAGE_ID, [$pageLanguageId]); | ||
|
||
return $this->dbService->getObjectMap($query, RedirectMap::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace KikCMS\Objects\Redirect; | ||
|
||
use KikCMS\Classes\DataTable\DataTable; | ||
|
||
class Redirects extends DataTable | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getFormClass(): string | ||
{ | ||
return RedirectForm::class; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabels(): array | ||
{ | ||
return ['redirect', 'redirects']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getModel(): string | ||
{ | ||
return Redirect::class; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getTableFieldMap(): array | ||
{ | ||
return [ | ||
Redirect::FIELD_ID => 'Id', | ||
Redirect::FIELD_PATH_FROM => 'Path_from', | ||
Redirect::FIELD_PATH_TO => 'Path_to', | ||
Redirect::FIELD_PAGE_LANGUAGE_ID => 'Page_language_id', | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function initialize() | ||
{ | ||
// nothing here... | ||
} | ||
} |