[ PHPXref.com ] [ Generated: Sun Jul 20 18:38:40 2008 ] [ METAjour 2.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> basic_model_createcopy.php (source)

   1  <?php
   2  /**
   3   * @author Jan H. Andersen <jha@ipwsystems.dk>
   4   * @author Martin R. Larsen <mrl@ipwsystems.dk>
   5   * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
   6   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   7   * @package METAjour
   8   * @subpackage model
   9   */
  10  
  11  require_once ('basic_model.php');
  12  
  13  class basic_model_createcopy extends basic_model {
  14      
  15  	function copyvariants($sourceid, $targetid) {
  16          $source = owRead($sourceid);
  17          $arr = $source->getVariants();
  18          if (!empty($arr)) {
  19              foreach ($arr as $cur) {
  20                  $variant = owRead($cur);
  21                  $targetvariant = owNew($variant->getType());
  22                  $targetvariant->createObject($variant->elements[0]);
  23                  $targetvariant->setVariantOf($targetid);
  24                  $targetvariant->setLanguage($variant->getLanguage());
  25  
  26                  $targetvariant->setVariantFields($variant->getVariantFields());
  27              }
  28          }
  29      }
  30      
  31  	function recurse($sourceid, $targetid) {
  32          $source = owRead($sourceid);
  33          $arr = $source->getchilds();
  34          if (!empty($arr)) {
  35              foreach ($arr as $order) {
  36                  $sourcechild = owRead($order);
  37                  $targetchild = owNew($sourcechild->getType());
  38                  $targetchild->createObject($sourcechild->elements[0],$targetid);
  39                  if ($sourcechild->hasVariant()) $this->copyVariants($sourcechild->getObjectId(),$targetchild->getObjectId());
  40                  if ($sourcechild->haschild()) {
  41                      $this->recurse($sourcechild->getObjectId(),$targetchild->getObjectId());
  42                  }
  43              }
  44          }
  45      }
  46      
  47  	function model() {
  48          foreach($this->objectid as $curid) {
  49              $source = owRead($curid);
  50              $source->elements[0]['name'] = "Copy of ".$source->elements[0]['name'];
  51              $target = owNew($source->getType());
  52              $target->createObject($source->elements[0],$source->getParentId());
  53              if ($source->hasVariant()) $this->copyVariants($source->getObjectId(),$target->getObjectId());
  54              if ($source->haschild()) {
  55                  $this->recurse($source->getObjectId(),$target->getObjectId());
  56              }
  57          }
  58      }
  59      
  60  }
  61  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]