Ejemplo n.º 1
0
function typography($str)
{
    $str = S::capitalize(trim($str));
    if ($str === '') {
        return $str;
    }
    $lb = '(?<=|\\.\\.\\.|[…\\s"\'«“‘‛‹\\/\\<[{(])';
    // left boundary
    $rb = '($|[…\\s"\'»„”’‛›\\/\\>\\]})?!.,:;])';
    // right boundary
    $regexp = array($lb . '"([^"]*)"' . $rb => '«\\1»\\2', $lb . '([+-]?\\d+)[\\s^](F|C)' . $rb => '\\1°\\2\\3', $lb . '\\+-(\\d+)' . $rb => '±\\1\\2', $lb . '([+-]?\\d+)\\.(\\d+)' . $rb => '\\1,\\2\\3', '\\.\\.\\.+' => '…', ' -+ ' => ' — ');
    $regexp = S::keys($regexp, '#"~?~u"');
    return preg_replace(array_keys($regexp), array_values($regexp), $str);
}
Ejemplo n.º 2
0
 function get_show($id = null)
 {
     if ($order = Order::find($id)) {
         $this->title = array($id);
         $this->order = $order;
         if (!$this->accessible($order)) {
             return false;
         } else {
             $setManagers = array();
             if ($this->editable($order)) {
                 $this->layout = '.set';
                 if ($this->can('order.edit.manager')) {
                     $managers = User::where('perms', 'LIKE', '%manager%')->get();
                     $setManagers = S::keys($managers, function ($user) {
                         $name = __('vanemart::order.set.manager', $user->to_array());
                         return array($user->id, $name);
                     });
                 }
             }
             return compact('setManagers') + $order->to_array();
         }
     }
 }
Ejemplo n.º 3
0
 function get_by_list($name = 'main', $slides = false)
 {
     if ($name === '*') {
         if ($route = \Vane\Route::current() and $route->lastServer) {
             $name = \Bundle::element($route->lastServer->name);
             $name = S::tryUnprefix(strtok($name, '@'), 'block.');
         } else {
             $name = null;
         }
     }
     $default = $this->in('default', 'main');
     if (!$name and !$default) {
         return E_INPUT;
     }
     $query = ProductListItem::order_by('sort');
     $name and $query->where('type', '=', $name);
     $default and $query->or_where('type', '=', $default);
     if ($list = $query->get()) {
         if ($default and !S::first($list, array('?->type === ?', $name))) {
             $type = $default;
         } else {
             $type = $name;
         }
         $list = S::keep($list, array('?->type === ?', $type));
         $goods = S::keys(Product::all(prop('product', $list)), '?->id');
         $ordered = array();
         foreach ($list as $item) {
             $product =& $goods[$item->product];
             if ($product and (!$slides or $product->image)) {
                 $product->extra = $item->extra;
                 $ordered[] = $product;
             }
         }
         $this->layout = $slides ? '.slides' : '.index';
         return static::listResponse($slides ? 1000 : 320, $ordered);
     }
 }
Ejemplo n.º 4
0
 function viewData($name, $value = null)
 {
     if (func_num_args() > 1 or is_array($name)) {
         is_array($name) or $name = array($name => $value);
         $alter = S::keys($name, function ($value, $name) {
             if (!isset(LayoutAlter::$typeChars[$name[0]])) {
                 $name = "={$name}";
             }
             return array($name[0] . '. ' . substr($name, 1), "={$value}");
         });
         return $this->alter($alter);
     } elseif (!$this->isViewEndpoint() and $view = $this->find('') and $block = $view->find($name)) {
         return Rendering::likeViewVar($block, $this, $this->slugs);
     }
 }
Ejemplo n.º 5
0
            $query->where(\DB::raw('DATE(created_at)'), $op, $date)->or_where(\DB::raw('DATE(updated_at)'), $op, $date);
        });
    }
    if ($names = $block->in('names', '')) {
        $query->where(function ($query) use($names) {
            $query->raw_where('LOCATE(?, name) = 1', array($names))->raw_or_where('LOCATE(?, surname) = 1', array($names));
        });
    }
    $can['filter'] += compact('date', 'names');
});
// Fired to add extra attributes to Orders retrieved with order.list.query.
//
//* $orders array of Order
Event::listen(VANE_NS . 'order.list.populate', function (array &$orders, Block_Order $block, array &$vars) {
    $counts = OrderProduct::where_in('order', prop('id', $orders))->group_by('order')->select(array('*', \DB::raw('COUNT(1) AS count')))->get();
    $counts = S::keys($counts, '?->order');
    foreach ($orders as $order) {
        $order->count = $counts[$order->id]->count;
    }
});
Event::listen(VANE_NS . 'order.list.populate', function (array &$orders, Block_Order $block, array &$vars) {
    $recentTime = time() - 3 * 24 * 3600;
    foreach ($orders as $order) {
        $order->recent = $order->updated_at >= $recentTime;
    }
});
// Fired to do final preparations of variables returned to client/given to template.
Event::listen(VANE_NS . 'order.list.populate', function (array &$vars, Block_Order $block) {
});
/*-----------------------------------------------------------------------
| POST MODEL