From 22235c3af046660bd4f2c3ad2f7defb6bd324381 Mon Sep 17 00:00:00 2001 From: Takuro Hishikawa Date: Wed, 28 Feb 2018 10:59:34 +0900 Subject: [PATCH 1/2] Update to v8 compatible --- attributes/page_selector/controller.php | 123 ++++++++++++------ attributes/page_selector/db.xml | 14 -- attributes/page_selector/icon.png | Bin 714 -> 0 bytes controller.php | 25 ++-- .../Value/Value/PageSelectorValue.php | 58 +++++++++ 5 files changed, 159 insertions(+), 61 deletions(-) delete mode 100644 attributes/page_selector/db.xml delete mode 100644 attributes/page_selector/icon.png create mode 100644 src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php diff --git a/attributes/page_selector/controller.php b/attributes/page_selector/controller.php index 66dca01..ba90796 100644 --- a/attributes/page_selector/controller.php +++ b/attributes/page_selector/controller.php @@ -1,20 +1,26 @@ 'integer', 'options' => array('default' => 0, 'notnull' => false)); - public function getValue() { - $db = Loader::db(); - $value = $db->GetOne("select value from atPageSelector where avID = ?", array($this->getAttributeValueID())); - return $value; - } + public function getIconFormatter() + { + return new FontAwesomeIconFormatter('file'); + } public function searchForm($list) { $PagecID = $this->request('value'); @@ -23,7 +29,7 @@ public function searchForm($list) { } public function search() { - $form_selector = Loader::helper('form/page_selector'); + $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); print $form_selector->selectPage($this->field('value'), $this->request('value'), false); } @@ -31,38 +37,23 @@ public function form() { if (is_object($this->attributeValue)) { $value = $this->getAttributeValue()->getValue(); } - $form_selector = Loader::helper('form/page_selector'); - print $form_selector->selectPage($this->field('value'), $value); + $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); + print $form_selector->selectPage($this->field('value'), (isset($value)) ? $value : null); } public function validateForm($p) { - return $p['value'] != 0; - } - - public function saveValue($value) { - $db = Loader::db(); - if(!intval($value)) { - $value = 0; + if (intval($p['value']) > 0) { + $c = Page::getByID(intval($p['value'])); + if (is_object($c) && !$c->isError()) { + return true; + } else { + return new Error(t('You must specify a valid page for %s', $this->getAttributeKey()->getAttributeKeyDisplayName()), + new AttributeField($this->getAttributeKey()) + ); + } + } else { + return new FieldNotPresentError(new AttributeField($this->getAttributeKey())); } - $db->Replace('atPageSelector', array('avID' => $this->getAttributeValueID(), 'value' => $value), 'avID', true); - } - - public function deleteKey() { - $db = Loader::db(); - $arr = $this->attributeKey->getAttributeValueIDList(); - foreach($arr as $id) { - $db->Execute('delete from atPageSelector where avID = ?', array($id)); - } - } - - public function saveForm($data) { - $db = Loader::db(); - $this->saveValue($data['value']); - } - - public function deleteValue() { - $db = Loader::db(); - $db->Execute('delete from atPageSelector where avID = ?', array($this->getAttributeValueID())); } public function getDisplayValue() { @@ -82,4 +73,62 @@ public function getDisplayValue() { return $html; } + public function exportValue(\SimpleXMLElement $akv) + { + $av = $akv->addChild('value'); + $cID = $this->getAttributeValue()->getValue(); + /** @var Number $nh */ + $nh = Application::getFacadeApplication()->make('helper/number'); + if ($nh->isInteger($cID)) { + $av->addChild('cID', ContentExporter::replacePageWithPlaceHolder($cID)); + } else { + $av->addChild('cID', 0); + } + } + + /** + * @param \SimpleXMLElement $akv + * @return bool|string|void + */ + public function importValue(\SimpleXMLElement $akv) + { + if (isset($akv->value->cID)) { + $cIDVal = (string) $akv->value->cID; + /** @var ValueInspectorInterface $inspector */ + $inspector = Application::getFacadeApplication()->make('import/value_inspector'); + $result = $inspector->inspect($cIDVal); + $cID = $result->getReplacedValue(); + if ($cID) { + return $this->createAttributeValue($cID); + } + } + } + + public function createAttributeValue($mixed) + { + if (is_object($mixed) && method_exists($mixed, 'getCollectionID')) { + $mixed = $mixed->getCollectionID(); + } + + $value = new PageSelectorValue(); + $value->setValue((int) $mixed); + return $value; + } + + public function createAttributeValueFromRequest() + { + $data = $this->post(); + if (intval($data['value']) > 0) { + $c = Page::getByID(intval($data['value'])); + return $this->createAttributeValue($c); + } + + return $this->createAttributeValue(0); + } + + public function getAttributeValueClass() + { + return PageSelectorValue::class; + } + } diff --git a/attributes/page_selector/db.xml b/attributes/page_selector/db.xml deleted file mode 100644 index a039c2f..0000000 --- a/attributes/page_selector/db.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - -
-
\ No newline at end of file diff --git a/attributes/page_selector/icon.png b/attributes/page_selector/icon.png deleted file mode 100644 index 2965ba45368799cb2310f4c0eeb36fa3b60cde97..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 714 zcmV;*0yX`KP)!QBBCOq|65a4H8WdVTl;Q(eSKq?4XL64$#S_|+TGoKd-K+=)jhm{aAbh};i-be3! zOy9j@uh%Q)=jSe5|LOYUnVFe+lAMN=CL|R&=b-AGI_Cs{nc?*5uUw3=NRs56<>lo& zKU}-^Jpci~_W*}M5+KLbu}L_0e$~~gRTQJqf~vyIIJtPbkpu)|bv(#Y$)W2#(|(FP z&nMguMxc#bL;->*mC6|O`*^vtgMPm+Ns?eR8ht)HJ6r2?I+=(FNlp})*(9BF@NYWU z+S)>^)k2!4vbVQ~*ZZ$O{dHsGx3ABhJwuYJsz(4CERF#*B7_{zHaF2|G;s0Ti*kN- z)slL0;?$`xt{OS`z=Jr7h-LtRkOwrIO=Ka%($W${6!m&tkAHHU?RNXKE0-_*c;MU7 zdS)RYgn*(b%&D`*#YNlS+qY)3X?Y0r-p7AiEy=R1^XTzkw-2qG+5-*MN(C09RH{`? zk{VW4R`B%c6Krp9nZ@Y3-LBu>dHDcjb@~+u0Qc_Ry%&bVFO5_ck$Sxj-}RLj&tFJm zZuVrJ7k%&j^WXot|4W*tK}BjtW&!{XIA%bFV^3=1BZ!EUNRCb}ESwo;nSa~sy(+67 wBRMegjR6Ch8sX@R9u5eAX5g51w5e0^A9tN>OJaG%-2eap07*qoM6N<$g7~La`Tzg` diff --git a/controller.php b/controller.php index 1de92d1..74573e4 100644 --- a/controller.php +++ b/controller.php @@ -1,15 +1,15 @@ associateAttributeKeyType(AttributeType::getByHandle('page_selector')); + $pkg = parent::install(); + /** @var TypeFactory $factory */ + $factory = $this->app->make(TypeFactory::class); + $type = $factory->getByHandle('page_selector'); + if (!is_object($type)) { + $type = $factory->add('page_selector', t('Page Selector'), $pkg); + /** @var CategoryService $service */ + $service = $this->app->make(CategoryService::class); + $col = $service->getByHandle('collection')->getController(); + $col->associateAttributeKeyType($type); + } } } \ No newline at end of file diff --git a/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php b/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php new file mode 100644 index 0000000..c774977 --- /dev/null +++ b/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php @@ -0,0 +1,58 @@ +value; + } + + /** + * @return Page + */ + public function getPageObject() + { + return Page::getByID($this->getValue()); + } + + /** + * @param integer $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * @param Page $page + */ + public function setPageObject(Page $page) + { + $this->setValue($page->getCollectionID()); + } + + /** + * @return string + */ + public function __toString() + { + return (string) $this->getValue(); + } +} \ No newline at end of file From 4a00b759e5e023e5ccb4c69b2409b2756be7a265 Mon Sep 17 00:00:00 2001 From: Takuro Hishikawa Date: Wed, 28 Feb 2018 11:04:09 +0900 Subject: [PATCH 2/2] PHP CS Fix --- attributes/page_selector/controller.php | 277 +++++++++--------- controller.php | 54 ++-- .../Value/Value/PageSelectorValue.php | 6 +- 3 files changed, 175 insertions(+), 162 deletions(-) diff --git a/attributes/page_selector/controller.php b/attributes/page_selector/controller.php index ba90796..2a4f6ac 100644 --- a/attributes/page_selector/controller.php +++ b/attributes/page_selector/controller.php @@ -1,134 +1,143 @@ - 'integer', 'options' => array('default' => 0, 'notnull' => false)); - - public function getIconFormatter() - { - return new FontAwesomeIconFormatter('file'); - } - - public function searchForm($list) { - $PagecID = $this->request('value'); - $list->filterByAttribute($this->attributeKey->getAttributeKeyHandle(), $PagecID, '='); - return $list; - } - - public function search() { - $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); - print $form_selector->selectPage($this->field('value'), $this->request('value'), false); - } - - public function form() { - if (is_object($this->attributeValue)) { - $value = $this->getAttributeValue()->getValue(); - } - $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); - print $form_selector->selectPage($this->field('value'), (isset($value)) ? $value : null); - } - - public function validateForm($p) { - if (intval($p['value']) > 0) { - $c = Page::getByID(intval($p['value'])); - if (is_object($c) && !$c->isError()) { - return true; - } else { - return new Error(t('You must specify a valid page for %s', $this->getAttributeKey()->getAttributeKeyDisplayName()), - new AttributeField($this->getAttributeKey()) - ); - } - } else { - return new FieldNotPresentError(new AttributeField($this->getAttributeKey())); - } - } - - public function getDisplayValue() { - $at_val = $this->getValue(); - $html = ''; - $at_page = Page::getByID($at_val); - if (is_object($at_page) && !$at_page->isInTrash()) { - $cpc = new Permissions($at_page); - if ($cpc->canViewPage()) { - $url = $at_page->getCollectionPath(); - $name = h($at_page->getCollectionName()); - $html = '' . $name . ''; - } else { - $html = '' . t('access denied') . ''; - } - } - return $html; - } - - public function exportValue(\SimpleXMLElement $akv) - { - $av = $akv->addChild('value'); - $cID = $this->getAttributeValue()->getValue(); - /** @var Number $nh */ - $nh = Application::getFacadeApplication()->make('helper/number'); - if ($nh->isInteger($cID)) { - $av->addChild('cID', ContentExporter::replacePageWithPlaceHolder($cID)); - } else { - $av->addChild('cID', 0); - } - } - - /** - * @param \SimpleXMLElement $akv - * @return bool|string|void - */ - public function importValue(\SimpleXMLElement $akv) - { - if (isset($akv->value->cID)) { - $cIDVal = (string) $akv->value->cID; - /** @var ValueInspectorInterface $inspector */ - $inspector = Application::getFacadeApplication()->make('import/value_inspector'); - $result = $inspector->inspect($cIDVal); - $cID = $result->getReplacedValue(); - if ($cID) { - return $this->createAttributeValue($cID); - } - } - } - - public function createAttributeValue($mixed) - { - if (is_object($mixed) && method_exists($mixed, 'getCollectionID')) { - $mixed = $mixed->getCollectionID(); - } - - $value = new PageSelectorValue(); - $value->setValue((int) $mixed); - return $value; - } - - public function createAttributeValueFromRequest() - { - $data = $this->post(); - if (intval($data['value']) > 0) { - $c = Page::getByID(intval($data['value'])); - return $this->createAttributeValue($c); - } - - return $this->createAttributeValue(0); - } - - public function getAttributeValueClass() - { - return PageSelectorValue::class; - } - -} + 'integer', 'options' => ['default' => 0, 'notnull' => false]]; + + public function getIconFormatter() + { + return new FontAwesomeIconFormatter('file'); + } + + public function searchForm($list) + { + $PagecID = $this->request('value'); + $list->filterByAttribute($this->attributeKey->getAttributeKeyHandle(), $PagecID, '='); + + return $list; + } + + public function search() + { + $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); + echo $form_selector->selectPage($this->field('value'), $this->request('value'), false); + } + + public function form() + { + if (is_object($this->attributeValue)) { + $value = $this->getAttributeValue()->getValue(); + } + $form_selector = Application::getFacadeApplication()->make('helper/form/page_selector'); + echo $form_selector->selectPage($this->field('value'), (isset($value)) ? $value : null); + } + + public function validateForm($p) + { + if (intval($p['value']) > 0) { + $c = Page::getByID(intval($p['value'])); + if (is_object($c) && !$c->isError()) { + return true; + } else { + return new Error(t('You must specify a valid page for %s', $this->getAttributeKey()->getAttributeKeyDisplayName()), + new AttributeField($this->getAttributeKey()) + ); + } + } else { + return new FieldNotPresentError(new AttributeField($this->getAttributeKey())); + } + } + + public function getDisplayValue() + { + $at_val = $this->getValue(); + $html = ''; + $at_page = Page::getByID($at_val); + if (is_object($at_page) && !$at_page->isInTrash()) { + $cpc = new Permissions($at_page); + if ($cpc->canViewPage()) { + $url = $at_page->getCollectionPath(); + $name = h($at_page->getCollectionName()); + $html = '' . $name . ''; + } else { + $html = '' . t('access denied') . ''; + } + } + + return $html; + } + + public function exportValue(\SimpleXMLElement $akv) + { + $av = $akv->addChild('value'); + $cID = $this->getAttributeValue()->getValue(); + /** @var Number $nh */ + $nh = Application::getFacadeApplication()->make('helper/number'); + if ($nh->isInteger($cID)) { + $av->addChild('cID', ContentExporter::replacePageWithPlaceHolder($cID)); + } else { + $av->addChild('cID', 0); + } + } + + /** + * @param \SimpleXMLElement $akv + * + * @return bool|string|void + */ + public function importValue(\SimpleXMLElement $akv) + { + if (isset($akv->value->cID)) { + $cIDVal = (string) $akv->value->cID; + /** @var ValueInspectorInterface $inspector */ + $inspector = Application::getFacadeApplication()->make('import/value_inspector'); + $result = $inspector->inspect($cIDVal); + $cID = $result->getReplacedValue(); + if ($cID) { + return $this->createAttributeValue($cID); + } + } + } + + public function createAttributeValue($mixed) + { + if (is_object($mixed) && method_exists($mixed, 'getCollectionID')) { + $mixed = $mixed->getCollectionID(); + } + + $value = new PageSelectorValue(); + $value->setValue((int) $mixed); + + return $value; + } + + public function createAttributeValueFromRequest() + { + $data = $this->post(); + if (intval($data['value']) > 0) { + $c = Page::getByID(intval($data['value'])); + + return $this->createAttributeValue($c); + } + + return $this->createAttributeValue(0); + } + + public function getAttributeValueClass() + { + return PageSelectorValue::class; + } +} diff --git a/controller.php b/controller.php index 74573e4..e289ebf 100644 --- a/controller.php +++ b/controller.php @@ -1,35 +1,39 @@ app->make(TypeFactory::class); - $type = $factory->getByHandle('page_selector'); - if (!is_object($type)) { - $type = $factory->add('page_selector', t('Page Selector'), $pkg); - /** @var CategoryService $service */ + public function install() + { + $pkg = parent::install(); + /** @var TypeFactory $factory */ + $factory = $this->app->make(TypeFactory::class); + $type = $factory->getByHandle('page_selector'); + if (!is_object($type)) { + $type = $factory->add('page_selector', t('Page Selector'), $pkg); + /** @var CategoryService $service */ $service = $this->app->make(CategoryService::class); - $col = $service->getByHandle('collection')->getController(); - $col->associateAttributeKeyType($type); + $col = $service->getByHandle('collection')->getController(); + $col->associateAttributeKeyType($type); } - } -} \ No newline at end of file + } +} diff --git a/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php b/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php index c774977..49e2b60 100644 --- a/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php +++ b/src/Concrete/Entity/Attribute/Value/Value/PageSelectorValue.php @@ -17,7 +17,7 @@ class PageSelectorValue extends AbstractValue protected $value; /** - * @return integer + * @return int */ public function getValue() { @@ -33,7 +33,7 @@ public function getPageObject() } /** - * @param integer $value + * @param int $value */ public function setValue($value) { @@ -55,4 +55,4 @@ public function __toString() { return (string) $this->getValue(); } -} \ No newline at end of file +}