예제 #1
0
 public function __construct($Data, $Table, $UserID)
 {
     $this->_Table = $Table;
     $this->_UserID = $UserID;
     foreach ($Data[0] as $key => $value) {
         if (is_int($key)) {
             //Remove all Numerical keys so no Duplicates
             unset($Data[0][$key]);
         }
     }
     parent::__construct($Data[0]);
     $this->AddMeta("Modify", function ($self, $Params) {
         //Update DB when values change
         \DB::getInstance()->table($this->_Table)->where("UserID", $this->_UserID)->update(array($Params["Offset"] => $Params["NewValue"]));
         $self->_data[$Params["Offset"]] = $Params["NewValue"];
         return $self->_data;
     });
     $this->AddMeta("NewIndex", function ($self, $Params) {
         return $self->_data;
         //Block new elements from being created. Can only modify existing Elements
     });
 }
예제 #2
0
 /**
  * 查询记录集
  * @return array
  */
 static function results($query = null)
 {
     $pdo = Database::pdo();
     $metaTables = array();
     $params = $query->getParameters();
     $ops = $query->getOperators();
     $sql = "select * from meta_table";
     Sql::splice($sql, MetaTableDao::$fields, $params, $ops);
     Sql::addtion($sql, $query);
     $stmt = $pdo->prepare($sql);
     Sql::params($stmt, $params);
     $stmt->execute();
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $metaTable = new MetaTable();
         $metaTable->setId($row['id']);
         $metaTable->setDatabaseId($row['database_id']);
         $metaTable->setDatabaseName($row['database_name']);
         $metaTable->setName($row['name']);
         $metaTable->setKeyId($row['key_id']);
         $metaTable->setKeyName($row['key_name']);
         array_push($metaTables, $metaTable);
     }
     $stmt->closeCursor();
     return $metaTables;
 }