示例#1
0
文件: PModel.php 项目: exildev/q-stad
 public function __call($name, $arguments)
 {
     $reflex = new ReflectionClass($this->model->get_called_class());
     $properts = $reflex->getProperties();
     foreach ($properts as $propert) {
         $pname = $propert->getName();
         if ($name == "get" . ucfirst($pname)) {
             $value = $this->model->{$name}();
             if ($value instanceof Constrain && $value->getType() == Constrain::FORAIN_KEY) {
                 $refer_package = $value->getReferPackage();
                 $refer_model = $value->getReferModel();
                 Kernel::import($refer_package . "." . ucfirst($refer_model));
                 $refer_object = new $refer_model();
                 $clone = clone $this;
                 $clone->model = $refer_object;
                 $clone->prefix($pname);
                 return $clone;
             } else {
                 if ($value instanceof Input || $value instanceof Constrain && $value->getType() == Constrain::PRIMARY_KEY) {
                     if (isset($this->value[($this->prefx != null ? $this->prefx . "__" : "") . $pname])) {
                         return $this->value[($this->prefx != null ? $this->prefx . "__" : "") . $pname];
                     } else {
                         return null;
                     }
                 }
             }
         } else {
             if ($name == "set" . ucfirst($pname)) {
                 $value = $this->model->{"get" . ucfirst($pname)}();
                 if ($value instanceof Input) {
                     $value->set($arguments[0]);
                     $this->value[$pname] = $arguments[0];
                 } else {
                     if ($value instanceof Constrain) {
                         $value->set($arguments[0]);
                         $this->value[$pname] = $arguments[0];
                     }
                 }
             }
         }
     }
     return null;
 }
示例#2
0
 /**
  * 
  * @param Model $model
  * @param Objects $object
  * @return Objects
  */
 public static function by_model(Model $model, Objects &$object = null, $prefix = null)
 {
     if ($object == null) {
         $object = Objects::objects($model);
     }
     $reflex = new ReflectionClass($model->get_called_class());
     $properts = $reflex->getProperties();
     $fullname = $model->get_fullname();
     foreach ($properts as $propert) {
         $name = $propert->getName();
         $value = $model->{"get" . $name}();
         if ($value instanceof Constrain && $value->getType() == Constrain::FORAIN_KEY) {
             $refer_package = $value->getReferPackage();
             $refer_model = $value->getReferModel();
             Kernel::import($refer_package . "." . ucfirst($refer_model));
             $fullrefer = $value->getFullRefer();
             $refer_object = new $refer_model();
             $pk = $refer_object->get_pk();
             $pk_name = $pk->name();
             $class = strtolower($refer_object->get_called_class());
             if ($class == "user") {
                 $fullclass = $class;
                 $fullon = "{$fullname}.{$name} = {$class}.{$pk_name}";
             } else {
                 $fullclass = $refer_package . '_' . $class;
                 $fullon = "{$fullname}.{$name} = {$fullrefer}.{$pk_name}";
             }
             $object->join($fullclass, "{$fullon}");
             if ($prefix != null) {
                 $object->refer($fullclass, "{$fullon}");
             } else {
                 $object->refers[0] = $fullclass;
                 array_push($object->basest, "{$name} = {$name}" . "__" . "pk");
             }
             $object = self::by_model($refer_object, $object, ($prefix != null ? $prefix . "__" : "") . $name);
         }
         if ($value instanceof Constrain || $value instanceof Input) {
             if ($value instanceof Constrain && $value->getType() == Constrain::PRIMARY_KEY) {
                 $col = "pk";
             } else {
                 $col = $name;
             }
             $object->select($fullname . "." . $name . " AS " . ($prefix != null ? $prefix . "__" : "") . $col);
             if ($prefix != null) {
                 //var_dump($prefix . "---" . $name . "<br>");
                 $object->others($fullname . "." . $name . " AS " . ($prefix != null ? $prefix . "__" : "") . $col);
             }
         }
     }
     return $object;
 }
示例#3
0
 public function update(Model $model, $array, $update)
 {
     foreach ($array as $key => $value) {
         $colsn = explode(" = ", $value);
         $cols = explode("__", $colsn[0]);
         $object = $model;
         foreach ($cols as $col) {
             $const = $object->{"get" . ucfirst($col)}();
             if ($const instanceof Constrain) {
                 $refer = $const->getRefer();
                 Kernel::import($refer);
                 $class = $const->getReferModel();
                 $fulln = $const->getFullRefer();
                 $name = $const->name();
                 if ($object == $model) {
                     $this->where("{$col} = {$refer}.{$name}");
                 } else {
                     $this->join($object->get_fullname(), null, $fulln, null, "{$col} = {$refer}.{$name}");
                 }
                 $object = new $class();
             } else {
                 return false;
             }
         }
     }
     return $this->get_sql_update($model->get_fullname(), $update);
 }
示例#4
0
 * and open the template in the editor.
 */
/**
 * Description of Package1
 *
 * @author luism
 */
Kernel::import('package1.Formulario');
Kernel::import('package1.Usuario');
Kernel::import('package1.Pregunta');
Kernel::import('package1.Respuesta_cerrada');
Kernel::import('package1.Respuesta_abierta');
Kernel::import('package1.Pregunta_cerrada');
Kernel::import('package1.Pregunta_abierta');
Kernel::import('package1.Responde');
Kernel::import('package1.Encuestador');
require_once realpath(dirname(__FILE__)) . "/Service.php";
require_once realpath(dirname(__FILE__)) . "/Upload.class.php";
class Package1 extends View
{
    public function __construct()
    {
        parent::__construct(realpath(dirname(__FILE__)) . "/../templ/");
    }
    public function main()
    {
        $user = Session::get_user();
        if ($user != null && $user->getVerified()) {
            return parent::render('menu.html', array());
        } else {
            header("Location: ?ID=login");