Beispiel #1
0
 public function testAction()
 {
     $entity_name = "a_user";
     $entity = new model\aUser();
     $white_list = array("id", "name");
     $data_source = array("id" => 4, "name" => "heh", "age" => 3);
     $provide_data = array();
     $reflect = new \ReflectionClass($entity);
     $properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC);
     $front = "UPDATE `{$entity_name}` set ";
     $back = '';
     foreach ($properties as $value) {
         if (in_array($value->name, $white_list)) {
             $back .= ' ' . $value->name . '=?,';
             $provide_data[] = $data_source[$value->name];
         }
     }
     $back = substr($back, 0, strlen($back) - 1);
     $back .= ' where id=?';
     $provide_data[] = $data_source["id"];
     $sql = $front . $back . ';';
     echo $sql;
     //return;
     $common = new model\common();
     $common->getReadConnection()->execute($sql, $provide_data);
     echo $common->getReadConnection()->affectedRows();
 }
Beispiel #2
0
 public function doneTicketAction()
 {
     if ($this->request->isPost()) {
         $id = $_POST["id"];
         $sql = "call p_done_book_ticket(?)";
         $myModel = new model\common();
         $query = $myModel->getReadConnection()->query($sql, array($id));
         $this->view->disable();
     }
 }
Beispiel #3
0
 public function GetFieldsAction()
 {
     if (isset($_GET["name"])) {
         $common = new model\common();
         $sql = "describe `" . $_GET["name"] . "`";
         $query = $common->getReadConnection()->query($sql);
         $result = $query->fetchAll();
         echo json_encode($result);
         $this->view->disable();
     }
 }
Beispiel #4
0
 public function getRowsAction()
 {
     $limit = ($_GET["page"] - 1) * $_GET["rows"] . "," . $_GET["rows"];
     $order = ' `' . $_GET["sort"] . '` ' . $_GET["order"] . ' ';
     $where = '1=1';
     if (isset($_GET["where"])) {
         $where = $_GET["where"];
     }
     $common = new model\common();
     $sql = "select SQL_CALC_FOUND_ROWS * from a_user where {$where} order by {$order} limit {$limit};SELECT FOUND_ROWS() as `rs`;";
     error_log($sql);
     $query = $common->getReadConnection()->query($sql);
     $rows = $query->fetchAll();
     $query->nextRowSet();
     $count = $query->fetchAll()[0]["rs"];
     echo '{"total":"' . $count . '","rows":' . json_encode($rows) . "}";
     $this->view->disable();
 }
Beispiel #5
0
 public function getRowsAction()
 {
     $where = '1=1';
     if (isset($_GET["where"])) {
         $where = $_GET["where"];
     }
     $limit = ($_GET["page"] - 1) * $_GET["rows"] . "," . $_GET["rows"];
     $order = ' `' . $_GET["sort"] . '` ' . $_GET["order"] . ' ';
     $where = '1=1';
     if (isset($_GET["where"])) {
         $where = $_GET["where"];
     }
     $common = new model\common();
     $sql = "select SQL_CALC_FOUND_ROWS a.*,c.name as bd_name from article a \nleft join bd_places b on b.article_id=a.id\nleft join bd c on b.city_id=c.id  where {$where} order by {$order} limit {$limit};SELECT FOUND_ROWS() as rs";
     $query = $common->getReadConnection()->query($sql);
     $rows = $query->fetchAll();
     $query->nextRowSet();
     $count = $query->fetchAll()[0]["rs"];
     echo '{"total":"' . $count . '","rows":' . json_encode($rows) . "}";
     $this->view->disable();
 }
Beispiel #6
0
 public function addCommentAction()
 {
     $question_id = $_POST["question_id"];
     $body = $_POST["body"];
     $uploads_dir = getcwd() . "\\user_images\\common";
     $img_name = '';
     if (isset($_FILES["img"]) && $_FILES["img"]["error"] == UPLOAD_ERR_OK) {
         $o_name = $_FILES["img"]["name"];
         $name_without_path = uniqid() . substr($o_name, strrpos($o_name, '.') - 1);
         $name = $uploads_dir . "\\" . $name_without_path;
         $img_name = '/user_images/question/' . $name_without_path;
         move_uploaded_file($_FILES["img"]["tmp_name"], $name);
         $image = new \Phalcon\Image\Adapter\Imagick($name);
         $width = $image->getWidth();
         $height = $image->getHeight();
         $final_width = 640;
         $final_height = 0;
         if ($width > $final_width) {
             $final_height = $height * ($final_width / $width);
         } else {
             $final_width = $width;
             $final_height = $height;
         }
         $image->resize($final_width, $final_height);
         if ($image->save()) {
         }
     }
     $page_object_id = $question_id;
     $page_object_name = 'question';
     $body = htmlspecialchars($body);
     $user_id = $_POST["user_id"];
     $common = new model\common();
     $sql = "call p_comment_" . $page_object_name . '(?,?,?,?)';
     $query = $common->getReadConnection()->query($sql, array($body, $img_name, $user_id, $page_object_id));
     $this->flag(TRUE, '√');
 }
Beispiel #7
0
 protected function execute($sql, $provide_data)
 {
     error_log($sql);
     $common = new model\common();
     $common->getReadConnection()->execute($sql, $provide_data);
     return $common->getReadConnection()->affectedRows();
 }