if (isset($this->args['book_id'])) {\r
$dao = new wsDAOBook($core->con);\r
$book = $dao->selectById($this->args['book_id']);\r
+\r
}\r
\r
$dao = new wsDAOTheme($core->con);\r
} else {\r
$right = '-';\r
}\r
- $t->addAttribute('right', rand(0,1)?'w':'r'/*$right*/);\r
+ $t->addAttribute('right', rand(0, 1)?'w':'r'/*$right*/);\r
$t->addAttribute('books', $theme->nbBooks);\r
}\r
}\r
\r
+ public function duplicateTheme()\r
+ {\r
+ global $core;\r
+ $dao = new wsDAOTheme($core->con);\r
+ $theme = $dao->duplicate($this->args['theme_id'], $core->user->utilisateur_id);\r
+ $this->xml->addChild('theme_id', $theme->theme_id);\r
+ if (isset($this->args['book_id'])) {\r
+ $dao = new wsDAOBook($core->con);\r
+ $data = array('book_id' => $this->args['book_id'], 'theme' => $theme->theme_id);\r
+ $dao->sauve($core->user->utilisateur_id, $data);\r
+ }\r
+ }\r
+\r
public function setTheme()\r
{\r
global $core;\r
$theme->date = $r->date;\r
$theme->proprietaire = $r->proprietaire;\r
$theme->books = explode(',', $r->books);\r
- $theme->nbBooks=$r->nb_books;\r
+ $theme->nbBooks = $r->nb_books;\r
$theme->signature = $r->signature;\r
$theme->icones = $r->icones;\r
$p = unserialize($r->parametres);\r
$r = $this->con->select($sql . ' ' . $order);\r
return $this->factory($r);\r
}\r
+\r
+ protected function getNextId()\r
+ {\r
+ $r = $this->con->select('SELECT MAX(theme_id) AS theme_id FROM themes');\r
+ return $r->theme_id + 1;\r
+ }\r
+\r
+ public function duplicate($theme_id, $proprietaire)\r
+ {\r
+ $theme = $this->selectById($theme_id);\r
+ // Copie des données\r
+ $c = $this->con->openCursor('themes');\r
+ $c->theme_id = $this->getNextId();\r
+ $c->nom = $theme->nom . ' (copy)';\r
+ $c->parametres = serialize($theme->parametres);\r
+ $c->signature = $theme->signature;\r
+ $c->icones = $theme->icones;\r
+ $c->proprietaire = $proprietaire;\r
+ $c->date = TIME;\r
+ $c->insert();\r
+ // Copie des fichiers\r
+ $from = ROOT . '/themes/' . $theme_id . '/';\r
+ $to = ROOT . '/themes/' . $c->theme_id . '/';\r
+ $dr = opendir($from);\r
+ if (!file_exists($to)) {\r
+ mkdir($to, 0777, true);\r
+ } while ($file = readdir($dr)) {\r
+ if ($file == '.' || $file == '..') {\r
+ continue;\r
+ }\r
+ copy($from . $file, $to . $file);\r
+ }\r
+\r
+ return $this->selectById($c->theme_id);\r
+ }\r
}\r
\r
?>
\ No newline at end of file