/**
  * @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
 protected function collectFilteredAttributes($id)
 {
     $a = array();
     if (count($id) > 1) {
         foreach ($id as $k => $filter) {
             if ($k <= 0 || $filter <= 0) {
                 continue;
             }
             // skip category
             $a[$k] = \Veer\Models\Attribute::find($filter)->toArray();
         }
     }
     return $a;
 }
Example #4
0
 /**
  * Delete attribute
  *
  */
 protected function deleteAttribute($id)
 {
     $t = \Veer\Models\Attribute::find($id);
     if (is_object($t)) {
         $t->pages()->detach();
         $t->products()->detach();
         $t->delete();
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Update Attributes Connections
  * @todo Test
  */
 protected function attachToAttributes($name, $form)
 {
     $new = $this->parseForm($form);
     if (!is_array($new['target'])) {
         return null;
     }
     foreach ($new['target'] as $a) {
         $a = trim($a);
         if (empty($a)) {
             continue;
         }
         if (starts_with($a, ":")) {
             // id
             $aDb = \Veer\Models\Attribute::find(substr($a, 1));
             if (!is_object($aDb)) {
                 continue;
             }
         } else {
             // string values
             $aDb = \Veer\Models\Attribute::firstOrNew(['name' => $name, 'val' => $a]);
             $aDb->type = empty($aDb->type) ? 'descr' : $aDb->type;
             $aDb->descr = empty($aDb->descr) ? '' : $aDb->descr;
             $aDb->save();
         }
         $attributes[] = $aDb->id;
     }
     if (isset($attributes)) {
         $this->attachFromForm($new['elements'], $attributes, 'attributes');
     }
 }
Example #6
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 #7
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;
 }