示例#1
0
 public function SetSelectValues()
 {
     $fields = array();
     $this->CheckSearch();
     switch ($this->samplingScheme) {
         case static::INIT_SCHEME:
             $fields = SQL::PrepareFieldsForSelect(static::TABLE, [$this->idField, $this->GetFieldByName(static::NUMBER_FLD), $this->GetFieldByName(static::POLYGON_FLD), $this->GetFieldByName(static::TYPE_FLD)]);
             $this->initFields = $fields;
             $this->search->AddClause(CCond(CF(static::TABLE, $this->GetFieldByName(static::FLOOR_FLD)), CVP($this->GetFieldByName(static::FLOOR_FLD)->GetValue()), cAND))->AddClause(CCond(CF(static::TABLE, $this->GetFieldByName(static::HOSTEL_FLD)), CVP($this->GetFieldByName(static::HOSTEL_FLD)->GetValue()), cAND, opEQ));
             break;
         case static::AVAILABLE_SCHEME:
             // SELECT
             //    places.id  as places_id,
             //    places.number  as places_number,
             //    places.polygon  as places_polygon,
             //    places.place_type  as places_place_type
             // FROM places
             // WHERE
             //    places.floor = 1 AND
             //    (
             //       (
             //          places.place_type = 1 AND
             //          places.number = (SELECT users.room FROM users INNER JOIN sessions ON sessions.user_id = users.id WHERE sessions.sid = '153382469192f1')
             //       )
             //       OR places.place_type <> 1
             //    )
             $fields = $this->initFields;
             global $_user, $_session;
             $this->search->AddClause(CCond(CF(static::TABLE, $this->GetFieldByName(static::TYPE_FLD)), CVP(1), cAND, opEQ, '(('))->AddClause(CCond(CF(static::TABLE, $this->GetFieldByName(static::NUMBER_FLD)), CVS('(' . SQL::SimpleQuerySelect($_user->ToTblNm(User::ROOM_FLD), sprintf('%s %s', User::TABLE, SQL::MakeJoin(User::TABLE, [Session::TABLE => [null, [User::ID_FLD, Session::USER_FLD]]])), new Clause(CCond(CF(Session::TABLE, $_session->GetFieldByName(Session::SID_FLD)), CVS(sprintf("'%s'", $_SESSION['sid']))))) . ')'), cAND, opEQ, null, ')'))->AddClause(CCond(CF(static::TABLE, $this->GetFieldByName(static::TYPE_FLD)), CVP(1), cOR, opNE, null, ')'));
             break;
     }
     $this->selectFields = SQL::GetListFieldsForSelect($fields);
 }
示例#2
0
 public function Delete($id)
 {
     parent::Delete($id);
     $this->DeleteImg($id);
     global $db;
     try {
         $db->link->beginTransaction();
         $query = SQL::SimpleQuerySelect($this->ToTblNm(static::ID_FLD), static::TABLE, new Clause(CCond(CF(static::TABLE, $this->GetFieldByName(static::IS_RESIZED_FLD)), CVS(0))));
         $sample = $db->Query($query);
         $db->Query('DELETE FROM ' . static::TABLE . ' WHERE ' . static::IS_RESIZED_FLD . ' = 0');
         foreach ($sample as &$set) {
             $this->DeleteImg($set[static::ID_FLD]);
         }
         $db->link->commit();
     } catch (DBException $e) {
         $db->link->rollback();
         throw new Exception($e->getMessage());
     }
 }