/** * * * @param Builder $query * @return Builder */ public function scopeNewestGrouped($query) { // @todo: find a better way of doing this $newest = \DB::select("select max(id) as id from mail_statistics group by service_message_id"); $newest = collect($newest)->pluck('id'); return $query->whereIn('id', $newest->toArray())->newest(); }
/** * @test */ public function getChartWithNumberOfValuesDifferents() { $mapsWithGroupedValues = $this->goupedListWithDifferentYears(); $years = array(1989, 1992); $xml = str_replace('<?xml version="1.0"?>', '', $this->chartBuilder->build($mapsWithGroupedValues, $years)); $this->assertEquals($this->xml2(), trim($xml)); }
/** * Sort * * @param \Illuminate\Database\Eloquent\Builder $builder * @param string|null $sort Optional sort string * * @return \Illuminate\Database\Query\Builder */ public function scopeSort(Builder $builder, $sort = null) { if ((is_null($sort) || empty($sort)) && Input::has($this->getSortParameterName())) { $sort = Input::get($this->getSortParameterName()); } if (!is_null($sort)) { $sort = explode(',', $sort); foreach ($sort as $field) { $field = trim($field); $order = 'asc'; switch ($field[0]) { case '-': $field = substr($field, 1); $order = 'desc'; break; case '+': $field = substr($field, 1); break; } $field = trim($field); if (in_array($field, $this->getSortable())) { $builder->orderBy($field, $order); } } } }
function calcola_prenotazione_online($user) { $builder = new Builder(); $dispatcher = $builder->build('calcola-online', null, $user, $_REQUEST['rc_sito_parking']); $dispatcher->executeAjax($_REQUEST); $ar_errori = $dispatcher->get_errori(); if (!empty($ar_errori)) { $ar_response['errori'] = $ar_errori; $ar_response['totale_giorni'] = 0; $ar_response['totale_costo'] = 0; return json_encode($ar_response); } $ar_so_selected = null; if ($_REQUEST['so']) { $ar_so_selected = json_decode($_REQUEST['so']); } $ar_data = array('sito_parking' => $_REQUEST['rc_sito_parking'], 'dt_p_iniziale' => $_REQUEST['rc_dt_checkin_checkout_in'], 'ora_p_iniziale' => $_REQUEST['rc_tm_checkin_checkout_in'], 'dt_p_finale' => $_REQUEST['rc_dt_checkin_checkout_out'], 'ora_p_finale' => $_REQUEST['rc_tm_checkin_checkout_out'], 'tipo_parcheggio' => $_REQUEST['rc_tipo_parcheggio'], 'tipo_cliente' => null, 'tipo_automezzo' => $_REQUEST['rc_tp_veicolo_cliente'], 'valore_sct_mag' => null, 'tipo_sct_mag' => null, 'p_online' => true, 'tp_sct_mag_v_p' => null, 'so' => $ar_so_selected, 'sop' => null); $calcoli = new CalcolaCostiStrategy(); $calcoli->set_data($ar_data); $calcoli->calcola(); $ar_response['totale_giorni'] = $calcoli->get_totale_giorni(); $valore_sconto = floatval($calcoli->get_valore_sct_p_online()); $ar_response['totale_costo'] = $calcoli->get_totale_costo() + $valore_sconto; if ($valore_sconto != 0) { $ar_response['totale_scontato'] = $ar_response['totale_costo'] - $valore_sconto; $ar_response['totale_risparmio'] = $ar_response['totale_costo'] - $ar_response['totale_scontato']; } return json_encode($ar_response); }
/** * Search scope * * @param Builder $query * @param string $keywords * @return Builder */ public function scopeSearch($query, $keywords) { //Return search results return $query->where(function ($query) use($keywords) { $query->where('first_name', 'like', $keywords . '%')->orWhere('last_name', 'like', $keywords . '%')->orWhereRaw('CONCAT(first_name, \' \',last_name) like \'' . $keywords . '%\''); }); }
function testToAppShouldHandleEmptyStack() { $b = new Builder(); $a = $b->toApp(); $this->assertInstanceOf('Middleware\\Runner', $a); $env = new \StdClass(); $a->call($env); }
public function build() { if ($this->builder !== null) { $this->builder->build($this->days); } else { return false; } }
/** * Create a new Builder instance. * * @param string $slug * * @return \Zumba\Swivel\Builder * * @see \Zumba\Swivel\ManagerInterface */ public function forFeature($slug) { $this->logger->debug('Swivel - Generating builder for feature "' . $slug . '"'); $builder = new Builder($slug, $this->bucket); $builder->setLogger($this->logger); $this->metrics && $builder->setMetrics($this->metrics); return $builder; }
/** * Add an "on" clause to the join. * * @param string $first * @param string $operator * @param string $second * @param string $boolean * @param bool $where * @return $this */ public function on($first, $operator, $second, $boolean = 'and', $where = false) { $this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where'); if ($where) { $this->query->addBinding($second, 'join'); } return $this; }
/** * Query scope that returns the friendships of a user * * @param Builder $query The query builder object * @param int $userId The ID of the user * @param boolean $confirmed Only show confirmed friendships? Default = true * @return Builder */ public function scopeFriendsOf($query, $userId, $confirmed = true) { if ($confirmed) { $query->whereConfirmed(1); } return $query->where(function ($query) use($userId) { $query->whereSenderId($userId)->orWhere('receiver_id', $userId); }); }
/** * Format a collection of items for our Vue viewmodel. * @param Builder $query * @param int $perPage Number of items to show per page * @return array Ready for JSON array of item data */ public function scopePagedJson($query, $perPage) { $items = $query->orderby('pub_date', 'desc')->paginate($perPage); $json_data = $items->toArray(); unset($json_data['data']); foreach ($items as $item) { $json_data['items'][] = ['date' => $item->pub_date->diffForHumans(), 'source' => $item->source(), 'title' => $item->title, 'categories' => $item->categories, 'link' => $item->link, 'id' => $item->id, 'viewed' => $item->viewed]; } return $json_data; }
public function __call($name, $args) { if ($name === 'onSuccess') { $entity = $this->builder->buildEntity($args[0]); if (!$entity) { return; } $args = array($entity, $args[0]); } return parent::__call($name, $args); }
/** * Test get page layouts config * * @return void */ public function testGetPageLayoutsConfig() { $files1 = ['content layouts_1.xml', 'content layouts_2.xml']; $files2 = ['content layouts_3.xml', 'content layouts_4.xml']; $theme1 = $this->getMockBuilder('Magento\\Theme\\Model\\Theme\\Data')->disableOriginalConstructor()->getMock(); $theme2 = $this->getMockBuilder('Magento\\Theme\\Model\\Theme\\Data')->disableOriginalConstructor()->getMock(); $this->themeCollection->expects($this->any())->method('loadRegisteredThemes')->willReturn([$theme1, $theme2]); $this->fileCollector->expects($this->exactly(2))->method('getFilesContent')->willReturnMap([[$theme1, 'layouts.xml', $files1], [$theme2, 'layouts.xml', $files2]]); $config = $this->getMockBuilder('Magento\\Framework\\View\\PageLayout\\Config')->disableOriginalConstructor()->getMock(); $this->configFactory->expects($this->once())->method('create')->with(['configFiles' => array_merge($files1, $files2)])->willReturn($config); $this->assertSame($config, $this->builder->getPageLayoutsConfig()); }
/** * Method returns models geted by uuid * @param Builder $query * @param array|tring $uuid uuid or list of uuids * @return Collection|Model Single model or collection of models */ public function scopeFindByUuid($query, $uuid) { if (!is_array($uuid)) { if (!Uuid::isValid($uuid)) { throw (new ModelNotFoundException())->setModel(get_class($this)); } return $query->where('uuid', $uuid)->first(); } elseif (is_array($uuid)) { array_map(function ($element) { if (!Uuid::isValid($element)) { throw (new ModelNotFoundException())->setModel(get_class($this)); } }, $uuid); return $query->whereIn('uuid', $uuid)->get(); } }
public function article_edit($opt = array()) { Builder::add_plugin('ckeditor'); $articles_model = $this->model('articles_model'); $contents = array(); if (empty($opt)) { $contents = $articles_model->get_empty(); $contents['article'] = ''; } else { $contents = $articles_model->get_article(reset($opt), next($opt)); $contents['article'] = ''; $path = APPPATH . "views/articles/{$contents['lang']}/{$contents['type']}/{$contents['id']}.php"; if (file_exists($path)) { $contents['article'] = file_get_contents($path); } } if (!empty($contents['id'])) { $contents['image_list'] = array(); $dir = "./modules/images/articles/{$contents['id']}/"; if (!file_exists($dir)) { mkdir($dir); } $include_images = scandir($dir); foreach ($include_images as $name) { if (!is_file($dir . $name) or in_array($name, array('.', '..'))) { continue; } $contents['image_list'][] = str_replace('./', config('settings', 'base_url'), $dir . $name); } } $page = array(); $page['content'] = $this->view('article_edit', $contents, TRUE); $this->view('backend/backend', $page); }
/** * Resolves all the ScopeInterface items into the current Builder. * @return \Illuminate\Database\Query\Builder $query */ public function getBuilder() { $this->query = clone $this->baseQuery; //apply all direct scopes to the query. $this->directScopes->each(function ($scope) { $scope_method = 'apply'; $this->query = $scope->{$scope_method}($this->query); }); //chain all required scopes in "AND" blocks $this->requiredScopes->each(function ($scope) { $scope_method = 'applyAnd'; $this->query = $scope->{$scope_method}($this->query); }); //chain all optional scopes using "OR", nested within a single "AND" block. if ($this->optionalScopes->count()) { $this->query->where(function ($query) { $this->optionalScopes->each(function ($scope) use($query) { $scope_method = 'applyOr'; return $scope->{$scope_method}($query); }); }); } collect([])->merge($this->directScopes)->merge($this->requiredScopes)->merge($this->optionalScopes)->each(function ($scope) { $this->parseScope($scope); }); return $this->query; }
protected function run() { parent::run(); if (!$this->dataDescription->isEmpty()) { $this->getResult()->removeAttribute('empty'); } }
$model = $this->__get_module('__model_list', 'models', $model_name); if (!$model) { return Loader::get_model($model_name); } return $model; } public function widget($name, $options, $return = FALSE) { if (empty($name)) { return ''; } $widget_name = (string) str_replace('/', '__', $name); $widget_path = $name; if (!function_exists($widget_name)) { $path = APPPATH . 'widgets/' . $widget_path . EXT; include_once $path; if (!function_exists($widget_name)) { Log::log_error("Widget does not exist. widgets:[{$widget_name}], path:[{$path}]"); return ''; } } if (!in_array($widget_name, self::$__widget_call_list)) { self::$__widget_call_list[] = $widget_name; //$path = Builder::get_style_path("/widgets/{$widget_path}"); //Builder::set_head($path, 'css'); $widget_path = str_replace('/', '-', $widget_path); Builder::add_css("widgets/{$widget_path}"); Builder::add_js("widgets/{$widget_path}"); //Builder::set_head($path.'_noscript', 'css'); //Builder::set_head("./widgets/{$widget_path}", 'js', TRUE); } $result = $widget_name($options);
/** * @param string $fieldName * @param FieldDescription $fieldInfo * @param bool $fieldValue * @param bool $fieldProperties * @return \DOMElement */ protected function createField($fieldName, FieldDescription $fieldInfo, $fieldValue = false, $fieldProperties = false) { foreach (['nullable', 'pattern', 'message', 'tabName', 'tableName', 'sort', 'customField', 'url', 'separator', 'default'] as $propertyName) { $fieldInfo->removeProperty($propertyName); } return parent::createField($fieldName, $fieldInfo, $fieldValue, $fieldProperties); }
public function querySql($sql, $messageError) { $result = \Meta\Core\Db::query(Builder::replaceSQL($sql))->fetchColumn(); if (!$result) { $this->error = $messageError; } return $result; }
/** * Enqueue control related scripts/styles */ public function enqueue() { parent::enqueue(); wp_enqueue_style('select2', get_template_directory_uri() . '/modules/builder/assets/vendor/select2/select2.css', [], '3.5.2'); wp_enqueue_script('select2', get_template_directory_uri() . '/modules/builder/assets/vendor/select2/select2.min.js', ['jquery'], '3.5.2', true); wp_enqueue_script("customize-controls-{$this->type}", get_template_directory_uri() . "/modules/builder/assets/scripts/controls/customize-controls-{$this->type}.js", ['jquery', 'select2', 'customize-controls'], null, true); wp_localize_script("customize-controls-{$this->type}", 'customizeControlsBuilderPost', ['actions' => ['search' => \Builder::get_ajax_action('customize_control_post_search')], 'nonces' => ['search' => wp_create_nonce()]]); }
/** * Get builder instance * @param $db * @param $name * @return Builder */ public static function init($db, $name) { if (null === self::$_instance) { self::$_instance = new Builder($db, $name); } else { self::$_instance->db($db)->name($name); } return self::$_instance; }
/** * Menu_Builder constructor. * * @param string $title Title menu. * @param integer|float $position Position menu. */ public function __construct($title, $position) { parent::__construct($title); if (!$this->position_is_valid($position)) { $this->position_exception(); } $this->position = $position; $this->settings['position'] = $position; }
/** * Select only those forums the user has access to. * WARNING: Creates JOINs with the forum_threads and the forums table. * * @param Builder $query The Eloquent Builder object * @param User $user User model or null if it's the current client * @return Builder */ public function scopeIsAccessible($query, $user = null) { $query->select('forum_posts.*')->join('forum_threads', 'forum_posts.thread_id', '=', 'forum_threads.id')->join('forums', 'forum_threads.forum_id', '=', 'forums.id'); if (!$user) { $user = user(); } if ($user) { $internal = $user->hasAccess('internal'); $teamIds = DB::table('team_user')->whereUserId($user->id)->lists('team_id'); $teamIds[] = -1; // Add -1 as team ID so the SQL statements (`team_id` in (...)) always has valid syntax return $query->where('internal', '<=', $internal)->where(function ($query) use($teamIds) { $query->whereNull('team_id')->orWhereIn('team_id', $teamIds); }); } else { return $query->whereInternal(0)->whereNull('team_id'); } }
protected function method() { if (Builder::get()) { } $code = array_map(function ($line) { return $line ? ' ' . $line : $line; }, explode("\n", $code)); return sprintf("if (%s)\n{\n%s}\n", implode(' && ', $conditions), $code); }
public function login() { Builder::add_meta('robots', 'none', TRUE); Builder::add_js(array('system/jquery-1.8.3', 'system/wx')); Builder::add_css(array('system/reset', 'pages/frontend')); Builder::add_css('pages/frontend-contacts'); Builder::add_constant(array('command' => 'user', 'action' => 'login')); $this->view('login', array()); }
protected function fetchFromSql($sql) { if (isset($_GET['id'])) { $row = Db::query(Builder::replaceSQL($sql))->fetch(\PDO::FETCH_ASSOC); if ($this->context instanceof \Meta\Builder\Object\Form) { $this->context->setData($row); } } return true; }
/** * Return single item * @return Entity */ public function item() { $item = $this->query->first(); $entityClass = $this->entityClass; if ($item) { return new $entityClass($item->toArray()); } else { return new $entityClass(); } }
/** * get current testable object from collection * * @return \PhpUnitTestGenerator\Testable\Object */ public function current() { $f = $this->fileList->current(); if (is_file($f)) { $object = Builder::buildTestableObjectFromFile($f); /* @var $object \PhpUnitTestGenerator\Testable\Object */ return $object; } return null; }
public function construct() { $this->builder->makeTitle('Greeting'); $this->builder->makeString('From morning to noon'); $this->builder->makeItems(['Good Morning', 'Hello']); $this->builder->makeString('At night'); $this->builder->makeItems(['Good evening', 'Good night', 'Good bye']); $this->builder->close(); }