_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q27900
DefaultSnippets.email
train
public function email($address, $text=null, $title=null, $class=null) { if (is_null($text)) { $text = $address; } $attributes = $this->getHtmlAttributes(array( 'title'=>$title, 'class'=>$class )); return "<a href='mailto:$address'$attributes>$text</a>"; }
php
{ "resource": "" }
q27901
DefaultSnippets.tel
train
public function tel($nr, $text=null, $class=null) { if (is_null($text)) { $text = $nr; } $attributes = $this->getHtmlAttributes(array('class'=>$class)); return "<a href='tel:$nr'$attributes>$text</a>"; }
php
{ "resource": "" }
q27902
DefaultSnippets.image
train
public function image($image, $width=null, $height=null, $alt=null, $class=null, $link=null, $caption=null, $srcset=null) { $image = $this->getLink($image); $attributes = $this->getHtmlAttributes(array( 'width'=>$width, 'height'=>$height, 'alt'=>$alt, 'caption'=>$caption, 'class'=>$class, 'srcset'...
php
{ "resource": "" }
q27903
DefaultSnippets.file
train
public function file($file, $text=null, $download=null, $class=null) { if (is_null($text)) { // if no text is given, we use the text originally provided by the user $text = $file; } $file = $this->getLink($file); $attributes = $this->getHtmlAttributes(array('class'=>$class)); if ($this->isTrue($downloa...
php
{ "resource": "" }
q27904
DefaultSnippets.youtube
train
public function youtube($link, $width=480, $height=360) { $url = parse_url($link); if (!array_key_exists('query', $url)) { return ""; } parse_str($url['query'], $query); $is_playlist = array_key_exists('list', $query); if ($is_playlist) { $playlist_id = $query['list']; $embed_url = "//www.youtube.c...
php
{ "resource": "" }
q27905
DefaultSnippets.vimeo
train
public function vimeo($link, $width=480, $height=360, $portrait=true, $title=true, $byline=true) { $matches = array(); $regexp = '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*(?\'video_id\'[0-9]{6,11})[?]?.*/'; if (preg_match_all($regexp, $link, $matches)) { if (array_key_exists('video_id', $matche...
php
{ "resource": "" }
q27906
DefaultSnippets.twitter
train
public function twitter($what, $text=null, $class=null) { if (is_null($text)) { $text = $what; } $attributes = $this->getHtmlAttributes(array('class'=>$class)); if (substr($what,0,1)=='@') { $link = "https://www.twitter.com/" . ltrim($what, '@'); } elseif (substr($what,0,1)=='#') { $parts = explode...
php
{ "resource": "" }
q27907
DefaultSnippets.gist
train
public function gist($link, $file=null) { $matches = array(); if (preg_match('/[0-9]+/', $link, $matches)>0) { $gist_id = $matches[0]; $link = "https://gist.github.com/$gist_id.js"; if (!is_null($file)) { $link .= "?file=" . urlencode($file); } } return "<script src='$link'></script>"; }
php
{ "resource": "" }
q27908
Producer.onResponse
train
public function onResponse(Connection $conn, $bytes) { $this->onPublishResponse($conn, $bytes); if ($bytes === "CLOSE_WAIT") { // nsqd ack客户端的StartClose, 准备关闭 // 可以假定不会再收到任何nsqd的消息 $conn->tryClose(); } }
php
{ "resource": "" }
q27909
Producer.onClose
train
public function onClose(Connection $conn) { $this->onPublishResponse($conn, "CONN_CLOSED", new NsqException("connection close, maybe disposable connection timeout")); if (!$conn->isDisposable()) { $this->lookup->removeConnection($conn); $remainConnNum = count($this->getNsqd...
php
{ "resource": "" }
q27910
CartPostage.postage
train
public function postage($params, $content, $template, &$repeat) { if (!$repeat) { return (null !== $this->countryId) ? $content : ""; } $customer = $this->getCurrentRequest()->getSession()->getCustomerUser(); /** @var Address $address */ /** @var Country $country...
php
{ "resource": "" }
q27911
CartPostage.getDeliveryInformation
train
protected function getDeliveryInformation(Customer $customer = null) { $address = null; // get the selected delivery address if (null !== $addressId = $this->getCurrentRequest()->getSession()->getOrder()->getChoosenDeliveryAddress()) { if (null !== $address = AddressQuery::create...
php
{ "resource": "" }
q27912
CartPostage.getCheapestDelivery
train
protected function getCheapestDelivery(Address $address = null, Country $country = null) { $cart = $this->getCurrentRequest()->getSession()->getSessionCart(); $deliveryModules = ModuleQuery::create() ->filterByActivate(1) ->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Crit...
php
{ "resource": "" }
q27913
AccioQuery.createVirtualColumns
train
public static function createVirtualColumns(string $tableName, string $column, array $virtualColumns, bool $isJson = true) { if(Schema::hasTable($tableName)) { Schema::table( $tableName, function ($table) use ($tableName, $column, $virtualColumns, $isJson) { ...
php
{ "resource": "" }
q27914
AccioQuery.deleteColumn
train
public static function deleteColumn(string $tableName, string $column) { if(Schema::hasTable($tableName)) { Schema::table( $tableName, function ($table) use ($tableName, $column) { if(Schema::hasColumn($tableName, $column)) { $table->dr...
php
{ "resource": "" }
q27915
Consumer.onConnect
train
public function onConnect(Connection $conn) { // 加入新连接重新调整所有连接rdy状态 $conn->setDelegate($this); $conn->writeCmd(Command::subscribe($this->topic, $this->channel)); $this->maybeUpdateRDY($conn); }
php
{ "resource": "" }
q27916
Consumer.onMessage
train
public function onMessage(Connection $conn, Message $msg) { $this->totalRdyCount--; $this->stats["messagesReceived"]++; yield $this->handleMessage($msg); // 收到消息后更新rdy // 李文告知不需要每次收到消息就调整RDY // $this->maybeUpdateRDY($conn); }
php
{ "resource": "" }
q27917
PageGenerator.resolveRouteOptions
train
private function resolveRouteOptions(Route $route, $routeName) { if (null === $cmsOptions = $route->getOption('_cms')) { throw new \InvalidArgumentException(sprintf('Route "%s" does not have "_cms" defaults attributes.', $routeName)); } $path = $route->getPath(); $dynam...
php
{ "resource": "" }
q27918
PageGenerator.gatherRoutesDefinitions
train
private function gatherRoutesDefinitions() { $route = $this->findRouteByName($this->homeRouteName); $this->homeDefinition = new RouteDefinition($this->homeRouteName, $this->resolveRouteOptions($route, $this->homeRouteName)); /** @var Route $route */ foreach ($this->routes as $name =...
php
{ "resource": "" }
q27919
PageGenerator.createRouteDefinition
train
private function createRouteDefinition($routeName, Route $route) { if (null === $definition = $this->findRouteDefinitionByRouteName($routeName)) { $definition = new RouteDefinition($routeName, $this->resolveRouteOptions($route, $routeName)); if (null === $parentRouteName = $definitio...
php
{ "resource": "" }
q27920
PageGenerator.findRouteByName
train
private function findRouteByName($name) { if (null === $route = $this->routes->get($name)) { throw new \RuntimeException(sprintf('Route "%s" not found.', $name)); } return $route; }
php
{ "resource": "" }
q27921
PageGenerator.findRouteDefinitionByRouteName
train
private function findRouteDefinitionByRouteName($routeName) { if ($routeName === $this->homeRouteName) { return $this->homeDefinition; } return $this->homeDefinition->findChildByRouteName($routeName); }
php
{ "resource": "" }
q27922
PageGenerator.createMenus
train
private function createMenus(PageInterface $page, array $menus) { if (!empty($menus)) { foreach ($menus as $parentName => $config) { if (null === $parent = $this->menuRepository->findOneByName($parentName)) { $this->output->writeln(sprintf( ...
php
{ "resource": "" }
q27923
PageGenerator.removeNonMappedPages
train
private function removeNonMappedPages() { /** @var PageInterface[] $staticPages */ $staticPages = $this->pageRepository->findBy(['static' => true], ['left' => 'DESC']); foreach ($staticPages as $page) { if (null === $this->findRouteDefinitionByRouteName($page->getRoute())) { ...
php
{ "resource": "" }
q27924
PageGenerator.validate
train
private function validate($element) { $violationList = $this->validator->validate($element, null, ['Generator']); if (0 < $violationList->count()) { $this->output->writeln('<error>Invalid element</error>'); /** @var \Symfony\Component\Validator\ConstraintViolationInterface $v...
php
{ "resource": "" }
q27925
PageGenerator.outputPageAction
train
private function outputPageAction($name, $action) { $this->output->writeln(sprintf( '- <comment>%s</comment> %s %s.', $name, str_pad('.', 44 - mb_strlen($name), '.', STR_PAD_LEFT), $action )); }
php
{ "resource": "" }
q27926
Flash.fetch
train
protected function fetch() { if($this->fetched) return; if($this->container['session']->has('messages')) $this->messages = $this->container['session']['messages']; $this->fetched = true; return $this; }
php
{ "resource": "" }
q27927
RouteProvider.getRouteCollectionForRequest
train
public function getRouteCollectionForRequest(Request $request) { $collection = new RouteCollection(); // Fetch pages IDs by request path. $qb = $this->pageRepository->createQueryBuilder('p'); $qb ->select('p.id') ->join('p.translations', 't') ->an...
php
{ "resource": "" }
q27928
RouteProvider.getRoutesByNames
train
public function getRoutesByNames($names, $parameters = []) { $qb = $this->pageRepository->createQueryBuilder('p'); $qb ->select('p.route, p.controller, t.path, t.locale') ->join('p.translations', 't') ->andWhere($qb->expr()->eq('p.static', 0)) ; if...
php
{ "resource": "" }
q27929
RouteProvider.getRouteByName
train
public function getRouteByName($name, $parameters = []) { $qb = $this->pageRepository->createQueryBuilder('p'); $results = $qb ->select('p.route, p.controller, t.path, t.locale') ->join('p.translations', 't') ->andWhere($qb->expr()->eq('p.static', 0)) ...
php
{ "resource": "" }
q27930
RouteProvider.transformResultsToRoutes
train
protected function transformResultsToRoutes(array $results) { $routes = []; foreach ($results as $result) { $name = $result['route']; if (array_key_exists($name, $routes)) { /** @var Route $route */ $route = $routes[$name]; $pat...
php
{ "resource": "" }
q27931
MacroCall.setProps
train
function setProps (array $props = null) { if ($this->propsClass) { if (!class_exists ($this->propsClass, false)) { $this->context ->getMacrosService () ->setupMacroProperties ($this->propsClass, $this->templateUrl, function () { $this->createView (); // Re...
php
{ "resource": "" }
q27932
MacroCall.databind
train
protected function databind () { $bp = "$this->propsClass::bindings"; if (defined ($bp)) foreach (constant ($bp) as $k => $v) { if (!exists($this->getComputedPropValue ($k))) $this->bindings[$k] = unserialize ($v); } parent::databind (); }
php
{ "resource": "" }
q27933
CollectionTrait.newCollection
train
public function newCollection(array $models = [], string $eloquent = null, string $table = null) { return (new AccioCollection($models))->setModel($eloquent, $table); }
php
{ "resource": "" }
q27934
CalendarExtension.getIndex
train
private function getIndex($searchedHour, $hours) { foreach ($hours as $index => $hour) { if ($hour == $searchedHour) { return $index; } } }
php
{ "resource": "" }
q27935
CalendarExtension.isWithinFrequency
train
public function isWithinFrequency($hour, $frequencies, $hours) { $hourIndex = $this->getIndex($hour, $hours); foreach ($frequencies as $frequency) { $startIndex = $this->getIndex(date('G', $frequency->getStartTime()->getTimestamp()), $hours); $endIndex = $this->getIndex(date(...
php
{ "resource": "" }
q27936
CalendarExtension.hourIndex
train
public function hourIndex($datetime, $hours) { $searchedHour = date('G', $datetime->getTimestamp()); return $this->getIndex($searchedHour, $hours); }
php
{ "resource": "" }
q27937
CalendarExtension.toWeekDays
train
public function toWeekDays($pattern) { $weekDays = $this->getWeekDays(); $formatedDays = []; foreach (str_split($pattern) as $key => $day) { if (array_key_exists($day, $weekDays) && intval($day) === 1) { $formatedDays[] = $weekDays[$key]; } }...
php
{ "resource": "" }
q27938
CalendarExtension.getWeekDays
train
private function getWeekDays() { if (empty(self::$weekDays) && ($this->translator instanceof TranslatorInterface)) { self::$weekDays = [ $this->translator->trans('calendar.weekdays.monday', [], 'default'), $this->translator->trans('calendar.weekdays.tuesday', [], ...
php
{ "resource": "" }
q27939
Util.mkdirr
train
public function mkdirr($pathname, $mode = null) { // Check if directory already exists if (is_dir($pathname) || empty($pathname)) { return true; } // Ensure a file does not already exist with the same name if (is_file($pathname)) { return false; ...
php
{ "resource": "" }
q27940
Util.rmdirr
train
public function rmdirr($dir) { if ($handle = opendir("$dir")) { while ($item = readdir($handle)) { if (($item != ".") && ($item != "..")) { if (is_dir("$dir/$item")) { $this->rmdirr("$dir/$item"); } else { ...
php
{ "resource": "" }
q27941
Util.readfileChunked
train
public function readfileChunked($filename, $retbytes = false) { $chunksize = 1 * (1024 * 1024); // how many bytes per chunk $buffer = ''; $cnt = 0; $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { ...
php
{ "resource": "" }
q27942
CDispatcherBasic.prepareName
train
public function prepareName($name) { $name = empty($name) ? 'index' : $name; $name = strtolower($name); $name = str_replace(['-', '_'], ' ', $name); $name = ucwords($name); $name = str_replace(' ', '', $name); return $name; }
php
{ "resource": "" }
q27943
CDispatcherBasic.setControllerName
train
public function setControllerName($name = 'index') { $name = $this->prepareName($name) . 'Controller'; $this->controllerName = $name; $this->controller = $this->di->has($name) ? $this->di->get($name) : null; }
php
{ "resource": "" }
q27944
CDispatcherBasic.forward
train
public function forward($forward = []) { $controller = isset($forward['controller']) ? $forward['controller'] : null; $action = isset($forward['action']) ? $forward['action'] : null; $params = isset($forward['params']) ? $...
php
{ "resource": "" }
q27945
TFBCBreadcrumb.getBreadcrumbTitle
train
private function getBreadcrumbTitle($file) { $frontmatter = $this->getFrontmatter($file); $title = $frontmatter["title"]; if (isset($frontmatter["titleBreadcrumb"])) { $title = $frontmatter["titleBreadcrumb"]; } return $title; }
php
{ "resource": "" }
q27946
Form.handleRequest
train
public function handleRequest(): void { global $save, $restore; $request = $this->getRequest(); if ((!empty($save) || !empty($restore)) && $request->isPost() && check_bitrix_sessid()) { if (!empty($restore)) { // Restore defaults Option::delete(ADMIN_MODULE_NAME); CAdminMessage::showMessage([ ...
php
{ "resource": "" }
q27947
GnStorageApi.GetStorageItem
train
public function GetStorageItem(string $storage, string $key, string $ownerUserName = NULL) { $result = $this->ExecuteCall("GetStorageItem", (object)[ "storage" => $storage, "key" => $key, "ownerUserName" => $ownerUserName ], GnResponseType::GnMashupStorageItem); ...
php
{ "resource": "" }
q27948
AccioUninstall.clearCaches
train
protected function clearCaches() { $this->callSilent('clear-compiled'); $this->callSilent('cache:clear'); $this->callSilent('route:clear'); $this->callSilent('config:clear'); $this->callSilent('view:clear'); Cache::flush(); }
php
{ "resource": "" }
q27949
RequireTagReference.compileTags
train
protected function compileTags(Compiler $compiler): void { $tagClass = $this->getAttribute('tagClass'); $assets = $this->getAttribute('assets'); $attributes = $this->getAttribute('attributes'); $position = $this->getAttribute('position'); foreach ($assets as $asset) { ...
php
{ "resource": "" }
q27950
BaseSettingsController.getSettings
train
public function getSettings() { $settings = Settings::all()->keyBy('settingsKey'); $settings['defaultLanguage'] = (object) array('value' => Language::getDefault()->languageID); if(isset($settings['logo'])) { $media = Media::where('mediaID', $settings['logo']->value)->select("me...
php
{ "resource": "" }
q27951
BaseSettingsController.store
train
public function store(Request $request) { // insert key and value in settings table $settings = Settings::all()->keyBy('settingsKey')->toArray(); foreach ($request->form as $key => $value){ if(!isset($settings[$key])) { $settings[$key] = ["settingsKey" => $key, "...
php
{ "resource": "" }
q27952
BaseSettingsController.storePermalinks
train
public function storePermalinks(Request $request) { $data = $request->all(); $tmp = []; foreach ($data as $permalinks){ $tmp = array_merge($tmp, $permalinks); } if(Permalink::truncate()) { if(Permalink::insert($tmp)) { return $this->r...
php
{ "resource": "" }
q27953
Pagination.LengthAwarePaginator
train
public function LengthAwarePaginator($items, $resultsPerPage = 4) { //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); //Create a new Laravel collection from data $collection = new Collection($items); //Slice the collection t...
php
{ "resource": "" }
q27954
CRequestBasic.setGlobals
train
public function setGlobals($globals = []) { $this->server = isset($globals['server']) ? array_merge($_SERVER, $globals['server']) : $_SERVER; $this->get = isset($globals['get']) ? array_merge($_GET, $globals['get']) : $_GET; $this->post = isset($globals['post']) ? array_merge...
php
{ "resource": "" }
q27955
CRequestBasic.init
train
public function init() { $this->requestUri = $this->getServer('REQUEST_URI'); $scriptName = $this->getServer('SCRIPT_NAME'); $this->path = rtrim(dirname($scriptName), '/'); $this->scriptName = basename($scriptName); // The route and its parts $this->extractRoute(); ...
php
{ "resource": "" }
q27956
CRequestBasic.extractRoute
train
public function extractRoute() { $requestUri = $this->getServer('REQUEST_URI'); $scriptName = $this->getServer('SCRIPT_NAME'); $scriptPath = dirname($scriptName); $scriptFile = basename($scriptName); $requestUri = urldecode($requestUri); // Compare REQUEST_URI and S...
php
{ "resource": "" }
q27957
CRequestBasic.getCurrentUrl
train
public function getCurrentUrl($queryString = true) { $rs = $this->getServer('REQUEST_SCHEME'); $https = $this->getServer('HTTPS') == 'on' ? true : false; $sn = $this->getServer('SERVER_NAME'); $port = $this->getServer('SERVER_PORT'); $port = ($port == '80') ...
php
{ "resource": "" }
q27958
CRequestBasic.getServer
train
public function getServer($key, $default = null) { return isset($this->server[$key]) ? $this->server[$key] : $default; }
php
{ "resource": "" }
q27959
CRequestBasic.setServer
train
public function setServer($key, $value = null) { if (is_array($key)) { $this->server = array_merge($this->server, $key); } else { $this->server[$key] = $value; } }
php
{ "resource": "" }
q27960
CRequestBasic.setGet
train
public function setGet($key, $value = null) { if (is_array($key)) { $this->get = array_merge($this->get, $key); } else { $this->get[$key] = $value; } }
php
{ "resource": "" }
q27961
BasePostTypeController.getAll
train
public function getAll($lang = "") { $result = []; $postType = PostType::all()->orderBy('postTypeID'); foreach ($postType as $postType){ $postType->categories = Category::where("postTypeID", $postType->postTypeID)->get(); $result[] = $postType; } retu...
php
{ "resource": "" }
q27962
BasePostTypeController.menuPanelItems
train
public function menuPanelItems($lang = "") { // check if user has permissions to access this link if(!User::hasAccess('PostType', 'read')) { return $this->noPermission(); } // Find post types if(Input::input('keyword')) { $postTypes = PostType::where(...
php
{ "resource": "" }
q27963
BasePostTypeController.delete
train
public function delete($lang, $id) { // check if user has permissions to access this link if(!User::hasAccess('PostType', 'delete')) { return $this->noPermission(); } $res = $this->deletePostType($id); if($res && is_bool($res)) { return $this->respons...
php
{ "resource": "" }
q27964
BasePostTypeController.bulkDelete
train
public function bulkDelete(Request $request) { // check if user has permissions to access this link if(!User::hasAccess('PostType', 'delete')) { return $this->noPermission(); } // if there are no item selected if (count($request->all()) <= 0) { return ...
php
{ "resource": "" }
q27965
BasePostTypeController.deletePostType
train
private function deletePostType($id) { $postType = PostType::find($id); if(!$postType) { return false; } // Check if this post type has posts // Post type should not be able to be deleted if it has posts if(PostType::hasPosts($postType->slug) || PostType:...
php
{ "resource": "" }
q27966
BasePostTypeController.deleteRelatedTagsAndCategory
train
public function deleteRelatedTagsAndCategory($postType) { $categories = Category::where("postTypeID", $postType->postTypeID); $categoryIDs = $categories->pluck('categoryID')->toArray(); $categoriesRelations = (new CategoryRelation)->setTable($postType->slug."_categories")->whereIn("categoryI...
php
{ "resource": "" }
q27967
BasePostTypeController.deleteField
train
public function deleteField(string $postTypeSlug, string $fieldSlug) { if (Schema::hasColumn($postTypeSlug, $fieldSlug)) { Schema::table( $postTypeSlug, function ($table) use ($fieldSlug) { $table->dropColumn($fieldSlug); } ); ...
php
{ "resource": "" }
q27968
BasePostTypeController.getTables
train
public function getTables() { $tables = [ 0 => [ 'group' => 'Post Type', 'options' => [] ], 1 => [ 'group' => 'Others', 'options' => [ ['label' => 'Users', 'name' => 'users', 'belongsTo' =...
php
{ "resource": "" }
q27969
ColumnIntersectsCollection.checkForRelationshipIntersections
train
public function checkForRelationshipIntersections(Collection $collection, $createIntersectionCallback) { if ($this->intersectionCreated) { return; } // While this behaviour could (and perhaps more efficiently) be achieved using `intersectWith` we instead // do a `joinWit...
php
{ "resource": "" }
q27970
ModelSchema.addColumn
train
public function addColumn(Column $column) { $columns = func_get_args(); foreach ($columns as $column) { $this->columns[$column->columnName] = $column; if ($column instanceof AutoIncrementColumn) { $this->uniqueIdentifierColumnName = $column->columnName; ...
php
{ "resource": "" }
q27971
ModelSchema.getIndex
train
public function getIndex($indexName) { if (isset($this->indexes[$indexName])) { return $this->indexes[$indexName]; } return null; }
php
{ "resource": "" }
q27972
MenuModel.createPrimaryMenu
train
public static function createPrimaryMenu() { $check = Menu::where('slug', 'primary')->get()->first(); if(!$check) { $create = factory(Menu::class)->create( [ 'title' => 'Primary', 'slug' => 'primary', 'isPrimary' => true, ...
php
{ "resource": "" }
q27973
HTMLHelper.tag
train
public static function tag($tag, array $attrs, $inner=null) { $str = ''; foreach($attrs as $k=>$v) { if(is_numeric($k)) $str .= $v.' '; else $str .= $k.'="'.$v.'" '; } $str = '<'.$tag.' '.trim($str).'>'; if($inner === null) return $str; $str .= $inner; return $str.'<...
php
{ "resource": "" }
q27974
RowManager.create
train
public function create($containerOrName, array $data = []) { // Check if parent or name is defined if (!( $containerOrName instanceof Model\ContainerInterface || (is_string($containerOrName) && 0 < strlen($containerOrName)) ) ) { throw new InvalidO...
php
{ "resource": "" }
q27975
RowManager.delete
train
public function delete(Model\RowInterface $row, $force = false) { $container = $row->getContainer(); // Skip checks if forced if (!$force) { // Don't remove container's only row or named row if ($row->isAlone() || $row->isNamed()) { throw new InvalidO...
php
{ "resource": "" }
q27976
RowManager.moveUp
train
public function moveUp(Model\RowInterface $row) { $sibling = $this->editor->getRepository()->findSiblingRow($row, false); if (null === $sibling) { throw new InvalidOperationException( "The row can't be moved up as no sibling row has been found." ); } ...
php
{ "resource": "" }
q27977
RowManager.moveDown
train
public function moveDown(Model\RowInterface $row) { $sibling = $this->editor->getRepository()->findSiblingRow($row, true); if (null === $sibling) { throw new InvalidOperationException( "The row can't be moved down as no sibling row has been found." ); ...
php
{ "resource": "" }
q27978
RowManager.fixBlocksPositions
train
public function fixBlocksPositions(Model\RowInterface $row) { $this->sortChildrenByPosition($row, 'blocks'); /** @var Model\BlockInterface[] $blocks */ $blocks = $row->getBlocks(); $position = 0; foreach ($blocks as $block) { $block->setPosition($position); ...
php
{ "resource": "" }
q27979
DoctrineSearchCondition.applyToQueryBuilder
train
public function applyToQueryBuilder(QueryBuilder $qb, &$parameterOffset = 0) { $expr = $qb->expr(); $conditions = $this->conditions; foreach ($conditions as $condition) { $field = $condition[self::FIELD_POS]; switch ($field) { case self::LEFT_FIELD: case self::RIGHT_FIELD: case self::LEVEL_FIE...
php
{ "resource": "" }
q27980
GeneratorEngine.processFile
train
public function processFile($src, $dst, $vars) { if(!$this->overrideFiles && file_exists($dst)) return; $container = $this->container; $_src = $src; $_dst = $dst; extract($vars); ob_start(); include $_src; $content = ob_get_contents(); ob_end_clean(); $content = str_replace('<%=', '<?=', $cont...
php
{ "resource": "" }
q27981
GeneratorEngine.outputPHP
train
public function outputPHP($v, $tabs=0, $line=false) { $r = ''; if($line) $r .= "\n".str_repeat("\t", $tabs); if(is_array($v)) { $r .= '['; if($v === array_values($v)) { foreach($v as $_v) $r .= $this->outputPHP($_v, $tabs+1, true).","; } else { foreach($v as $_k=>$_v) $r .= $thi...
php
{ "resource": "" }
q27982
Arr.get
train
public static function get(array $array, $key = null, $default = null) { if (is_null($key)) { return; } if (isset($array[$key])) { return $array[$key]; } foreach (explode('.', $key) as $token) { if (! is_array($array) or ! array_key_exist...
php
{ "resource": "" }
q27983
Arr.transmute
train
public static function transmute($items) { if (is_array($items)) { return $items; } elseif ($items instanceof Collection) { return $items->all(); } return (array) $items; }
php
{ "resource": "" }
q27984
Record.unserialize
train
public function unserialize($data) { $data = unserialize($data); $this->dict = $data[0]; $this->setInterpolator($data[1]); }
php
{ "resource": "" }
q27985
Matcher.getMatches
train
public function getMatches(VerbalExpression $verbalExpression, $test) { $matches = array(); preg_match($verbalExpression, $test, $matches); return $matches; }
php
{ "resource": "" }
q27986
AssetsGroup.render
train
protected function render () { $this->context->getAssetsService ()->beginAssetsContext ($this->props->prepend); $this->runChildren (); $this->context->getAssetsService ()->endAssetsContext (); }
php
{ "resource": "" }
q27987
AbstractGridNodeTypePostprocessor.getEditorValues
train
protected function getEditorValues($set, array $setData, $device, $groupLabel) { $groupLabel = $groupLabel ? $groupLabel : $device; $editorValues = []; $cssSuffixes = $this->settings[static::$SETTINGS_SECTION][$set]['cssClassSuffixes']; foreach ($cssSuffixes as $cssSuffix) { ...
php
{ "resource": "" }
q27988
TagModel.href
train
public function href($routeName = 'tag.single', $customAttributes = []) { $params = ['tagSlug'=>$this->slug]; if($customAttributes) { $params = array_merge($customAttributes, $params); } return route($routeName, $params); }
php
{ "resource": "" }
q27989
PostModel.setTable
train
public function setTable($table) { $this->table = 'post_'.cleanPostTypeSlug($table); self::$_tmptable = $this->table; return $this; }
php
{ "resource": "" }
q27990
PostModel.with
train
public static function with($relations) { $model = (new static()); $class = new \ReflectionClass($model); $method = $class->getProperty("table"); $class = explode("\\", $method->class); if ($class[count($class)-1] != class_basename($model)) { if(self::$_tmptabl...
php
{ "resource": "" }
q27991
PostModel.menuLinkPanel
train
protected static function menuLinkPanel() { // List one menu panel for each post type $panels =[]; foreach(PostType::all() as $postType){ $panels[] = [ 'label' => $postType->name, 'belongsTo' => $postType->slug, 'controller' => ($po...
php
{ "resource": "" }
q27992
PostModel.setMostReadCache
train
public static function setMostReadCache() { // check if a article has been read if(Cache::has("most_read_articles_ids")) { // current date and time $currentDate = new DateTime(); // use to refresh the cache "most_read_articles_ids", removes posts that are older t...
php
{ "resource": "" }
q27993
PostModel.getMostReadCache
train
public static function getMostReadCache() { $mostRead = Cache::get("most_read_articles"); if(!$mostRead || $mostRead == null || $mostRead->isEmpty()) { return []; } return $mostRead; }
php
{ "resource": "" }
q27994
PostModel.getDefaultRelations
train
public function getDefaultRelations($postType) { $relations = []; if(count($this->autoCacheRelations)) { return $this->autoCacheRelations; } // Tags if($postType->hasTags) { $relations[] = 'tags'; } // Categories if($postTyp...
php
{ "resource": "" }
q27995
PostModel.scopeDate
train
public function scopeDate($query, $year = '', $month ='', $day ='') { if($year) { $query->whereMonth($this->getTable().'.created_at', $year); } if($month) { $query->whereYear($this->getTable().'.created_at', $month); } if($day) { $query->...
php
{ "resource": "" }
q27996
PostModel.setHomepage
train
public static function setHomepage() { if(!self::$homepage) { $findHomePage = null; if (settings('homepageID')) { $findHomePage = (new Post())->setTable("post_pages") ->where('postID', settings('homepageID')) ->first(); ...
php
{ "resource": "" }
q27997
PostModel.getHomepage
train
public static function getHomepage($columnName = '') { if($columnName) { if(isset(self::$homepage->$columnName)) { return self::$homepage->$columnName; } return null; } return self::$homepage; }
php
{ "resource": "" }
q27998
PostModel.mediaField
train
public function mediaField($field) { if(count($this->media)) { $results = $this->media->where('field', $field); if(count($results)) { return $results; } } return null; }
php
{ "resource": "" }
q27999
PostModel.media
train
public function media() { $query = $this->customHasManyThrough('App\Models\Media', 'App\Models\MediaRelation', 'postID', 'mediaID', 'postID', 'mediaID', $this->getTable()."_media"); if($this->mediaField) { $query->where($this->getTable().'_media.field', $this->mediaField); } ...
php
{ "resource": "" }