Example #1
0
 public static function upload($value)
 {
     $document = new Documents();
     foreach ($value as $item => $i) {
         $document->{$item} = $i;
     }
     $document->created_at = time();
     $document->updated_at = time();
     $document->user = $value['user'];
     $token = Util::generateRandomStringCode(20);
     $document->token = $token;
     // echo \yii\helpers\Url::home(true) . $value['original_url'];die;
     $document->money_url = Util::makeOuoUrl(\yii\helpers\Url::home(true) . $value['original_url']);
     //$value['user'] = 1; //for testing
     $user = Users::findOne(['id' => $value['user']]);
     if (!$user) {
         return Util::arrayError('Error !');
     }
     if ($document->save()) {
         $user->number_upload += 1;
         $user->points += 3;
         $user->save();
         return Util::arraySuccess('Success', $document->id);
     }
     return Util::arrayError('Error !');
 }
Example #2
0
 /**
  * Updates an existing ProductUnit model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         Util::save($model);
     }
     $searchModel = new ProductUnitSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('update', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 /**
  * Updates an existing ProductCategory model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->last_update = date("Y-m-d H:i:s");
         \app\components\Util::save($model);
     }
     $searchModel = new ProductCategorySearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('update', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Example #4
0
 public function actionLoginWithFacebook()
 {
     $request = Yii::$app->request;
     try {
         $value = array();
         $value['email'] = $request->post('email', '');
         $value['avatar'] = $request->post('avatar', '');
         $value['gender'] = $request->post('gender', '');
         $value['dob'] = $request->post('dob', '');
         $value['name'] = $request->post('name', '');
         $value['description'] = $request->post('description', '');
         $value['fb_id'] = $request->post('facebook_id', '');
         $result = Users::facebookLogin($value);
         return json_encode(Util::arraySuccess('Success', $result));
     } catch (Exception $ex) {
     }
 }
Example #5
0
 public function actionUpload()
 {
     $request = Yii::$app->request;
     $lang = $request->post('language', '');
     if ($lang == '') {
         return json_encode(Util::arrayError('Bạn phải chọn ngôn ngữ', ''));
     }
     $result = Util::multipleUpload('file');
     if (is_array($result)) {
         return json_encode(Util::arrayError($result['message'], ''));
     }
     $moss = new Moss(Yii::$app->params['moss_id']);
     $moss->setLanguage($lang);
     $moss->addByWildcard($result . '/*');
     $moss->setCommentString("This is a bluebee test");
     return json_encode(Util::arraySuccess('Thành công', $moss->send()));
 }
Example #6
0
 public function actionRateTeacher()
 {
     $request = Yii::$app->request;
     try {
         $teacher = $request->post('teacher', '');
         $check_teacher = Teachers::find()->where(['id' => $teacher])->count();
         if ($check_teacher == 0) {
             return json_encode(Util::arrayError('Giáo viên không tồn tại', ''));
         }
         $stars = $request->post('stars', '');
         if ($stars < 1 || $stars > 5) {
             return json_encode(Util::arrayError('Điểm không hợp lệ', ''));
         }
         $result = Teachers::rateTeacher($teacher, $stars);
         return json_encode(Util::arraySuccess('Success', $result));
     } catch (Exception $ex) {
     }
 }
Example #7
0
 public static function getUserById($id)
 {
     $retVal = array();
     $user = Users::findOne(['id' => $id]);
     $retVal['id'] = $user->id;
     $retVal['name'] = $user->name;
     $retVal['avatar'] = $user->avatar;
     $retVal['fb_id'] = $user->fb_id;
     $retVal['description'] = $user->description;
     $retVal['created_at'] = Date('d/m/Y', $user->created_at);
     $retVal['updated_at'] = Date('d/m/Y', $user->updated_at);
     $retVal['number_upload'] = $user->number_upload;
     $retVal['points'] = $user->points;
     $retVal['role'] = $user->role;
     $retVal['status'] = $user->status;
     $retVal['gender'] = \app\components\Util::getGender($user->gender);
     $retVal['dob'] = $user->dob;
     $retVal['email'] = $user->email;
     return $retVal;
 }
Example #8
0
        <div class="clearfix"></div>

        <div class="products grid row">
<?php 
foreach ($models as $item) {
    ?>
                <div class="col-sm-4 col-md-4 col-sm-4 col-md-4 product" style="float: left !important;">
                    <div class="default">
<!--                        <span class="sale top"></span>-->
                        <a href="<?php 
    echo Url::to(['document/item', 'id' => $item->id]);
    ?>
" class="product-image">
                            <img class="replace-2x" src="<?php 
    echo Util::makeUrlImage($item->preview);
    ?>
" alt="" title="" width="270" height="270">
                        </a>
                        <div class="product-description">
                            <div class="vertical">
                                <h3 class="product-name">
                                    <a href="<?php 
    echo Url::to(['document/item', 'id' => $item->id]);
    ?>
"><?php 
    echo $item->name;
    ?>
</a>
                                </h3>
 public function actionRegister()
 {
     $request = Yii::$app->request;
     $username = $request->post('username');
     $email = $request->post('email');
     $password = $request->post('password');
     if (empty($username) or empty($email) or empty($password)) {
         $this->setHeader(400);
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Missing params'), JSON_PRETTY_PRINT);
         exit;
     }
     $db = Yii::$app->db;
     $projectName = $request->post('gbid');
     if (!empty($projectName)) {
         $sql = "SELECT id FROM project WHERE name = :projectName";
         $params = [':projectName' => $projectName];
         $projectId = $db->createCommand($sql, $params)->queryScalar();
     }
     if (empty($projectId)) {
         $projectId = 0;
     }
     if (strlen($password) < 6 or strlen($password) > 20) {
         $this->setHeader(400);
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Password length must in [6, 20]'), JSON_PRETTY_PRINT);
         exit;
     }
     $email = trim($email);
     $sql = "SELECT 1 FROM user WHERE email = :email";
     $params = [':email' => $email];
     $emailExist = $db->createCommand($sql, $params)->queryScalar();
     if ($emailExist) {
         $this->setHeader(400);
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Email exists'), JSON_PRETTY_PRINT);
         exit;
     }
     $username = trim($username);
     $password = Util::hashPassword(trim($password));
     $sql = "INSERT user (name, password, email, project_id) VALUES (:name, :password, :email, :projectId)";
     $params = [':name' => $username, ':password' => $password, ':email' => $email, ':projectId' => $projectId];
     $db->createCommand($sql, $params)->execute();
     $sql = "SELECT id user_id, name user_name, project_id FROM user WHERE name = :name";
     $params = [':name' => $username];
     $data = $db->createCommand($sql, $params)->queryOne();
     $this->setHeader(200);
     echo json_encode(array('status' => 1, 'data' => $data, 'message' => 'Register success'), JSON_PRETTY_PRINT);
     exit;
 }
 public function actionRankList()
 {
     $user = Yii::$app->session->get('user');
     if (empty($user)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong request'], JSON_PRETTY_PRINT);
         exit;
     }
     $request = Yii::$app->request;
     $auctionId = $request->post('auctionId');
     if (empty($auctionId)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong params'], JSON_PRETTY_PRINT);
         exit;
     }
     $auction = Auction::find()->select('week, seats')->where(['id' => $auctionId])->limit(1)->one();
     $query = new Query();
     $rankInfoAry = $query->select('bid.offer, bid.created, `user`.family_name')->from('bid')->leftJoin('`user`', '`bid`.`user_id` = `user`.`id`')->where(['auction_id' => $auctionId])->orderBy(['bid.offer' => SORT_DESC, 'bid.id' => SORT_ASC])->all();
     $lang = Util::getLanguage();
     $view = $lang == 'en' ? 'rankList' : 'rankList-cn';
     Util::setLanguage($lang);
     return $this->render($view, compact('auction', 'rankInfoAry'));
 }
Example #11
0
 public function actionRegister()
 {
     $request = Yii::$app->request;
     $password = $request->post('password');
     $givenName = $request->post('givenName');
     $familyName = $request->post('familyName');
     $specialization = $request->post('specialization');
     //        $portfolio = $request->post('portfolio');
     $email = $request->post('email');
     $mobile = $request->post('mobile');
     $code = $request->post('code');
     if (empty($password) or empty($givenName) or empty($familyName) or empty($specialization) or empty($email) or empty($mobile) or empty($code)) {
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Missing params'), JSON_PRETTY_PRINT);
         exit;
     }
     $db = Yii::$app->db;
     $verify = Verify::find()->where(['mobile' => $mobile])->one();
     if (empty($verify)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong verify message'], JSON_PRETTY_PRINT);
     }
     if ($code != $verify->code) {
         echo json_encode(['status' => 0, 'message' => 'Wrong verify message'], JSON_PRETTY_PRINT);
     }
     if (strlen($password) < 6 or strlen($password) > 20) {
         $this->setHeader(400);
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Password length must in [6, 20]'), JSON_PRETTY_PRINT);
         exit;
     }
     $email = trim($email);
     $sql = "SELECT 1 FROM user WHERE email = :email";
     $params = [':email' => $email];
     $emailExist = $db->createCommand($sql, $params)->queryScalar();
     if ($emailExist) {
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Email exists'), JSON_PRETTY_PRINT);
         exit;
     }
     $phoneExist = $db->createCommand("SELECT 1 FROM user WHERE mobile = :mobile", [':mobile' => $mobile])->queryScalar();
     if ($phoneExist) {
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Mobile exists'), JSON_PRETTY_PRINT);
         exit;
     }
     $givenName = trim($givenName);
     $familyName = trim($familyName);
     $password = Util::hashPassword(trim($password));
     $user = new User();
     $user->password = $password;
     $user->given_name = $givenName;
     $user->family_name = $familyName;
     $user->specialization = $specialization;
     $user->email = $email;
     $user->mobile = $mobile;
     $user->is_verified = 1;
     $user->save();
     echo json_encode(array('status' => 1, 'message' => 'Register success'), JSON_PRETTY_PRINT);
     exit;
 }
Example #12
0
 public function actionAddWishlist()
 {
     $request = Yii::$app->request;
     try {
         $doc_id = $request->post('doc_id', '');
         $user_id = Yii::$app->session['user_id'];
         $check_doc = Documents::find()->where(['id' => $doc_id])->count();
         if ($check_doc == 0) {
             return json_encode(Util::arrayError('Không tồn tại tài liệu này', ''));
         }
         if (empty($user_id)) {
             return json_encode(Util::arrayError('Bạn chưa đăng nhập', ''));
         }
         $result = Wishlist::add($doc_id, $user_id);
         return json_encode(Util::arraySuccess('Thành công', $result));
     } catch (Exception $ex) {
     }
 }
Example #13
0
    echo $i;
    ?>
"><?php 
    echo $i;
    ?>
</option>
                            <?php 
}
?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="subject">Môn học</label>
                        <select class="form-control" id="subject" name="subject">
                            <?php 
$subjects = Util::getSubjects();
?>
                            <?php 
foreach ($subjects as $subject) {
    ?>
                                <option value="<?php 
    echo $subject->id;
    ?>
"><?php 
    echo $subject->name;
    ?>
</option>
                            <?php 
}
?>
                        </select>
Example #14
0
<?php

use yii\helpers\Url;
use app\components\Util;
?>
<div class="row">
    <article class="content product-page col-sm-12 col-md-12">
        <div class="row">
            <div class="col-sm-3 col-md-3">
                <div class="image-box">

                    <div class="general">
                        <img class="replace-2x" alt="" src="<?php 
echo Util::makeUrlImage($data['avatar']);
?>
" data-zoom-image="<?php 
echo Yii::getAlias('@web');
?>
/content/img/single-1.jpg" width="700" height="700">
                    </div><!-- .general-img -->
                </div>
            </div>

            <div class="col-sm-9 col-md-9">
                <div class="reviews-box">
                    <div class="rating-box">
                        <div style="width: 80%" class="rating">
                            <svg x="0" y="0" width="73px" height="12px" viewBox="0 0 73 12" enable-background="new 0 0 73 12" xml:space="preserve">

                            <?php 
for ($i = 1; $i <= $data['stars']; $i++) {
Example #15
0
                <th>Created at</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php 
foreach ($models as $model) {
    ?>
                <tr>
                    <td><input type="checkbox" > </td>
                    <td><?php 
    echo $model->id;
    ?>
</td>
                    <td><img src="<?php 
    echo Util::makeUrlImage($model->preview);
    ?>
" style="max-height: 150px;"/></td>
                    <td><?php 
    echo Users::findOne(['id' => $model->user])->name;
    ?>
</td>
                    <td><?php 
    echo Subjects::findOne(['id' => $model->subject])->name;
    ?>
</td>
                    <td><?php 
    echo Date('d/m/Y', $model->created_at);
    ?>
</td>
Example #16
0
        <div class="row">

            <?php 
foreach ($models as $item) {
    ?>
                <div class="col-sm-3 col-md-3">

                    <h6><a href="<?php 
    echo Url::to(['document/get-document-by-subject', 'id' => $item->id]);
    ?>
"><?php 
    echo $item->name;
    ?>
</a></h6>
                    <div class="text-small"><?php 
    echo Util::excerpt($item->description, 150);
    ?>
</div>

                </div>
            <?php 
}
?>
        </div>
        <?php 
if ($pages->getPageCount() > 1) {
    ?>
            <div class="pagination-box">
                <?php 
    echo LinkPager::widget(['pagination' => $pages]);
    ?>
Example #17
0
<?php

use yii\helpers\Url;
use app\components\Util;
foreach ($teachers as $item) {
    ?>
    <div class="col-sm-3 col-md-3 col-sm-3 col-md-3 employee rotation">
        <div class="default">

            <a href="<?php 
    echo Url::to(['item', 'id' => $item->id]);
    ?>
" class="image">
                <img class="replace-2x" src="<?php 
    echo Util::makeUrlImage($item->avatar);
    ?>
" alt="" title="" width="270" height="270">
            </a>
            <div class="description">
                <div class="vertical">
                    <h3 class="name">
                        <a href="<?php 
    echo Url::to(['item', 'id' => $item->id]);
    ?>
" style="color: white"><?php 
    echo $item->name;
    ?>
</a>
                    </h3>

                </div>
Example #18
0
                    </div>
                    <div class="modal-body">
                        <form role="form" id="form-upload">
                            <div class="form-group">
                                <label for="name">Tên tài liệu</label>
                                <input type="text" class="form-control" id="name" name="name" placeholder="Điền tên tài liệu">
                            </div>
                            <div class="form-group">
                                <label for="description">Miêu tả</label>
                                <textarea type="text" class="form-control" id="description" name="description" placeholder="Điền miêu tả tài liệu"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="subject">Môn học</label>
                                <select class="form-control" id="subject" name="subject">
                                    <?php 
$subjects = \app\components\Util::getSubjects();
?>
                                    <?php 
foreach ($subjects as $subject) {
    ?>
                                        <option value="<?php 
    echo $subject->id;
    ?>
"><?php 
    echo $subject->name;
    ?>
</option>
                                    <?php 
}
?>
                                </select>
Example #19
0
                <tr>
                    <td><input type="checkbox" > </td>
                    <td><?php 
    echo $model->id;
    ?>
</td>
                    <td><?php 
    echo $model->name;
    ?>
</td>
                    <td><?php 
    echo $model->description;
    ?>
</td>
                    <td><img src="<?php 
    echo Util::makeUrlImage($model->avatar);
    ?>
" ></td>
                    <td><?php 
    echo $model->email;
    ?>
</td>
                    <td><?php 
    echo $model->phone;
    ?>
</td>
                    <td><?php 
    echo $model->website;
    ?>
</td>
                    <td><?php 
Example #20
0
                Left"
                <?php 
    } else {
        ?>
                    Right"
                <?php 
    }
    ?>
                >
                    <h2 class="entry-title">
                        Các môn học theo khuyến nghị của nhà trường:
                    </h2>

                    <div class="entry-content">
                        <?php 
    $data = Util::suggest($department_id, $i);
    ?>

                            <?php 
    foreach ($data as $item) {
        ?>
                                   <a href="<?php 
        echo \yii\helpers\Url::to(['document/get-document-by-subject', 'id' => $item['subject_id']]);
        ?>
"> <?php 
        echo $item['subject'];
        ?>
</a><br>
                            <?php 
    }
    ?>