From c6cfd97b1a70382b0bfe00448c0051c24f824bcf Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Wed, 16 Aug 2017 23:32:54 -0400 Subject: [PATCH 1/2] started on duplicate smartblock functionality --- .../controllers/LibraryController.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index e063ea263..135ce178e 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -9,6 +9,7 @@ class LibraryController extends Zend_Controller_Action $ajaxContext->addActionContext('contents-feed', 'json') ->addActionContext('delete', 'json') ->addActionContext('duplicate', 'json') + ->addActionContext('duplicate-block', 'json') ->addActionContext('delete-group', 'json') ->addActionContext('context-menu', 'json') ->addActionContext('get-file-metadata', 'html') @@ -155,6 +156,7 @@ class LibraryController extends Zend_Controller_Action $menu["duplicate"] = array("name" => _("Duplicate Playlist"), "icon" => "edit", "url" => $baseUrl."library/duplicate"); } elseif ($type === 'block') { $obj = new Application_Model_Block($id); + $menu["duplicate"] = array("name" => _("Duplicate Smartblock"), "icon" => "edit", "url" => $baseUrl."library/duplicate-block"); if (!$obj->isStatic()) { unset($menu["play"]); } @@ -280,6 +282,7 @@ class LibraryController extends Zend_Controller_Action public function duplicateAction(){ $params = $this->getRequest()->getParams(); $id = $params['id']; + Logging::info($params); $originalPl = new Application_Model_Playlist($id); $newPl = new Application_Model_Playlist(); @@ -308,6 +311,24 @@ class LibraryController extends Zend_Controller_Action $newPl->setName(sprintf(_("Copy of %s"), $originalPl->getName())); } + // duplicate smartblock + public function duplicateBlockAction(){ + Logging::info("duplicate smartblock functionality not yet implemented"); + $params = $this->getRequest()->getParams(); + $id = $params['id']; + Logging::info($params); + + $originalBl = new Application_Model_Block($id); + $newBl = new Application_Model_Block(); + $newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $newBl->setDescription($originalBl->getDescription()); + + Logging::info($originalBl->getCriteria()); + //$newBl->saveSmartBlockCriteria(); + $newBl->setName(sprintf(_("Copy of %s"), $originalBl->getName())); + } + + public function contentsFeedAction() { $params = $this->getRequest()->getParams(); From 6a11253ce31ed779babe4771e604b759781f44f7 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 17 Aug 2017 01:21:26 -0400 Subject: [PATCH 2/2] added code to duplicate criteria and type for duplicate smartblock --- .../controllers/LibraryController.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 135ce178e..7ec84ddef 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -322,9 +322,27 @@ class LibraryController extends Zend_Controller_Action $newBl = new Application_Model_Block(); $newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); $newBl->setDescription($originalBl->getDescription()); - - Logging::info($originalBl->getCriteria()); - //$newBl->saveSmartBlockCriteria(); + if ($originalBl->isStatic()) { + $newBl->saveType('static'); + } + else { + $newBl->saveType('dynamic'); + } + // the issue here is that the format that getCriteria provides is different from the format the saveCriteria + // expects due to the useage of startForm. So we either need to write new code that simply copies the database + // or figure out a way to instantiate a form inside of here and save it without modifying it. + //$newBlForm = new Application_Form_SmartBlockCriteria; + //$newBlForm->startForm($id); + $criteria = CcBlockcriteriaQuery::create()->orderByDbCriteria()->findByDbBlockId($id); + foreach ($criteria as &$c) { + $row = new CcBlockcriteria(); + $row->setDbCriteria($c->getDbCriteria()); + $row->setDbModifier($c->getDbModifier()); + $row->setDbValue($c->getDbValue()); + $row->setDbExtra($c->getDbExtra()); + $row->setDbBlockId($newBl->getId()); + $row->save(); + } $newBl->setName(sprintf(_("Copy of %s"), $originalBl->getName())); }