예제 #1
0
 /**
  * Get a value
  * @params pdoMap_Mapping_Entity Entity to handle
  * @params pdoMap_Mapping_Metadata_Field Field to manage
  * @params mixed Value to handle                
  * @returns pdoMap_Mapping_Entity
  */
 public function getter(pdoMap_Mapping_Entity $entity, pdoMap_Mapping_Metadata_Field $field, $value)
 {
     if (is_numeric($value)) {
         return pdoMap::get($field->getOption('adapter'))->SelectEntity($value);
     } else {
         return $value;
     }
 }
예제 #2
0
 /**
  * Get a database manager
  * @returns pdoMap_Database_Reques_Adapters_IBuilder         
  */
 public function manager($database)
 {
     if (!isset($this->managers[$database])) {
         $type = pdoMap::database()->getType($database);
         $manager = 'pdoMap_Database_Request_Adapters_' . $type . '_Builder';
         $this->register($database, new $manager($database));
     }
     return $this->managers[$database];
 }
예제 #3
0
 public static function escapeEntity($name, $table = null)
 {
     if ($table) {
         $db = pdoMap::structure($table)->db;
         $table = pdoMap::database()->getPrefix($db) . pdoMap::structure($table)->name;
         return '[' . $table . '].[' . $name . ']';
     } else {
         return '[' . $name . ']';
     }
 }
예제 #4
0
 public function Count()
 {
     $l = $this->scope->args['limit'];
     $f = $this->scope->args['fields'];
     $this->scope->args['fields'] = array('COUNT(*) AS NB');
     $this->scope->args['limit'] = array();
     $ret = pdoMap::database()->Request($this->scope->database, $this->scope->Request());
     $ret = pdoMap::database()->Fetch($ret);
     $this->scope->args['fields'] = $f;
     $this->scope->args['limit'] = $l;
     return $ret['NB'];
 }
예제 #5
0
 /**
  * Get the cache manager instance
  */
 public function proxy()
 {
     if (!$this->proxy) {
         // INITIALIZE CACHE MANAGER
         if (pdoMap::coreConfig()->cacheAdapter == null) {
             pdoMap::coreConfig()->cacheAdapter = pdoMap::coreConfig()->cacheAdapters[0];
         }
         $class = 'pdoMap_Cache_Adapters_' . pdoMap::coreConfig()->cacheAdapter;
         $this->proxy = new $class();
         $this->proxy->openSession();
         $this->raise('OpenSession');
     }
     return $this->proxy;
 }
예제 #6
0
 public function Run()
 {
     if ($this->mode == 'select') {
         return pdoMap::database()->RequestArray($this->database, $this->Request(), $this->table[0]);
     } else {
         if ($this->mode == 'insert') {
             $ret = pdoMap::database()->Request($this->database, $this->Request());
             if ($ret) {
                 return pdoMap::database()->getPdo($this->database)->lastInsertId();
             } else {
                 return false;
             }
         } else {
             return pdoMap::database()->Request($this->database, $this->Request());
         }
     }
 }
예제 #7
0
 /**
  * Get to the next item
  */
 public function next()
 {
     $this->index++;
     if (!isset($this->buffer[$this->index])) {
         $this->buffer[$this->index] = pdoMap::database()->Fetch($this->ptr);
     }
     if ($this->type && $this->buffer[$this->index]) {
         $this->current = pdoMap::get($this->type)->Create($this->buffer[$this->index]);
     } else {
         $this->current = $this->buffer[$this->index];
     }
 }
예제 #8
0
 /**
  * Generate php mapping class 
  * @throw pdoMap_Parsing_Mapping_Exceptions_Field         
  */
 public function generate($file, $ns)
 {
     $this->mappingKey = $ns;
     $ns = ucfirst($ns);
     // Camelstyle
     /**
      * Defining Interface Service
      */
     $this->open($file . '.class.php');
     $this->writeLine('<?php // GEN ' . $ns . ' AT ' . date('Y-m-d H:i:s'));
     $this->writeLine('interface I' . $ns . 'Adapter {');
     if (isset($this->adapter)) {
         if (isset($this->adapter->request)) {
             foreach ($this->adapter->request as $rq) {
                 $rq->writeSignature(true);
             }
         }
         if (isset($this->adapter->transaction)) {
             foreach ($this->adapter->transaction as $rq) {
                 $rq->writeSignature(true);
             }
         }
     }
     $this->writeLine('}');
     /**
      * Defining Adapter Service
      */
     $this->writeLine('class ' . $ns . 'AdapterImpl');
     $this->writeLine('extends pdoMap_Mapping_Adapter');
     $this->writeLine('implements I' . $ns . 'Adapter {');
     $this->writeLine('public static $adapter = \'' . $this->mappingKey . '\';');
     $this->writeLine('public function __construct() {');
     $this->writeLine('parent::__construct(\'' . $this->mappingKey . '\');');
     $this->writeLine('}');
     if (isset($this->adapter)) {
         if (isset($this->adapter->request)) {
             foreach ($this->adapter->request as $rq) {
                 $rq->toPhp(true);
             }
         }
         if (isset($this->adapter->transaction)) {
             foreach ($this->adapter->transaction as $rq) {
                 $rq->toPhp(true);
             }
         }
     }
     $this->writeLine('}');
     /**
      * Generating Item Entity Manager
      */
     $this->writeLine('class ' . $ns . 'EntityImpl extends pdoMap_Mapping_Entity {');
     $this->writeLine('public function __construct($values = null) {');
     $this->writeLine('parent::__construct(\'' . $this->mappingKey . '\', $values);');
     $this->writeLine('}');
     foreach ($this->fields->field as $field) {
         if (isset($field->calculated)) {
             $field->calculated = str_replace('{', '$this->', $field->calculated);
             $field->calculated = str_replace('}', '', $field->calculated);
             $field->calculated = str_replace('.', '->', $field->calculated);
             $this->writeLine('/**');
             $this->writeLine(' * Calculated field getter ' . $field->bind);
             $this->writeLine(' * Formula : ' . $field->calculated);
             $this->writeLine(' */');
             $this->writeLine('public function getter' . $field->bind . '() {');
             $this->writeLine('$this->setValue(\'' . $field->bind . '\', ' . $field->calculated . ');');
             $this->writeLine('return $this->getValue(\'' . $field->bind . '\');');
             $this->writeLine('}');
         }
     }
     if (isset($this->entity)) {
         if (isset($this->entity->collection)) {
             foreach ($this->entity->collection as $rq) {
                 $rq->toPhp(false);
             }
         }
         if (isset($this->entity->request)) {
             foreach ($this->entity->request as $rq) {
                 $rq->toPhp(false);
             }
         }
         if (isset($this->entity->transaction)) {
             foreach ($this->entity->transaction as $rq) {
                 $rq->toPhp(false);
             }
         }
     }
     $this->writeLine('}');
     /**
      * Generating Structure Manager
      */
     $this->open($file . '.structure.php');
     $this->writeLine('<?php // GEN ' . $ns . ' AT ' . date('Y-m-d H:i:s'));
     // GET ENTITY MANAGER
     if (isset($this->entity) && isset($this->entity->class)) {
         $entity = $this->entity->class;
     } else {
         $entity = $ns . 'EntityImpl';
     }
     // GET ADAPTER MANAGER
     if (isset($this->adapter) && isset($this->adapter->class)) {
         $adapter = ', \'' . $this->adapter->class . '\'';
     } else {
         $adapter = ', \'I' . $ns . 'Adapter\'';
     }
     // GET DATABASE MANAGER
     if ($this->use) {
         $db = ', \'' . $this->use . '\'';
     } else {
         $db = '';
     }
     // START CONSTRUCT
     $this->writeLine('$return = new pdoMap_Mapping_Metadata_Table(\'' . $this->mappingKey . '\', \'' . $this->name . '\', \'' . $entity . '\'' . $adapter . $db . ');');
     foreach ($this->fields->field as $field) {
         if (!isset($field->bind)) {
             throw new Exception('A field must contain a bind attribute !');
         }
         if (!isset($field->type)) {
             throw new Exception('A field must contain a type attribute !');
         }
         if (!isset($field->name)) {
             $field->name = $field->bind;
         }
         $this->writeLine('$return->fields[\'' . $field->bind . '\'] = new pdoMap_Mapping_Metadata_Field(');
         $this->writeData('\'' . $field->name . '\',');
         $this->writeLine('\'' . $field->bind . '\',');
         $this->writeData('\'' . ucfirst(strtolower($field->type)) . '\',');
         $props = $field->getProperties();
         unset($props['name']);
         unset($props['bind']);
         unset($props['type']);
         if (isset($props['calculated'])) {
             unset($props['calculated']);
         }
         $this->writeData(var_export($props, true));
         $this->writeLine(');');
     }
     $this->writeLine('return $return;');
     $this->close();
     // TEST STRUCTURE
     $structure = (include $file . '.structure.php');
     foreach ($structure->fields as $bind => $field) {
         try {
             pdoMap::field()->getMeta($field);
             // TEST FIELD META
         } catch (Exception $ex) {
             @unlink($file . '.structure.php');
             @unlink($file . '.class.php');
             throw new pdoMap_Parsing_Mapping_Exceptions_Field($field, $this->__file, $ex->getMessage());
         }
     }
     return $structure;
 }
예제 #9
0
 /**
  * Truncate table
  */
 public function Truncate()
 {
     $this->TableRequest()->Truncate();
     pdoMap::cache()->clear();
 }
예제 #10
0
 /**
  * Get an adapter instance (singleton version)
  * Use static call directly for php 5.3 versions
  * @params string Binded table name           
  * @returns pdoMap_Mapping_IAdapter 
  */
 public static function get($type)
 {
     if (!isset(self::$services[$type])) {
         self::using($type);
         if (!pdoMap::cache()->hasService($type)) {
             $interface = self::structure($type)->service;
             $classes = get_declared_classes();
             foreach ($classes as $namespace) {
                 $reflexion = new ReflectionClass($namespace);
                 if (!$reflexion->isAbstract() && !$reflexion->isInterface() && $reflexion->implementsInterface($interface)) {
                     if (!pdoMap::cache()->hasService($type)) {
                         pdoMap::cache()->setService($type, $reflexion->newInstance());
                     } else {
                         throw new pdoMap_Exceptions_ServiceDuplicated($type, $interface, pdoMap::cache()->getService($type), $namespace);
                     }
                 }
             }
         }
         self::$services[$type] = pdoMap::cache()->getService($type);
         if (!self::$services[$type]) {
             throw new pdoMap_Exceptions_ServiceNotFound($type);
         }
     }
     return self::$services[$type];
 }
예제 #11
0
 /**
  * Registering database connections
  */
 public function __wakeup()
 {
     foreach ($this->data['connections'] as $key => $cnx) {
         pdoMap::database()->Register($cnx['dns'], $cnx['user'], $cnx['pwd'], $cnx['prefix'], $key);
     }
 }
예제 #12
0
 public function JoinAll()
 {
     $found = false;
     $sql = 'ALTER TABLE ' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable($this->name, $this->database) . "\n";
     foreach ($this->fields as $field) {
         if ($field->type == pdoMap_Mapping_Metadata_Field::FIELD_TYPE_FK) {
             $sql .= ' ADD CONSTRAINT ' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($this->name . '_' . $field->name) . ' FOREIGN KEY(';
             $sql .= pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($field->name);
             $sql .= ') REFERENCES ';
             $ref = pdoMap::structure($field->adapter);
             if (!$ref) {
                 throw new Exception('Could not join ' . $field->bind . ' to an undefined table ' . $field->adapter);
             }
             $sql .= pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable($ref->name, $ref->db);
             $sql .= ' (' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($ref->getPk()->name) . ')';
             $sql .= ' ON DELETE CASCADE, ' . "\n";
             $found = true;
         }
     }
     if (!$found) {
         return true;
     }
     $sql = substr($sql, 0, strlen($sql) - 3);
     return pdoMap::database()->Request($this->database, $sql);
 }
예제 #13
0
 /**
  * Load object from a var_export command
  */
 public static function __set_state($data)
 {
     return pdoMap::get($data['type'])->Create($data['values']);
 }
예제 #14
0
 public function escapeTable($name)
 {
     return pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable(pdoMap::structure($name)->name, pdoMap::structure($name)->db);
 }
예제 #15
0
 margin-bottom: 0px;
}
.style1 {color: #FF0000}
</style>


</head>

<body>	
<?php 
    $username = $_SESSION['user_sc'];
    $password = "";
    $login = 2;
    require_once 'lib/pdomap.php';
    pdoMap::config('config.xml');
    $category = pdoMap::get('category_master')->SelectAll();
    $ret = "";
    $js = "([";
    foreach ($category as $key => $value) {
        if ($js != "([") {
            $js .= ",";
        }
        $ret .= "<option value='" . $value->CAT_ID . "'>" . $value->CATEGORY_NAME . "</option>";
        $js .= "{'ID' : '" . $value->CAT_ID . "','Name' : '" . $value->CATEGORY_NAME . "','Comment' : '" . $value->COMMENTS . "'}";
    }
    $js .= "])";
    ?>
<script language="javascript">
var categoryMaster= eval(<?php 
    echo $js;
    ?>
예제 #16
0
 /**
  * Build join tags
  */
 public function getJoin($joins)
 {
     foreach ($joins as $join) {
         if (!$join->adapter) {
             throw new Exception('Expecting to define the adapter on join !');
         }
         if (!$join->on) {
             $on = $this->getType();
         } else {
             $on = $join->on;
         }
         $field = null;
         if (!$join->field) {
             $fields = pdoMap::structure($join->adapter)->getFields();
             foreach ($fields as $f) {
                 if ($f->getOption('adapter') == $on) {
                     $field = $f->bind;
                     break;
                 }
             }
             if (!$field) {
                 throw new Exception('Join error : unable to find a foreign key for ' . $on . ' on adapter ' . $join->adapter);
             }
         } else {
             $field = $join->field;
         }
         if ($join->adapter != $this->getType()) {
             $pk = pdoMap::structure($join->adapter)->getPk()->bind;
         } else {
             $pk = $this->getPk();
         }
         $this->writeLine('->Join(\'' . $on . '\', \'' . $field . '\', \'' . $join->adapter . '\', \'' . $pk . '\')');
     }
 }
예제 #17
0
 /**
  * Validate entity values
  * @throw pdoMap_Mapping_Exceptions_EntityValidateIsNull
  * @throw pdoMap_Mapping_Exceptions_EntityValidateType          
  */
 public function Validate(pdoMap_Mapping_Entity &$entity)
 {
     $event = $this->raise('Validate', new pdoMap_Mapping_Adapter_Args($entity));
     if ($event) {
         // AUTOMATIC FIELD VALIDATION
         foreach ($this->getStructure()->getFields() as $field) {
             // SET DEFAULT VALUE
             if (is_null($event->entity->getValue($field->bind)) && !is_null($field->DefaultValue())) {
                 $event->entity->__set($field->bind, $field->DefaultValue());
             }
             // READ VALUE
             try {
                 $value = $event->entity->__get($field->bind);
             } catch (Exception $ex) {
                 throw new pdoMap_Mapping_Exceptions_EntityValidateType($event->entity, $field);
             }
             // CHECK NULL CONSTRAINT
             if (!$field->IsNull() && is_null($value) && $field->type != 'Primary') {
                 throw new pdoMap_Mapping_Exceptions_EntityValidateIsNull($event->entity, $field);
             }
             // VALIDATE FIELD VALUE
             if (!is_null($value) && !pdoMap::field()->Validate($event->entity, $field, $value)) {
                 throw new pdoMap_Mapping_Exceptions_EntityValidateType($event->entity, $field);
             }
         }
         return true;
     } else {
         return false;
     }
 }
<?php

$category = $_GET["category"];
require_once 'lib/pdomap.php';
pdoMap::config('config.xml');
$addInfo = pdoMap::get('additional_info_master')->SelectBy("CAT_ID", $category);
if ($addInfo->count()) {
    $start = true;
    echo "([";
    foreach ($addInfo as $key => $value) {
        if ($start) {
            $start = false;
        } else {
            echo ",";
        }
        echo "{'INFO_NAME' : '" . $value->INFO_NAME . "' , ";
        echo "'MANDATORY' : '" . $value->MANDATORY . "' , ";
        echo "'ADD_INFO_MASTER_ID' : '" . $value->ADD_INFO_MASTER_ID . "' , ";
        echo "'TYPE' : '" . $value->TYPE . "' , ";
        echo "'COMMENTS' : '" . $value->COMMENTS . "'}";
    }
    echo "])";
} else {
    echo "([])";
}
pdoMap::cache()->closeSession();
예제 #19
0
 public function Create($drop = false)
 {
     $name = pdoMap::database()->getName($this->database);
     if ($drop) {
         $this->Drop();
     }
     pdoMap::database()->Change('');
     pdoMap::database()->Request($this->database, sprintf($this->sqlCreateSchema, $this->escapeEntity($name), $this->character_set, $this->collate));
     pdoMap::database()->Change($name);
 }