Example #1
0
 function execute($params)
 {
     // パラメータを調整
     $post = Vizualizer::request();
     $month = $post["ym"];
     if (empty($month) || preg_match("/[0-9]{4}-[0-9]{2}/", $month) == 0) {
         $month = date("Y-m");
     }
     // クエリを生成
     $loader = new Vizualizer_Plugin("stock");
     $orders = $loader->loadTable("Orders");
     $orderDetails = $loader->loadTable("OrderDetails");
     $select = new Vizualizer_Query_Select($orderDetails);
     $select->addColumn($orderDetails->set_id)->addColumn($orderDetails->choice_id);
     $select->addColumn($orderDetails->set_menu_name)->addColumn($orderDetails->menu_name);
     $select->addColumn("SUM(" . $orderDetails->price . " * " . $orderDetails->quantity . ")", "price");
     $select->join($orders, array($orders->order_id . " = " . $orderDetails->order_id));
     $select->where("order_date LIKE ?", array($month . "-%"));
     $select->group($orderDetails->set_id)->group($orderDetails->choice_id);
     $select->having("SUM(" . $orderDetails->price . " * " . $orderDetails->quantity . ") > 0");
     $select->order($orderDetails->set_id)->order($orderDetails->choice_id);
     // 生成したクエリに対して検索を実行し、結果をモデルとして取得
     $order = $loader->loadModel("OrderDetail");
     $orders = $order->queryAllBy($select);
     // 結果を属性に設定
     $attr = Vizualizer::attr();
     $attr["sales"] = $orders;
     $attr["thismonth"] = date("Y-m-01", strtotime($month . "-01"));
     $attr["nextmonth"] = date("Y-m", strtotime("+1 month", strtotime($month . "-01")));
     $attr["lastmonth"] = date("Y-m", strtotime("-1 month", strtotime($month . "-01")));
 }
Example #2
0
 /**
  * セッションのデータををDBから読み込む.
  *
  * @param string $id セッションID
  * @return string セッションデータの値
  */
 function read($id)
 {
     $id_key = $this->id_key;
     $data_key = $this->data_key;
     // セッションデータを取得する。
     $select = new Vizualizer_Query_Select($this->table);
     $select->addColumn($this->table->_W);
     $select->addWhere($this->table->{$id_key} . " = ?", array($id));
     $result = $select->execute();
     return $result[0][$data_key];
 }
Example #3
0
 /**
  * レコードの件数を取得する。
  */
 public function countBy($values = array(), $columns = "*")
 {
     $select = new Vizualizer_Query_Select($this->access, $this->viewTable);
     $select->addColumn("COUNT(" . $columns . ") AS count");
     if (is_array($values)) {
         foreach ($values as $key => $value) {
             $select = $this->appendWhere($select, $key, $value);
         }
     }
     $result = $select->execute();
     if (count($result) > 0) {
         return $result[0]["count"];
     } else {
         return "0";
     }
 }
Example #4
0
 /**
  * 指定したトランザクション内にて主キーベースでデータの保存を行う。
  * 主キーが存在しない場合は何もしない。
  * また、モデル内のカラムがDBに無い場合はスキップする。
  * データ作成日/更新日は自動的に設定される。
  */
 public function save()
 {
     if (!empty($this->primary_keys)) {
         // 現在該当のデータが登録されているか調べる。
         $pkset = false;
         $select = new Vizualizer_Query_Select($this->access);
         $select->addColumn($this->access->_W);
         foreach ($this->primary_keys as $key) {
             if (isset($this->values[$key])) {
                 $select->addWhere($this->access->{$key} . " = ?", array($this->values[$key]));
             } else {
                 $pkset = false;
                 break;
             }
             $pkset = true;
         }
         if ($pkset) {
             $result = $select->execute();
         } else {
             $result = array();
         }
         if (!is_array($result) || empty($result)) {
             // 主キーのデータが無かった場合はデータを作成する。
             $this->create();
         } else {
             // 主キーのデータがあった場合はデータを更新する。
             $this->update();
         }
     }
 }