コード例 #1
0
ファイル: class.Place.php プロジェクト: koninka/Hackathon
 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
ファイル: class.Search.php プロジェクト: koninka/Hackathon
 public function GetJoins()
 {
     if ($this->isChangeJoin) {
         $this->joins = SQL::MakeJoin($this->table, $this->joinFields);
         $this->isChangeJoin = false;
     }
     return $this->joins;
 }
コード例 #3
0
ファイル: class.Event.php プロジェクト: koninka/Hackathon
 private function GenQueryForList($user_id, $limit, $start = 0)
 {
     global $_user, $_place;
     $fields = SQL::GetListFieldsForSelect(array_merge(SQL::PrepareFieldsForSelect(static::TABLE, [$this->idField, $this->GetFieldByName(static::HEAD_FLD), $this->GetFieldByName(static::CREATION_DATE_FLD), $this->GetFieldByName(static::DUE_DATE_FLD), $this->GetFieldByName(static::TYPE_FLD), $this->GetFieldByName(static::DESCRIPTION_FLD)]), SQL::PrepareFieldsForSelect(User::TABLE, [$_user->idField, $_user->GetFieldByName(User::NAME_FLD), $_user->GetFieldByName(User::SURNAME_FLD), $_user->GetFieldByName(User::PHOTO_FLD)]), SQL::PrepareFieldsForSelect(Place::TABLE, [$_place->GetFieldByName(Place::TYPE_FLD), $_place->GetFieldByName(Place::NUMBER_FLD)])));
     return sprintf('SELECT %s FROM %s %s WHERE %s = %s %s ORDER BY %s DESC LIMIT %d, %d', $fields, static::TABLE, SQL::MakeJoin(static::TABLE, [User::TABLE => [null, [static::OWNER_FLD, User::ID_FLD]], Place::TABLE => [null, [static::PLACE_FLD, Place::ID_FLD]]]), $this->ToTblNm(static::TYPE_FLD), '%d', !empty($user_id) ? sprintf('AND %s = ?', $_user->ToTblNm(User::ID_FLD)) : '', $this->ToTblNm(static::CREATION_DATE_FLD), $start, $limit);
 }
コード例 #4
0
ファイル: class.Image.php プロジェクト: koninka/Hackathon
function ImageSelectSQL($th, $entity, $field)
{
    global $_image;
    return sprintf("IFNULL((SELECT GROUP_CONCAT(%s) FROM %s %s WHERE %s GROUP BY %s), '') as %s", $entity->ToTblNm($entity::PHOTO_FLD), $entity::TABLE, SQL::MakeJoin($entity::TABLE, [Image::TABLE => [null, [$entity::PHOTO_FLD, Image::ID_FLD]]]), (new Clause(CCond(CF($entity::TABLE, $entity->GetFieldByName($field)), CF($th::TABLE, $th->GetFieldByName($th::ID_FLD))), CCond(CF(Image::TABLE, $_image->GetFieldByName(Image::IS_RESIZED_FLD)), CVS(1), 'AND')))->GetClause(), $th->ToTblNm($th::ID_FLD), $th->ToPrfxNm($th::PHOTOS_FLD));
}