public function actionLike()
 {
     if (!\Yii::$app->getRequest()->getIsPost()) {
         return 'try agaen';
     }
     if (\Yii::$app->getRequest()->getHeaders()->get('x-like') !== 'True') {
         return 'try agaen';
     }
     $pictureId = \Yii::$app->getRequest()->post('p');
     $hash = \Yii::$app->getRequest()->post('h');
     $picture = Picture::find()->where(['id' => $pictureId])->one();
     /* @var Picture $picture */
     if ($picture == null) {
         return 'try agaen';
     }
     if ($picture->getLikeHash() !== $hash) {
         return 'try agaen';
     }
     $like = Like::find()->where(['ip' => \Yii::$app->getRequest()->getUserIP(), 'pictureId' => $picture->getPrimaryKey()])->count();
     if ($like > 0) {
         return 'pls stap';
     }
     $like = new Like();
     $like->ip = \Yii::$app->getRequest()->getUserIP();
     $like->pictureId = $picture->getPrimaryKey();
     $like->save();
     $picture->likeCount += 1;
     $picture->save();
     return '+' . $picture->likeCount;
 }
 public function actionQueue()
 {
     $query = Picture::find()->where(['state' => 'new']);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 50]);
     $pages->pageSizeParam = false;
     $pictures = $query->offset($pages->offset)->limit($pages->limit)->orderBy('id asc')->all();
     return $this->render('queue', ['pictures' => $pictures, 'paginator' => $pages]);
 }
 public function check()
 {
     $count = Picture::find()->where(['ip' => \Yii::$app->getRequest()->getUserIP()])->andWhere(['state' => 'new'])->count();
     if ($count >= 3) {
         $this->addError('image', 'Sorry, you cannot upload more than 3 images while they in queue. Try later.');
         return false;
     }
     return true;
 }
 public function actionClear()
 {
     $pictures = Picture::find()->where(['<=', 'updated', new Expression('NOW() - INTERVAL 5 MINUTE')])->andWhere(['state' => 'pending'])->all();
     /* @var Picture[] $pictures */
     foreach ($pictures as $pic) {
         echo "Pending picture #" . $pic->id . " was detached and become 'new' now.\n";
         $pic->state = 'new';
         $pic->save();
     }
     echo "Okay.\n";
 }
Exemple #5
0
 public function update($fieldsCols = null)
 {
     parent::update();
     $item = \app\models\Picture::find($this->id);
     $fields = [];
     if ($item->getField('description') == '') {
         $fields['description'] = GsssHtml::getMiniText($item->getField('content'));
     }
     if (count($fields) > 0) {
         $item->update($fields);
     }
     return true;
 }
 public function up()
 {
     $algo = new \app\models\Algorithm();
     $algo->name = 'inception_4c/output';
     $algo->count = \app\models\Picture::find()->count();
     $algo->save();
     $pk = $algo->getPrimaryKey();
     \app\models\Picture::updateAll(['algorithm' => 'inception_4c/output', 'algorithmId' => $pk]);
     $other = ['conv2/3x3', 'conv2/3x3_reduce', 'conv2/norm2', 'inception_3a/3x3', 'inception_3a/3x3_reduce', 'inception_3a/5x5_reduce', 'inception_3a/output', 'inception_3a/pool', 'inception_3b/1x1', 'inception_3b/3x3', 'inception_3b/3x3_reduce', 'inception_3b/5x5_reduce', 'inception_3b/output', 'inception_3b/pool', 'inception_3b/pool_proj', 'inception_4a/1x1', 'inception_4a/3x3_reduce', 'inception_4a/5x5_reduce', 'inception_4b/pool'];
     foreach ($other as $name) {
         $algo = new \app\models\Algorithm();
         $algo->count = 0;
         $algo->name = $name;
         $algo->save();
     }
 }
 public function actionStatus()
 {
     $pendingImageCount = Picture::find()->where(['state' => 'new'])->count();
     $pendingPictures = Picture::find()->where(['state' => 'pending'])->orderBy('id ASC')->all();
     $response = [];
     foreach ($pendingPictures as $pic) {
         $progress = (int) (100.0 * $pic->status / 40);
         $response[] = ['id' => $pic->id, 'source' => '/images/' . $pic->source, 'progress' => $progress];
     }
     echo json_encode(['images' => $response, 'queue' => $pendingImageCount]);
 }