Beispiel #1
0
	public function moveData($action, $toCat = null)
	{
		$transaction=$this->dbConnection->beginTransaction();
		try {
			if($action=='cut') ModelFactory::cutRelations($this, $toCat);
			if($action=='copy') ModelFactory::copyRelations($this, $toCat);
			if($action=='delete') ModelFactory::deleteRelations($this); 
			
			//copy templates
			$res = array();
			foreach ($this->templates as $tmpl) {
				$newTmpl = $tmpl;
				$doAssign = true;
				if ($action=='cut') {
					$doAssign = $toCat->getOwnTemplate($tmpl->alias) == null;
				} elseif ($action=='copy') {
					$doAssign = $toCat->getOwnTemplate($tmpl->alias) == null;
					$newTmpl->pk = null;
				}
				
				if($doAssign)
					$res[] = $newTmpl;
			}
			if ($action=='cut' || $action=='copy') {
				$to->templates = $res;
				$to->save();
			}
			if ($action=='cut' || $action=='delete')
				$this->templates = array();
			
			$transaction->commit();
			$result = true;
		} catch(Exception $e) {
		    $transaction->rollBack();
			$result = false;	
		}
		
		return $result;
	}