public function smartBlockGenerateAction() { $request = $this->getRequest(); $params = $request->getPost(); //make sure block exists try { $bl = new Application_Model_Block($params['obj_id']); $form = new Application_Form_SmartBlockCriteria(); $form->startForm($params['obj_id']); if ($form->isValid($params)) { $result = $bl->generateSmartBlock($params['data']); $this->_helper->json->sendJson(array("result" => 0, "html" => $this->createFullResponse($bl, true, true))); } else { $this->view->obj = $bl; $this->view->id = $bl->getId(); $this->view->form = $form; $viewPath = 'playlist/smart-block.phtml'; $result['html'] = $this->view->render($viewPath); $result['result'] = 1; $this->_helper->json->sendJson($result); } } catch (BlockNotFoundException $e) { $this->playlistNotFound('block', true); } catch (Exception $e) { Logging::info($e); $this->playlistUnknownError($e); } }
protected function createFullResponse($obj = null, $isJson = false) { $isBlock = false; $viewPath = 'playlist/playlist.phtml'; if ($obj instanceof Application_Model_Block) { $isBlock = true; $viewPath = 'playlist/smart-block.phtml'; } if (isset($obj)) { $formatter = new LengthFormatter($obj->getLength()); $this->view->length = $formatter->format(); if ($isBlock) { $form = new Application_Form_SmartBlockCriteria(); $form->removeDecorator('DtDdWrapper'); $form->startForm($obj->getId()); $this->view->form = $form; $this->view->obj = $obj; $this->view->id = $obj->getId(); if ($isJson) { return $this->view->render($viewPath); } else { $this->view->html = $this->view->render($viewPath); } } else { $this->view->obj = $obj; $this->view->id = $obj->getId(); $this->view->html = $this->view->render($viewPath); unset($this->view->obj); } } else { $this->view->html = $this->view->render($viewPath); } }