/**
  * @group category
  */
 public function testSort()
 {
     for ($j = 1; $j <= 5; $j++) {
         $this->handler->add('Category' . $j, null, ['sort' => $j * 10]);
     }
     $categories = Veer\Models\Category::all()->sortBy('manual_sort')->lists('manual_sort', 'id')->toArray();
     $this->assertEquals(5, count($categories));
     $lastId = last(array_keys($categories));
     $this->handler->sortChilds([]);
     $this->handler->sort([]);
     $this->handler->sort('String');
     $this->handler->sort(['oldindex' => count($categories) - 1, 'newindex' => 0, 'parentid' => app('veer')->siteId]);
     $categories = Veer\Models\Category::all()->sortBy('manual_sort')->lists('manual_sort', 'id')->toArray(0);
     $firstId = head(array_keys($categories));
     $this->assertEquals($lastId, $firstId);
     $this->handler->sort(['oldindex' => 0, 'newindex' => count($categories) - 1, 'parentid' => app('veer')->siteId]);
     $categories = Veer\Models\Category::all()->sortBy('manual_sort')->lists('manual_sort', 'id')->toArray(0);
     $newLastId = last(array_keys($categories));
     $this->assertEquals($newLastId, $firstId);
 }
Exemplo n.º 2
0
 /**
  * Add a Category.
  *
  * @helper Model create|save
  * @param string $title
  * @param int $siteid
  * @param array $options
  * @param boolean $updateEntity
  * @param boolean $returnId
  * @return \Veer\Services\Administration\Elements\Category|integer
  */
 public function add($title, $siteid = null, $options = [], $updateEntity = true, $returnId = false)
 {
     if (empty($title)) {
         return $returnId ? null : $this;
     }
     $c = new \Veer\Models\Category();
     $c->title = $title;
     $c->description = array_get($options, 'description', '');
     $c->remote_url = array_get($options, 'remote_url', '');
     $c->manual_sort = array_get($options, 'sort', 999999);
     $c->views = array_get($options, 'views', 0);
     $c->sites_id = empty($siteid) ? app('veer')->siteId : $siteid;
     $c->save();
     if ($updateEntity) {
         $this->id = $c->id;
         $this->entity = $c;
     }
     return $returnId ? $c->id : $this;
 }