public function addKey(SetEntity $set, Key $key)
 {
     $displayOrder = 0;
     $keys = $set->getAttributeKeys();
     if (count($keys) > 0) {
         $displayOrder = count($keys);
     }
     $r = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Attribute\\SetKey');
     $setKey = $r->findOneBy(array('attribute_key' => $key, 'set' => $set));
     if (!is_object($setKey)) {
         $setKey = new SetKey();
         $setKey->setAttributeKey($key);
         $setKey->setAttributeSet($set);
         $setKey->setDisplayOrder($displayOrder);
         $set->getAttributeKeyCollection()->add($setKey);
         $this->entityManager->persist($setKey);
         $this->entityManager->flush();
     }
 }
 public function sort_attribute_set()
 {
     $entity = $this->getCategoryObject();
     $category = $entity->getAttributeKeyCategory();
     if ($category->getSetManager()->allowAttributeSets()) {
         /*
          * @var CategoryInterface
          */
         $keys = array();
         foreach ((array) $this->request->request->get('akID') as $akID) {
             /*
              * @var AttributeInterface
              */
             $key = $category->getAttributeKeyByID($akID);
             if (is_object($key)) {
                 $keys[] = $key;
             }
         }
         foreach ($category->getSetManager()->getAttributeSets() as $set) {
             if ($set->getAttributeSetID() == $this->request->request->get('asID') && count($keys)) {
                 // Clear the keys
                 foreach ($set->getAttributeKeyCollection() as $setKey) {
                     $this->entityManager->remove($setKey);
                 }
                 $this->entityManager->flush();
                 $i = 0;
                 foreach ($keys as $key) {
                     $setKey = new SetKey();
                     $setKey->setAttributeKey($key);
                     $setKey->setAttributeSet($set);
                     $setKey->setDisplayOrder($i);
                     $set->getAttributeKeyCollection()->add($setKey);
                     ++$i;
                 }
                 break;
             }
         }
         $this->entityManager->persist($set);
         $this->entityManager->flush();
         return new JsonResponse($set);
     }
 }
Example #3
0
 public function addKey(Key $key)
 {
     $setKey = new SetKey();
     $setKey->setAttributeKey($key);
     $setKey->setAttributeSet($this);
     $setKey->setDisplayOrder(count($this->keys));
     $this->keys->add($setKey);
 }