public function addClipboard()
 {
     $user = $this->serviceContainer->getService('user');
     if (!$user->can('behavior_add')) {
         return $this;
     }
     $data = $user->getAttribute('dm_behavior_clipboard', null, 'dm.front_user_behavior_clipboard');
     if (!is_null($data)) {
         if ($data['dm_behavior_clipboard_action'] == 'cut' && !$user->can('behavior_delete')) {
             return $this;
         }
         $behaviorsManager = $this->serviceContainer->getService('behaviors_manager');
         try {
             $behavior = DmBehaviorTable::getInstance()->findOneById($data['dm_behavior_id']);
             if (!$behavior) {
                 return $this;
             }
             $settings = $behaviorsManager->getBehaviorSettings($behavior->getDmBehaviorKey());
         } catch (Exception $e) {
             return $this;
         }
         $this->addChild('Clipboard')->ulClass('clearfix level2')->liClass('dm_droppable_behaviors')->addChild($behavior->getDmBehaviorKey() . 'clipboard')->setOption('clipboard_action', $data['dm_behavior_clipboard_action'])->setOption('clipboard_icon', $settings['icon'])->setOption('clipboard_id', $behavior->getId())->label($settings['name']);
     }
     return $this;
 }
 public function saveSortOrder()
 {
     try {
         $behaviors = json_decode($this->getValue('behaviors'), true);
         DmBehaviorTable::getInstance()->getConnection()->beginTransaction();
         foreach ($behaviors as $behavior) {
             $tmp = dmDb::query('DmBehavior b')->where('id = ?', $behavior['dm_behavior_id'])->fetchOne();
             $tmp->setPosition($behavior['dm_behavior_sequence']);
             $tmp->save();
         }
         DmBehaviorTable::getInstance()->getConnection()->commit();
         return true;
     } catch (Exception $e) {
         DmBehaviorTable::getInstance()->getConnection()->rollback();
         return false;
     }
 }
 /**
  * Stores behavior id and copy action in clipboard     
  */
 public function executeCopy(dmWebRequest $request)
 {
     if (!$this->getUser()->can('behavior_add')) {
         return $this->renderError($this->getI18n()->__('Error'), $this->getI18n()->__('You do not have privileges to copy behavior'));
     }
     if ($request->hasParameter('dm_behavior_id')) {
         $behavior = DmBehaviorTable::getInstance()->findOneById($request->getParameter('dm_behavior_id'));
         if (!$behavior) {
             return $this->renderError($this->getI18n()->__('Error'), $this->getI18n()->__('The behavior that you are copying does not exist anymore'));
         }
         $this->getUser()->setAttribute('dm_behavior_clipboard', array('dm_behavior_clipboard_action' => 'copy', 'dm_behavior_id' => $behavior->getId()), 'dm.front_user_behavior_clipboard');
         return $this->renderJson(array('error' => false));
     } else {
         return $this->renderError($this->getI18n()->__('Error'), $this->getI18n()->__('You must supply behavior for copying'));
     }
 }