Esempio n. 1
0
 public function getListProductById($table, $idcate)
 {
     $Products = DB::table($table)->where("cate", "=", $idcate)->orderby('sort', 'asc')->get();
     if ($Products) {
         return $Products;
     }
     return false;
 }
 /**
  * Register the Capsule service.
  * Ref: http://stackoverflow.com/questions/17105829/using-eloquent-orm-from-laravel-4-outside-of-laravel
  *
  * @param $app
  **/
 public function register(Application $app)
 {
     $app['capsule.connection_defaults'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => null, 'username' => 'root', 'password' => null, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null, 'logging' => false);
     $app['capsule.container'] = $app->share(function () {
         return new Container();
     });
     $app['capsule.dispatcher'] = $app->share(function () use($app) {
         return new Dispatcher($app['capsule.container']);
     });
     if (class_exists('Illuminate\\Cache\\CacheManager')) {
         $app['capsule.cache_manager'] = $app->share(function () use($app) {
             return new CacheManager($app['capsule.container']);
         });
     }
     $app['capsule'] = $app->share(function ($app) {
         $capsule = new DB($app['capsule.container']);
         $capsule->setEventDispatcher($app['capsule.dispatcher']);
         if (isset($app['capsule.cache_manager']) && isset($app['capsule.cache'])) {
             $capsule->setCacheManager($app['capsule.cache_manager']);
             foreach ($app['capsule.cache'] as $key => $value) {
                 $app['capsule.container']->offsetGet('config')->offsetSet('cache.' . $key, $value);
             }
         }
         if (!isset($app['capsule.connections'])) {
             $app['capsule.connections'] = array('default' => isset($app['capsule.connection']) ? $app['capsule.connection'] : array());
         }
         foreach ($app['capsule.connections'] as $connection => $options) {
             $options = array_replace($app['capsule.connection_defaults'], $options);
             $logging = $options['logging'];
             unset($options['logging']);
             $capsule->addConnection($options, $connection);
             if ($logging) {
                 $capsule->getConnection($connection)->enableQueryLog();
             } else {
                 $capsule->getConnection($connection)->disableQueryLog();
             }
         }
         return $capsule;
     });
 }
 public function get_comments($id)
 {
     return DB::table('comments')->where('on_post', $id)->orderBy('id', 'desc')->get();
 }
 public static function moveNode($parent_id, $child_id, $position)
 {
     $sth = new static();
     $new_parent = static::findOrFail($parent_id);
     $old_child[self::$atb[0]] = $child_id;
     $old_child = static::where(self::$atb[0], $old_child[self::$atb[0]])->first();
     $space = $old_child[self::$atb[3]] - $old_child[self::$atb[2]] + 1;
     // Xác định left, right mới
     for ($i = $new_parent[self::$atb[2]] + 1;;) {
         if ($position == 1) {
             $new_child[self::$atb[2]] = $i;
             $new_child[self::$atb[3]] = $i + $space - 1;
             break;
         } else {
             $cur_child = static::where(self::$atb[2], $i)->first();
             $i = $cur_child[self::$atb[3]] + 1;
             if ($old_child[self::$atb[2]] != $cur_child[self::$atb[2]]) {
                 $position--;
             }
         }
     }
     //Update relevant nodes
     if ($new_child[self::$atb[2]] > $old_child[self::$atb[2]]) {
         $new_child[self::$atb[2]] -= $space;
         $new_child[self::$atb[3]] -= $space;
         $child_road = $new_child[self::$atb[2]] - $old_child[self::$atb[2]];
         $space = -$space;
         $dau1 = '>';
         $dau2 = '<=';
         $lr1 = self::$atb[2];
         $lr2 = self::$atb[3];
     } else {
         $child_road = $new_child[self::$atb[2]] - $old_child[self::$atb[2]];
         $dau1 = '<';
         $dau2 = '>=';
         $lr1 = self::$atb[3];
         $lr2 = self::$atb[2];
     }
     $little_child = DB::table(self::$tbl)->where(self::$atb[2], '>', $old_child[self::$atb[2]])->where(self::$atb[3], '<', $old_child[self::$atb[3]])->lists(self::$atb[0]);
     DB::table(self::$tbl)->whereIn(self::$atb[0], $little_child)->increment(self::$atb[2], $child_road);
     DB::table(self::$tbl)->whereIn(self::$atb[0], $little_child)->increment(self::$atb[3], $child_road);
     $need_update = DB::table(self::$tbl)->where($lr1, $dau1, $old_child[$lr1])->where($lr2, $dau2, $new_child[$lr2])->whereNotIn(self::$atb[0], $little_child)->lists(self::$atb[0]);
     DB::table(self::$tbl)->whereIn(self::$atb[0], $need_update)->increment(self::$atb[2], $space);
     DB::table(self::$tbl)->whereIn(self::$atb[0], $need_update)->increment(self::$atb[3], $space);
     DB::table(self::$tbl)->where($lr1, $dau2, $new_child[$lr2])->where($lr1, $dau1, $old_child[$lr1])->where($lr2, $dau1, $new_child[$lr2])->whereNotIn(self::$atb[0], $little_child)->whereNotIn(self::$atb[0], $need_update)->increment($lr1, $space);
     DB::table(self::$tbl)->where($lr2, $dau1, $old_child[$lr1])->where($lr2, $dau2, $new_child[$lr2])->where($lr1, $dau2, $old_child[$lr1])->whereNotIn(self::$atb[0], $little_child)->whereNotIn(self::$atb[0], $need_update)->increment($lr2, $space);
     static::where(self::$atb[0], $old_child[self::$atb[0]])->update($new_child);
 }
 function getCategory()
 {
     return DB::table('product_type')->get();
 }