protected function postProcessResponse(Response $response, Controller $controllerInstance) { if (!$response instanceof Renderable || !$this->isInstalled()) { return false; } $response->set('user', $controllerInstance->getUser()->toArray()); $response->set('message', $controllerInstance->getMessage()); $response->set('errorMessage', $controllerInstance->getErrorMessage()); if ($controllerInstance instanceof FrontendController) { $response->set('currency', $controllerInstance->getRequestCurrency()); } // fetch queued EAV data if (class_exists('ActiveRecordModel', false)) { ActiveRecordModel::loadEav(); } $renderer = $this->getRenderer(); if ($response instanceof ActionResponse && !$controllerInstance->isBlocksProcessed) { $controllerInstance->isBlocksProcessed = true; foreach ($renderer->getBlockConfiguration() as $object => $commands) { foreach ($commands as $command) { if ($renderer->isBlock($object)) { $action = $command['action']; switch ($action['command']) { case 'replace': $action['command'] = 'append'; $controllerInstance->removeBlock($object); case 'append': case 'prepend': if (!empty($action['isDefinedBlock'])) { $action = array_merge($action, (array) array_shift($controllerInstance->getBlocks($action['view']))); } $controllerInstance->addBlock($object, $action['call'], $action['view'], $action['command'] == 'prepend'); break; case 'remove': $controllerInstance->removeBlock($object); break; case 'theme': $this->setTheme($action['view']); break; } } } } } }
/** * * @param Controller $controller */ public function actionVoucher($controller) { $message = $controller->getUser()->message(); if (isset($_POST['remove'])) { foreach ($_POST['delete'] as $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->delete('voucher')->where('id = ?')); $sql->execute(array($value)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } $sql = CShop::app()->getDb()->query(QueryBuilder::getInstance()->select()->from('voucher')); $content = '<div class="title">مدیریت کد های تخفیف</div> <div class="content"> <form action="" method="post"> <table> <tr> <th>ردیف</th> <th>کد</th> <th>ارزش</th> <th>زمان پایان</th> <th>تعداد باقی مانده</th> <th>مدیریت</th> <th><a href="#" onclick="check(this)">انتخاب</a></th> </tr>'; $i = 1; while ($item = $sql->fetch()) { $content .= '<tr>'; $content .= '<td>' . $i++ . '</td>'; $content .= '<td>' . $item['code'] . '</td>'; $content .= '<td>' . $item['value'] . '%</td>'; $content .= '<td>' . jDateTime::date(CShop::app()->systemConfig()->timeformat, $item['paymenttime'] ? $item['paymenttime'] : $item['time']) . '</td>'; $content .= '<td>' . $item['maxuse'] . '</td>'; $content .= '<td><a href="' . self::getActionLink('editvoucher', $this->id) . '&vid=' . $item['id'] . '">ویرایش</a></td>'; $content .= '<td><input type="checkbox" name="delete[]" value="' . $item['id'] . '"></td>'; $content .= '</tr>'; } $content .= '</table><div style="text-align: left"><input type="submit" value="ذخیره" name="update"><input type="submit" value="حذف" name="remove"></div></form></div>'; $controller->renderWithContent($content, array('message' => $message)); }
public function testGetUser() { $this->container->expects($this->once())->method('getInstanceOf')->with($this->equalTo('user_service'))->will($this->returnValue($this->getMock('IUser'))); $this->assertThat($this->object->getUser(), $this->isInstanceOf('IUser')); }
/** * * @param Controller $controller */ public function actionPage($controller) { $message = $controller->getUser()->message(); if (isset($_POST['update'])) { foreach ($_POST['order'] as $key => $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->update('page')->set('`order` = ?')->where('id = ?')); $sql->execute(array($value, $key)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } elseif (isset($_POST['remove'])) { foreach ($_POST['delete'] as $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->delete('page')->where('id = ?')); $sql->execute(array($value)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } $sql = CShop::app()->getDb()->query(QueryBuilder::getInstance()->select()->from('page')->order('`order`')); $content = '<div class="title">مدیریت صفحه ها</div> <div class="content"> <form action="" method="post"> <table> <tr> <th>ردیف</th> <th>نام</th> <th>ترتیب</th> <th>مدیریت</th> <th><a href="#" onclick="check(this)">انتخاب</a></th> </tr>'; $i = 1; while ($item = $sql->fetch()) { $content .= '<tr>'; $content .= '<td>' . $i++ . '</td>'; $content .= '<td>' . $item['name'] . '</td>'; $content .= '<td><input type="text" name="order[' . $item['id'] . ']" value="' . $item['order'] . '"></td>'; $content .= '<td><a href="' . self::getActionLink('editpage', $this->id) . '&pid=' . $item['id'] . '">ویرایش</a></td>'; $content .= '<td><input type="checkbox" name="delete[]" value="' . $item['id'] . '"></td>'; $content .= '</tr>'; } $content .= '</table><div style="text-align: left"><input type="submit" value="ذخیره" name="update"><input type="submit" value="حذف" name="remove"></div></form></div>'; $controller->renderWithContent($content, array('message' => $message)); }