/**
  * @group attribute
  */
 public function testDelete()
 {
     $attributes = \Veer\Models\Attribute::where('name', 'like', 'Color%')->get();
     foreach ($attributes as $attribute) {
         $this->attribute->delete($attribute->id);
     }
     $this->assertEquals(0, \Veer\Models\Attribute::where('name', 'like', 'Color%')->count());
     $attributes = \Veer\Models\Attribute::where('name', 'like', 'Color%')->withTrashed()->lists('id');
     $this->assertGreaterThan(0, count($attributes));
     \Veer\Models\Attribute::whereIn('id', $attributes)->withTrashed()->forceDelete();
     $attributes = \Veer\Models\Attribute::where('name', 'like', 'Color%')->withTrashed()->lists('id');
     $this->assertEquals(0, count($attributes));
 }
Example #2
0
 protected function replaceFilterId($type, $filter_id)
 {
     if ($type == "attributes") {
         $a = \Veer\Models\Attribute::where('id', '=', $filter_id)->select('name', 'val')->first();
         if (is_object($a)) {
             $filter_id = $a->name . ":" . $a->val;
         }
     }
     if ($type == "tags") {
         $filter_id = \Veer\Models\Tag::where('id', '=', $filter_id)->pluck('name');
     }
     return $filter_id;
 }
Example #3
0
 /**
  * Update an Attribute's date by id.
  *
  * @todo rewrite? not necessary as it is a helper method, for normal update eloquent can be used
  * @helper Model update
  * @param array $data
  * @return \Veer\Services\Administration\Elements\Attribute
  */
 public function update($data)
 {
     if (empty($data) || !is_array($data)) {
         return $this;
     }
     $data += ['renameAttrValue' => [], 'descrAttrValue' => [], 'attrType' => [], 'newAttrValue' => []];
     foreach ($data['renameAttrValue'] as $k => $v) {
         $type = array_get($data['attrType'], $k);
         \Veer\Models\Attribute::where('id', '=', $k)->update(['val' => $v, 'descr' => array_get($data['descrAttrValue'], $k, ''), 'type' => $type == 'descr' || $type == 1 ? 'descr' : 'choose']);
     }
     foreach ($data['newAttrValue'] as $k => $v) {
         $this->attachToAttributes($k, $v);
     }
     return $this;
 }
Example #4
0
 /**
  * Get attribute.
  * 
  * 
  * @param integer $id
  */
 public function getAttribute($id, $childId = null)
 {
     if (empty($childId)) {
         $p = null;
         $parent_attribute = \Veer\Models\Attribute::where('id', '=', $id)->select('name')->first();
         if (is_object($parent_attribute)) {
             $p = \Veer\Models\Attribute::where('name', 'like', $parent_attribute->name)->get();
             // @todo like?
         }
     } else {
         $p = \Veer\Models\Attribute::where('id', '=', $childId)->first();
     }
     return $p;
 }