Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • DefaultClipboard

Interfaces

  • ClipboardInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\Clipboard;
 14: 
 15: /**
 16:  * Class DefaultClipboard.
 17:  *
 18:  * Default implementation of the clipboard.
 19:  *
 20:  * @package DcGeneral\Clipboard
 21:  */
 22: class DefaultClipboard implements ClipboardInterface
 23: {
 24:     /**
 25:      * The ids contained.
 26:      *
 27:      * @var array
 28:      */
 29:     protected $arrIds;
 30: 
 31:     /**
 32:      * The ids that will create a circular reference and therefore shall get ignored for pasting.
 33:      *
 34:      * @var array
 35:      */
 36:     protected $arrCircularIds;
 37: 
 38:     /**
 39:      * The current mode the clipboard is in.
 40:      *
 41:      * @var string
 42:      */
 43:     protected $mode;
 44: 
 45:     /**
 46:      * {@inheritDoc}
 47:      */
 48:     public function loadFrom($objEnvironment)
 49:     {
 50:         $strName      = $objEnvironment->getDataDefinition()->getName();
 51:         $arrClipboard = $objEnvironment->getInputProvider()->getPersistentValue('CLIPBOARD');
 52: 
 53:         if (isset($arrClipboard[$strName]))
 54:         {
 55:             if (isset($arrClipboard[$strName]['ignoredIDs']))
 56:             {
 57:                 $this->setCircularIds($arrClipboard[$strName]['ignoredIDs']);
 58:             }
 59: 
 60:             if (isset($arrClipboard[$strName]['ids']))
 61:             {
 62:                 $this->setContainedIds($arrClipboard[$strName]['ids']);
 63:             }
 64: 
 65:             if (isset($arrClipboard[$strName]['mode']))
 66:             {
 67:                 $this->mode = $arrClipboard[$strName]['mode'];
 68:             }
 69:         }
 70:     }
 71: 
 72:     /**
 73:      * {@inheritDoc}
 74:      */
 75:     public function saveTo($objEnvironment)
 76:     {
 77:         $strName      = $objEnvironment->getDataDefinition()->getName();
 78:         $arrClipboard = $objEnvironment->getInputProvider()->getPersistentValue('CLIPBOARD');
 79: 
 80:         if ($this->isEmpty())
 81:         {
 82:             unset($arrClipboard[$strName]);
 83:         }
 84:         else
 85:         {
 86:             $arrClipboard[$strName] = array();
 87:             if ($this->getCircularIds())
 88:             {
 89:                 $arrClipboard[$strName]['ignoredIDs'] = $this->getCircularIds();
 90:             }
 91: 
 92:             if ($this->isNotEmpty())
 93:             {
 94:                 $arrClipboard[$strName]['ids'] = $this->getContainedIds();
 95:             }
 96: 
 97:             $arrClipboard[$strName]['mode'] = $this->mode;
 98:         }
 99: 
100:         $objEnvironment->getInputProvider()->setPersistentValue('CLIPBOARD', $arrClipboard);
101:     }
102: 
103:     /**
104:      * {@inheritDoc}
105:      */
106:     public function clear()
107:     {
108:         unset($this->arrIds);
109:         unset($this->mode);
110: 
111:         return $this;
112:     }
113: 
114:     /**
115:      * {@inheritDoc}
116:      */
117:     public function isEmpty()
118:     {
119:         return ((!isset($this->arrIds) || empty($this->arrIds)) && (!isset($this->mode)) || empty($this->mode));
120:     }
121: 
122:     /**
123:      * {@inheritDoc}
124:      */
125:     public function isNotEmpty()
126:     {
127:         return !$this->isEmpty();
128:     }
129: 
130:     /**
131:      * {@inheritDoc}
132:      */
133:     public function isCut()
134:     {
135:         return $this->mode == self::MODE_CUT;
136:     }
137: 
138:     /**
139:      * {@inheritDoc}
140:      */
141:     public function isCopy()
142:     {
143:         return $this->mode == self::MODE_COPY;
144:     }
145: 
146:     /**
147:      * {@inheritDoc}
148:      */
149:     public function isCreate()
150:     {
151:         return $this->mode == self::MODE_CREATE;
152:     }
153: 
154:     /**
155:      * {@inheritDoc}
156:      */
157:     public function copy($ids)
158:     {
159:         $this->mode = self::MODE_COPY;
160: 
161:         if (is_array($ids) || is_null($ids))
162:         {
163:             $this->setContainedIds($ids);
164:         }
165:         else
166:         {
167:             $this->setContainedIds(array($ids));
168:         }
169: 
170:         return $this;
171:     }
172: 
173:     /**
174:      * {@inheritDoc}
175:      */
176:     public function cut($ids)
177:     {
178:         $this->mode = self::MODE_CUT;
179: 
180:         if (is_array($ids) || is_null($ids))
181:         {
182:             $this->setContainedIds($ids);
183:         }
184:         else
185:         {
186:             $this->setContainedIds(array($ids));
187:         }
188: 
189:         return $this;
190:     }
191: 
192:     /**
193:      * {@inheritDoc}
194:      */
195:     public function create($parentId)
196:     {
197:         $this->mode = self::MODE_CREATE;
198: 
199:         $this->setContainedIds($parentId);
200: 
201:         return $this;
202:     }
203: 
204:     /**
205:      * {@inheritDoc}
206:      */
207:     public function setContainedIds($arrIds)
208:     {
209:         $this->arrIds = $arrIds;
210: 
211:         return $this;
212:     }
213: 
214:     /**
215:      * {@inheritDoc}
216:      */
217:     public function getContainedIds()
218:     {
219:         return $this->arrIds;
220:     }
221: 
222:     /**
223:      * {@inheritDoc}
224:      */
225:     public function setCircularIds($arrIds)
226:     {
227:         $this->arrCircularIds = $arrIds;
228: 
229:         return $this;
230:     }
231: 
232:     /**
233:      * {@inheritDoc}
234:      */
235:     public function getCircularIds()
236:     {
237:         return $this->arrCircularIds;
238:     }
239: 
240:     /**
241:      * {@inheritdoc}
242:      */
243:     public function getMode()
244:     {
245:         return $this->mode;
246:     }
247: }
248: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0