Location: PHPKode > projects > QuickTicket > quickticket/bin/qti_class_dom.php
<?php

// QuickTicket 2.5 build:20101222

class cDomain extends aQTcontainer
{

// --------

function __construct($aDom=null)
{
  if ( isset($aDom) )
  {
    if ( is_int($aDom) )
    {
      if ( $aDom<0 ) die('No domain '.$aDom);      
      global $oDB;      
      $oDB->Query('SELECT * FROM '.TABDOMAIN.' WHERE id='.$aDom);
      $row = $oDB->Getrow();
      if ( $row===False ) die('No domain '.$aDom);
      $this->MakeFromArray($row);
    }
    elseif ( is_array($aDom) )
    {
      $this->MakeFromArray($aDom);
    }
    else
    {
      die('Invalid constructor parameter #1 for the class cDomain');
    }
  }
}

// --------

private function MakeFromArray($arr)
{
  foreach($arr as $strKey=>$oValue) {
  switch ($strKey) {
    case 'id':        $this->id = intval($oValue); break;
    case 'title':     $this->title = $oValue; break;
  }}
}

// --------

public function Rename($str='')
{
  if ( !is_string($str) || empty($str) ) die('cDomain->Rename: Argument #1 must be a string');
  global $oDB;
  $oDB->Query('UPDATE '.TABDOMAIN.' SET title="'.addslashes($str).'" WHERE id='.$this->id);
  if ( isset($_SESSION[QT]['sys_sections']) ) Unset($_SESSION[QT]['sys_sections']);
}

// --------
// aQTcontainer implementations
// --------

public static function Create($title,$parentid)
{
  // parentid is no used here
  if ( !is_string($title) ) die('cDomain->Add: Argument #1 must be a string');
  global $oDB;
  $id = $oDB->Nextid(TABDOMAIN);
  $oDB->Query('INSERT INTO '.TABDOMAIN.' (id,title,titleorder) VALUES ('.$id.',"'.addslashes($title).'",0)');
  return $id;
}

public static function Drop($id)
{
  if ( !is_int($id) ) die('cDomain->Drop: Argument #1 must be a integer');
  if ( $id<1 ) die('cDomain->Drop: Cannot delete domain 0');
  global $oDB;
  $oDB->Query('UPDATE '.TABSECTION.' SET domainid=0 WHERE domainid='.$id); // sections return to domain 0  
  $oDB->Query('DELETE FROM '.TABDOMAIN.' WHERE id='.$id);
  cVIP::LangDel('domain','d'.$id);
  if ( isset($_SESSION[QT]['sys_sections']) ) Unset($_SESSION[QT]['sys_sections']);
}

public static function MoveItems($id,$destination)
{
  QTargs( 'cDomain->MoveItems',array($id,$destination),array('int','int') );
  if ( $id<0 || $destination<0 ) die('cDomain->MoveItems: source and destination cannot be <0');
  global $oDB;
  $oDB->Query('UPDATE '.TABSECTION.' SET domainid='.$destination.' WHERE domainid='.$id);
}

public static function CountItems($id,$status)
{
  // Count Sections in domain $id
  if ( $id<0 ) die('cDomain->CountItems: id cannot be <0');
  global $oDB;
  $oDB->Query( 'SELECT count(*) as countid FROM '.TABSECTION.' WHERE domainid='.$id.(isset($status) ? ' AND status='.$status : '') );
  $row = $oDB->Getrow();
  return (int)$row['countid'];
}


// --------

}
Return current item: QuickTicket