/** * Create new task and relation(s) * * @param CreateTaskRequest $request * * @return mixed */ public function store(CreateTaskRequest $request) { $input = $request->only('body', 'date', 'taskable'); $task = $this->task->create(['body' => $input['body'], 'date' => $input['date']]); foreach ($input['taskable'] as $taskable => $id) { $task->{$taskable}()->attach($id); } }
/** * Notifies about an alarm through Horde_Notification. * * @param array $alarm An alarm hash. */ public function notify(array $alarm) { $notification = $this->_notification->create(); $notification->push($alarm['title'], 'horde.alarm', array('alarm' => $alarm)); if (!empty($alarm['params']['notify']['sound']) && !isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) { $notification->attach('audio'); $notification->push($alarm['params']['notify']['sound'], 'audio'); $this->_soundPlayed[$alarm['params']['notify']['sound']] = true; } }
/** * Create new comment and relation(s) * * @param CreateCommentRequest $request * * @return mixed */ public function store(CreateCommentRequest $request) { $input = $request->only('body', 'commentable'); $comment = $this->comment->create(['body' => $input['body']]); foreach ($input['commentable'] as $commentable => $id) { $comment->{$commentable}()->attach($id); } if (!$request->ajax()) { return back(); } }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { global $g_ado_db; $query = "DELETE FROM Languages WHERE Name = '" . $this->m_languageData['Name'] . "'"; $g_ado_db->Execute($query); $this->m_languageObj = new Language(); $this->m_languageObj->create($this->m_languageData); $this->m_metaLanguageObj = new MetaLanguage($this->m_languageObj->getLanguageId()); }
/** * Push a message onto the end of the queue * * @param array $message * @return mixed */ public function push($message) { $mid = $this->implement->create($message); if ($mid === false || $this->implement->error()) { $this->error = $this->implement->error(); return false; } if ($this->monitor->isReady()) { $this->monitor->update(); } return $mid; }
/** * Execute action * * @return \Magento\Backend\Model\View\Result\Redirect * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { try { $collection = $this->filter->getCollection($this->collectionFactory->create()); return $this->massAction($collection); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath($this->redirectUrl); } }
/** * Sort by column * * @param string $name * @param string $column * * @return response */ public function sort($name, $column) { if ($this->sorter->existsForLoggedUser($name)) { $sorter = $this->sorter->getByNameAndLoggedUser($name); if ($sorter->column == $column) { $this->sorter->toggleDesc($sorter->id); return redirect()->back(); } $this->sorter->deleteByNameAndLoggedUser($name); } $this->sorter->create(['name' => $name, 'column' => $column]); return redirect()->back(); }
/** * Creates the cache file. * * @since 6.2.0 * @param int|string $key * Unique key of the cache file. * @param mixed $data * Data that should be cached. * @param string $namespace * Optional. Where the cache contents are namespaced. * @param int $ttl * Time to live sets the life of the cache file. */ public function create($key, $data, $namespace = 'default', $ttl = 0) { if (empty($namespace)) { $namespace = 'default'; } return $this->_cache->create($key, $data, $namespace, (int) $ttl); }
/** * Find a Ip in the data source * * @param string $ip * @return object|null */ public function addToList($whitelist, $ip) { $this->model->unguard(); $model = $this->model->create(array('ip_address' => $ip, 'whitelisted' => $whitelist)); $this->cacheRemember($model); return $model; }
protected function import_tweet(\stdClass $tweet) { $tweet = $this->get_real_tweet($tweet); $this->post->set_tweet($tweet); $post_id = $this->post->create(); return $post_id; }
/** * @param $pageId * @param $emails * * @return mixed */ public function createEmailAlerts($pageId, $emails) { $base_url = $this->url_components['server'] . $this->url_components['6.0'] . "profiles/%d/pages/%d/email_alerts"; $url = sprintf($base_url, $this->url_components['profiles'], $pageId); $this->api->setupRequest($this->base_params['ACCESS_TOKEN'], $emails); return $this->api->create($url); }
/** * Returns principal details. * * @param string $user A user name. * * @return array A hash with user information. */ protected function _getUserInfo($user) { if ($user == '-system-') { return array('uri' => 'principals/-system-', '{DAV:}displayname' => Horde_Dav_Translation::t("System")); } $identity = $this->_identities->create($user); return array('uri' => 'principals/' . $user, '{DAV:}displayname' => $identity->getName(), '{http://sabredav.org/ns}email-address' => (string) $identity->getDefaultFromAddress()); }
public function testBindingByName() { $post = new Record(array('model' => $this->_model, 'data' => array('author_id' => '2', 'title' => 'New post', 'body' => 'New post body'))); $info = new Record(array('model' => $this->_model2, 'data' => array('section' => 'New post section', 'notes' => 'New post notes'))); $this->form->create(compact('post', 'info')); $this->assertEqual($post, $this->form->binding('post')); $this->assertEqual($info, $this->form->binding('info')); }
/** * Event: new_faq * Triggered after FAQ addition * @param xhelpTicket $ticket Ticket used as base for FAQ * @param xhelpFaq $faq FAQ that was added */ function new_faq($ticket, $faq) { global $xoopsUser; $logMessage =& $this->_hLog->create(); $logMessage->setVar('uid', $xoopsUser->getVar('uid')); $logMessage->setVar('ticketid', $ticket->getVar('id')); $logMessage->setVar('action', sprintf(_XHELP_LOG_NEWFAQ, $faq->getVar('subject'))); return $this->_hLog->insert($logMessage, true); }
public function testFormCreationWithNoContext() { $this->form = new Form(array('context' => new MockFormRenderer(array( 'request' => new Request(array('base' => '/bbq')) )))); $result = $this->form->create(null, array('url' => '/foo')); $this->assertTags($result, array('form' => array( 'action' => "/bbq/foo", 'method'=> "post" ))); }
/** * Save should create or update based on object existance. * * @return int */ public function save() { if ($this->data_store) { if ($this->get_id()) { $this->data_store->update($this); } else { $this->data_store->create($this); } return $this->get_id(); } }
public function testErrorWithCustomConfiguration() { $this->form->config(array('error' => array('class' => 'custom-error-class'))); $record = new Record(); $record->errors(array('name' => array('Please enter a name'))); $this->form->create($record); $result = $this->form->field('name'); $expected = '<div><label for="name">Name</label><input type="text" name="name" />'; $expected .= '<div class="custom-error-class">Please enter a name</div></div>'; $this->assertEqual($expected, $result); }
/** * Saves email data in the database * * @param mixed $content Either an array of text lines, or a string with contents * @param string $template Template to use when sending email * @param string $layout Layout to use to enclose email body * @return boolean Success */ function _db($content = null, $template = null, $layout = null) { // Process mail content if ($template) { $this->template = $template; } if ($layout) { $this->layout = $layout; } if (is_array($content)) { $content = implode("\n", $content) . "\n"; } $this->htmlMessage = $this->textMessage = null; if ($content) { if ($this->sendAs === 'html') { $this->htmlMessage = $content; } elseif ($this->sendAs === 'text') { $this->textMessage = $content; } else { $this->htmlMessage = $this->textMessage = $content; } } $message = $this->_wrap($content); if ($this->template === null) { $message = $this->_formatMessage($message); } else { $message = $this->_render($message); } // Save in db $data = array('from' => $this->from, 'replyTo' => $this->replyTo, 'readReceipt' => $this->readReceipt, 'return' => $this->return, 'headers' => serialize($this->headers), 'additionalParams' => serialize($this->additionalParams), 'attachments' => serialize($this->attachments), 'subject' => $this->subject, 'textMessage' => $this->textMessage, 'htmlMessage' => $this->htmlMessage); if (is_array($this->to)) { foreach ($this->to as $to) { $all[] = array_merge(array('to' => $to), $data); } return $this->QueuedEmail->saveAll($all); } else { $data = array_merge(array('to' => $this->to), $data); $this->QueuedEmail->create($data); return $this->QueuedEmail->save() == true; } }
/** * Saves the log data previously stored into $this->logData * * @access public * @return boolean True if data was saved, false if was not */ public function log() { if (!$this->loggable || $this->saved) { return false; } $this->saved = true; if (!empty($this->logData[$this->Model->alias]['extra_fields'])) { $this->logData[$this->Model->alias]['extra_fields'] = serialize($this->logData[$this->Model->alias]['extra_fields']); } $this->Model->create($this->logData); return $this->Model->save(); }
/** * Write data for key into cache * * @param string $key Identifier for the data * @param mixed $data Data to be cached * @param integer $duration How long to cache the data, in seconds * @return boolean True if the data was successfully cached, false on failure * @access public */ public function write($key, $data, $duration) { // if (isset($this->settings['serialize'])) { $data = serialize($data); // } if (!$data) { return false; } $cache_obj = $this->model->create(); $cache_obj->setVar($this->model->keyname, $key); $cache_obj->setVar($this->fields[0], $data); $cache_obj->setVar($this->fields[1], time() + $duration); return $this->model->insert($cache_obj); }
/** * Armazena um novo registro no database * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ protected function store(Request $request) { // Varre o array procurando valores vazios, para settar como nulos $post = array_map(function ($dataPost) { return $dataPost == '' ? null : $dataPost; }, $request->only(array_keys($this->model->_getConfig('form_add')))); // Novo filtro no array postado, pq quando grava, nao importa valores nulos! // Esta regra não se aplica para update! $post = array_filter($post); // Pega o id inserido no momento $id = $this->model->create($post)->{$this->model->primaryKey}; // Redireciona para a index, com uma mensagem de inserção return redirect()->action($this->_getController() . "@getIndex")->with(array('status' => 'success', 'message' => "Register ({$id}) Inserted!")); }
public function testFormDataBinding() { $record = new Record(array('model' => 'lithium\\tests\\mocks\\template\\helper\\MockFormPost', 'data' => array('id' => '5', 'author_id' => '2', 'title' => 'This is a saved post', 'body' => 'This is the body of the saved post'))); $base = trim($this->context->request()->env('base'), '/') . '/'; $base = $base == '/' ? $base : '/' . $base; $result = $this->form->create($record); $this->assertTags($result, array('form' => array('action' => "{$base}posts/add", 'method' => 'POST'))); $result = $this->form->text('title'); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'title', 'value' => 'This is a saved post'))); $result = $this->form->end(); $this->assertTags($result, array('/form')); $result = $this->form->text('title'); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'title'))); }
/** * add 添加 * @return boolean | */ public function add($entity) { // dump($entity); $result = $this->model->create($entity, 1); if ($result === false) { $error = $this->model->getError(); return $this->apiReturnErr($error); } else { $result = $this->model->add(); if ($result === false) { return $this->apiReturnErr($this->model->getDbError()); } return $this->apiReturnSuc($result); } }
/** * testSave * * @retun void * @access public */ function testSave() { $data = array('Produto' => array('nome' => 'Produto 4', 'valor' => '5.000,00')); $this->Produto->create(); $this->assertTrue($this->Produto->save($data)); $id = $this->Produto->getInsertId(); $data['Produto']['id'] = $id; $result = $this->Produto->read(null, $id); $this->assertEqual($data, $result); $result = $this->Produto->read(array('valor'), $id); $this->assertEqual(array('Produto' => array('valor' => '5.000,00')), $result); $result = $this->Produto->read(array('nome'), $id); // Verificar se dá erro quando não vem o campo $this->assertEqual(array('Produto' => array('nome' => 'Produto 4')), $result); }
/** * This method tests the processing of the saved search * */ public function testRunSavedSearch_KTAPI() { // create the document object $randomFile = $this->createRandomFile(); $document = $this->root->add_document('title.txt', 'name_1.txt', 'Default', $randomFile); @unlink($randomFile); $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); $response = $this->ktapi->run_saved_search($searchID); $this->assertIsA($response, 'array'); $this->assertEqual($response['status_code'], 0); $this->assertNoErrors(); $document->delete('Testing'); $document->expunge(); $this->savedSearch->delete($searchID); }
/** * Test for create() method. */ public function testCreate() { global $g_ado_db; $this->clear(); $this->alias = new Alias(); $aliasData = array('Name'=>$this->testName, 'IdPublication'=>$this->testPublicationId); $this->alias->create($aliasData); $query = "SELECT COUNT(*) FROM Aliases WHERE Name = '" . $this->testName . "' AND IdPublication = " . $this->testPublicationId; $this->assertNotEquals(0, $g_ado_db->GetOne($query)); $this->assertNotEquals(0, $this->alias->getId()); $this->assertEquals($this->testName, $this->alias->getName()); $this->testAliasId = $this->alias->getId(); }
/** * Create a new cookie * * @access public */ public function create() { $ci = get_instance(); //don't set a cookie if it's url segment has been blacklisted in config if (in_array($ci->uri->segment(1), $ci->config->item('cookie_blacklist'))) { return false; } //echo $this->name; $cookie = $this->cookie->create(); $cookie['id'] = sha1(time() . $this->randomString . $this->salt); $cookie['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $cookie['ip'] = $_SERVER['REMOTE_ADDR']; $cookie['last_accessed'] = time(); setcookie($this->name, $cookie['id'], $this->expires, $this->domain); $this->cookie->save($cookie); log_message('debug', "cookie set " . $ci->uri->segment(1)); }
/** * API compatible create method to allow saving * @param Model $model * @param null $fields * @param null $values * @return bool */ public function create(Model $model, $fields = null, $values = null) { $data = array_combine($fields, $values); if (array_key_exists('Id', $data)) { $response = $this->sfUpdate($data, $model->name); return $response; } $data = (object) $data; try { $response = $this->client->create(array($data), $model->name); $this->log($data); } catch (Exception $e) { $response->errorMessages = array($e->faultstring, $this->client->getLastRequest()); $this->log("Error in Create: " . $response->errorMessages); return false; } return $response; //This should return the ID of the created record? }
/** * allows for adding an article */ public function add() { if ($this->user->isLoggedIn()) { if (Input::exists()) { $article_title = Input::get('title'); $article_body = Input::get('body'); // validation $this->validator->validate(['title' => [$article_title, 'required|max(100)'], 'body' => [$article_body, 'required']]); if ($this->validator->passes()) { // create the article, then insert it to the database $this->article->create($article_title, $article_body); header('Location: /admin/index'); } } $this->view('admin/add', ['validation_errors' => $this->validator->errors()]); } else { // user is not logged in header('Location: /admin/auth'); } }
/** * Make a new {@link XoopsConfigOption} * * @return object {@link XoopsConfigOption} */ function &createConfigOption() { $inst =& $this->_oHandler->create(); return $inst; }