protected function preFetchData(DataModel $controller, &$response) { $maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 10); $controller->setStart(0); $controller->setLimit($maxPerPage); return parent::preFetchData($controller, $response); }
protected function preFetchData(DataModel $controller, &$response) { $retriever = $controller->getRetriever(); $posts = $retriever->getPosts(); $response = $retriever->getLastResponse(); foreach ($posts as $key => $post) { if (is_object($post) && ($author = $post->getAuthor()) && !in_array($author, $this->authors)) { $this->authors[] = $author; $controller->getUser($author); } } }
public function run() { $parameterId = 2; $dataModel = new DataModel(); $userModel = new UserModel(); Session::init(); $userId = Session::get('user')['user_id']; $userData = $dataModel->getData($userId, $parameterId); $users = $userModel->run(); $var = ['userData' => $userData, 'users' => $users]; // Session::init(); // print_r($_SESSION); $this->view->render('dashboard.twig', $var); }
public function handleItem($gridField, $request) { $controller = $gridField->getForm()->Controller(); $record = $gridField->getList()->byId($request->param("ID")); $handler = Object::create('GridFieldExpandableForm_ItemRequest', $gridField, $this, $record, $controller, 'DetailForm', $this->formorfields); return $handler->handleRequest($request, DataModel::inst()); }
protected function fireSilverstripeCommand($url) { $this->bootSilverstripe($url); $_SERVER['REQUEST_URI'] = BASE_URL . '/' . $url; // Direct away - this is the "main" function, that hands control to the appropriate controller \Director::direct($url, \DataModel::inst()); }
function __construct($r) { parent::__construct($r); $this->tablename = 'cmnts'; $this->addProjection('*'); $this->more = "order by commentid desc"; }
function __construct($r) { parent::__construct($r); $this->tablename = 'msgs'; $this->addProjection('*'); $this->more = "order by msgid desc limit 20"; }
/** * */ public static function load() { if (!DataModel::$s_datamodel_instance_cache) { DataModel::$s_datamodel_instance_cache = new Datamodel(); } return DataModel::$s_datamodel_instance_cache; }
/** * @test */ public function form_appears_and_saves() { Config::inst()->update('Controller', 'extensions', array('QuickFeedbackExtension')); $controller = new TestController(); $result = $controller->handleRequest(new SS_HTTPRequest('GET', 'form_appears_and_saves'), DataModel::inst()); $body = $result->getBody(); $this->assertContains('Form_QuickFeedbackForm', $body); $this->assertContains('Form_QuickFeedbackForm_Rating', $body); $this->assertContains('Form_QuickFeedbackForm_Comment', $body); preg_match('/action="([^"]+)"/', $body, $action); if (!count($action)) { $this->fail('No form action'); } preg_match('/name="SecurityID" value="([^"]+)"/', $body, $token); if (!count($action)) { $this->fail('No token'); } $parts = explode('/', $action[1]); $action = end($parts); $time = time(); $data = ['SecurityID' => $token[1], 'Rating' => '0', 'Comment' => 'comment at ' . $time]; $controller->handleRequest(new SS_HTTPRequest('POST', $action, array(), $data), DataModel::inst()); $existing = Feedback::get()->filter('Comment', 'comment at ' . $time)->first(); if (!$existing) { $this->fail('Record missing'); } }
public function __construct($pks = array(), $load = false) { parent::__construct($this->table, $pks); if ($load === true) { $this->load(); } }
public function getFields() { $fields = parent::getFields(); $fields[] = array('attribute' => 'key_name', 'label' => 'Name', 'type' => 'string'); $fields[] = array('attribute' => 'descr', 'label' => 'Description', 'type' => 'string'); return $fields; }
public function handleManagePresentation(SS_HTTPRequest $r) { if ($presentation = Presentation::get()->byID($r->param('ID'))) { $request = PresentationAPI_PresentationRequest::create($presentation, $this); return $request->handleRequest($r, DataModel::inst()); } return $this->httpError(404, "Presentation " . $r->param('ID') . " not found"); }
public function addfield($gridField, $request) { $controller = $gridField->getForm()->Controller(); $record = singleton('MetadataField'); $handler = Object::create('MetaDataFieldAddForm_ItemRequest', $gridField, $this, $record, $controller, $this->name); $handler->setTemplate($this->template); return $handler->handleRequest($request, DataModel::inst()); }
protected function getFeed($feed = null) { $feed = isset($this->feeds[$feed]) ? $feed : $this->getDefaultSection(); $feedData = $this->feeds[$feed]; $modelClass = isset($feedData['MODEL_CLASS']) ? $feedData['MODEL_CLASS'] : self::$defaultModel; $controller = DataModel::factory($modelClass, $feedData); return $controller; }
/** * @covers \Heystack\Ecommerce\Controller\InputController::__construct */ public function testProcessDoesProduceExpectedOutput() { $controller = new InputController($inputMock = $this->getMock('Heystack\\Core\\Input\\Handler'), $outptuMock = $this->getMock('Heystack\\Core\\Output\\Handler')); $request = new \SS_HTTPRequest('GET', '/input/process/test/'); $inputMock->expects($this->once())->method('process')->with('test', $request)->will($this->returnValue(['success' => true])); $outptuMock->expects($this->once())->method('process')->with('test', $controller, ['success' => true])->will($this->returnValue('yay')); $response = $controller->handleRequest($request, \DataModel::inst()); $this->assertEquals('yay', $response->getBody()); }
public function getFields() { $fields = parent::getFields(); $fields[] = array('attribute' => 'name', 'label' => 'Name', 'type' => 'string'); $fields[] = array('attribute' => 'email', 'label' => 'Email', 'type' => 'string'); $fields[] = array('attribute' => 'login', 'label' => 'Login', 'type' => 'string'); $fields[] = array('attribute' => 'password', 'label' => 'Password', 'type' => 'string'); return $fields; }
private function handleRequest() { $result['message'] = ''; // $job = isset($this->submit['action']) ? $this->submit['action'] : ''; $job = $this->request->get('action'); switch ($job) { case 'save': $parameterId = 2; $dataModel = new DataModel(); $userId = Session::get('user')['user_id']; $dataModel->saveData($userId, $parameterId, $this->request->get('heart_rate')); // $dataModel->saveData(1, $this->submit['req']['heart_rate']); $result['message'] = 'Your data has been saved.'; break; default: } return $result; }
public function getFields() { $fields = parent::getFields(); $fields[] = array('attribute' => 'name', 'label' => 'Name', 'type' => 'string'); $fields[] = array('attribute' => 'text_value', 'label' => 'Value', 'type' => 'text'); $fields[] = array('attribute' => 'descr', 'label' => 'Description', 'type' => 'string'); $fields[] = array('attribute' => 'property', 'label' => 'Properties', 'type' => 'array'); return $fields; }
/** * Tests to make sure short codes get translated to full paths. * */ public function testRedirectingMapping() { DocumentationPermalinks::add(array('foo' => 'en/framework/subfolder/foo', 'bar' => 'en/cms/bar')); $this->autoFollowRedirection = false; $v = new DocumentationViewer(); $response = $v->handleRequest(new SS_HTTPRequest('GET', 'foo'), DataModel::inst()); $this->assertEquals('301', $response->getStatusCode()); $this->assertContains('en/framework/subfolder/foo', $response->getHeader('Location')); }
/** * @depends testSerializeWithExtraData * @covers \Heystack\Core\State\Traits\DataObjectSerializableTrait::unserialize */ public function testUnserializeWithExtraData($data) { $t = $this->getMockForAbstractClass(__NAMESPACE__ . '\\TestDataObjectSerializableTraitWithExtraData'); $t->expects($this->once())->method('setExtraData')->with(['test' => true]); $t->unserialize($data); $this->assertAttributeEquals(get_class($t), 'class', $t); $this->assertAttributeEquals(['test' => true], 'record', $t); $this->assertAttributeEquals(\DataModel::inst(), 'model', $t); }
public function initializeForCommand() { switch ($this->command) { case 'notice': $response = null; $responseVersion = 1; if ($this->getOptionalModuleVar('BANNER_ALERT', false, 'notice')) { $noticeData = $this->getOptionalModuleSection('notice'); if ($noticeData) { $response = array('notice' => '', 'moduleID' => null, 'link' => $this->getOptionalModuleVar('BANNER_ALERT_MODULE_LINK', false, 'notice')); // notice can either take a module or data model class or retriever class. The section is passed on. It must implement the HomeAlertInterface interface if (isset($noticeData['BANNER_ALERT_MODULE'])) { $moduleID = $noticeData['BANNER_ALERT_MODULE']; $controller = WebModule::factory($moduleID); $response['moduleID'] = $moduleID; $string = "Module {$moduleID}"; } elseif (isset($noticeData['BANNER_ALERT_MODEL_CLASS'])) { $controller = DataModel::factory($noticeData['BANNER_ALERT_MODEL_CLASS'], $noticeData); $string = $noticeData['BANNER_ALERT_MODEL_CLASS']; } elseif (isset($noticeData['BANNER_ALERT_RETRIEVER_CLASS'])) { $controller = DataRetriever::factory($noticeData['BANNER_ALERT_RETRIEVER_CLASS'], $noticeData); $string = $noticeData['BANNER_ALERT_RETRIEVER_CLASS']; } else { throw new KurogoConfigurationException("Banner alert not properly configured"); } if (!$controller instanceof HomeAlertInterface) { throw new KurogoConfigurationException("{$string} does not implement HomeAlertModule interface"); } $response['notice'] = $controller->getHomeScreenAlert(); } } $this->setResponse($response); $this->setResponseVersion($responseVersion); break; case 'modules': if ($setcontext = $this->getArg('setcontext')) { Kurogo::sharedInstance()->setUserContext($setcontext); } $responseVersion = 2; $response = array('primary' => array(), 'secondary' => array(), 'customize' => $this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true), 'displayType' => $this->getOptionalModuleVar('display_type', 'springboard')); $allmodules = $this->getAllModules(); $navModules = Kurogo::getSiteSections('navigation', Config::APPLY_CONTEXTS_NAVIGATION); foreach ($navModules as $moduleID => $moduleData) { if ($module = Kurogo::arrayVal($allmodules, $moduleID)) { $title = Kurogo::arrayVal($moduleData, 'title', $module->getModuleVar('title')); $type = Kurogo::arrayVal($moduleData, 'type', 'primary'); $visible = Kurogo::arrayVal($moduleData, 'visible', 1); $response[$type][] = array('tag' => $moduleID, 'title' => $title, 'visible' => (bool) $visible); } } $this->setResponse($response); $this->setResponseVersion($responseVersion); break; default: $this->invalidCommand(); } }
/** * @return string */ public function process() { if ($this->siteUrl) { ob_start(); Director::direct($this->url, \DataModel::inst()); return ob_get_clean(); } else { return @file_get_contents($this->url); } }
/** * Retrieve the correct error page for the current multisite instance. * @param integer * @param SS_HTTPRequest * @throws SS_HTTPResponse_Exception */ public function onBeforeHTTPError($code, $request) { $errorPage = ErrorPage::get()->filter(array('ErrorCode' => $code, 'SiteID' => Multisites::inst()->getCurrentSiteId()))->first(); if ($errorPage) { Requirements::clear(); Requirements::clear_combined_files(); $response = ModelAsController::controller_for($errorPage)->handleRequest($request, DataModel::inst()); throw new SS_HTTPResponse_Exception($response, $code); } }
public function getFields() { $fields = parent::getFields(); $fields[] = array('attribute' => 'name', 'label' => 'Name', 'type' => 'string'); $fields[] = array('attribute' => 'create_date', 'label' => 'Creation Date', 'type' => 'string', 'readonly' => true); $fields[] = array('attribute' => 'modify_date', 'label' => 'Modify Date', 'type' => 'string', 'readonly' => true); $fields[] = array('attribute' => 'owner_user', 'label' => 'Owner User', 'type' => 'string', 'readonly' => true); $fields[] = array('attribute' => 'property', 'label' => 'Property', 'type' => 'array'); $fields[] = array('attribute' => 'objects', 'label' => 'Object', 'type' => 'array'); return $fields; }
protected function getFeed($feed) { if (!isset($this->feeds[$feed])) { throw new KurogoException(get_class($this) . ": Invalid Album id: {$feed}"); return false; } $feedData = $this->feeds[$feed]; $modelClass = isset($feedData['MODEL_CLASS']) ? $feedData['MODEL_CLASS'] : 'PhotosDataModel'; $controller = DataModel::factory($modelClass, $feedData); return $controller; }
protected function getFeed($feed = null) { $feed = isset($this->feeds[$feed]) ? $feed : $this->getDefaultSection(); $feedData = $this->feeds[$feed]; $modelClass = isset($feedData['MODEL_CLASS']) ? $feedData['MODEL_CLASS'] : self::$defaultModel; $controller = DataModel::factory($modelClass, $feedData); $maxResultsOption = $this->pagetype == 'tablet' ? 'MAX_TABLET_RESULTS' : 'MAX_RESULTS'; $maxPerPage = $this->getOptionalModuleVar($maxResultsOption, 20); $controller->setLimit($maxPerPage); return $controller; }
public function getFields() { $fields = parent::getFields(); $fields[] = array('attribute' => 'name', 'label' => 'Name', 'type' => 'string'); $fields[] = array('attribute' => 'email', 'label' => 'Email', 'type' => 'string'); $fields[] = array('attribute' => 'company', 'label' => 'Company', 'type' => 'string'); $fields[] = array('attribute' => 'devkey', 'label' => 'Developer Key', 'type' => 'string', 'readonly' => true); $fields[] = array('attribute' => 'weblink', 'label' => 'Web', 'type' => 'string'); $fields[] = array('attribute' => 'descr', 'label' => 'Description', 'type' => 'string'); return $fields; }
public function testTemplateFunctionsForOtherSteps() { $summaryRequest = new SS_HTTPRequest('GET', "summary"); $this->checkout = new CheckoutPage_Controller(); $this->checkout->handleRequest($summaryRequest, DataModel::inst()); //change to summary step $this->assertTrue($this->checkout->StepExists('summary')); $this->assertFalse($this->checkout->IsPastStep('summary')); $this->assertTrue($this->checkout->IsCurrentStep('summary')); $this->assertFalse($this->checkout->IsFutureStep('summary')); $this->assertFalse($this->checkout->StepExists('nosuchstep')); }
public function setAttributes($attr) { parent::setAttributes($attr); $props = $attr['property']; if (isset($props) && is_array($props)) { foreach ($props as $propertyAttr) { $property = new Property(); $property->setAttributes($propertyAttr); $this->property[] = $property; } } }
/** * * @param type $gridField * @param type $request * @return GridFieldDetailForm_ItemRequest */ public function handleItem($gridField, $request) { $controller = $gridField->getForm()->Controller(); if (is_numeric($request->param('ID'))) { $record = $gridField->getList()->byId($request->param("ID")); } else { $record = Object::create($gridField->getModelClass()); } $class = $this->getItemRequestClass(); $handler = Object::create($class, $gridField, $this, $record, $controller, $this->name); $handler->setTemplate($this->template); return $handler->handleRequest($request, DataModel::inst()); }