示例#1
0
 public function save()
 {
     if (!$this->emptyAttr('id')) {
         $item = R::findOne('room_pattern', 'id=?', [$this->getAttr('id')]);
         $item->updated_at = date('Y-m-d H:i:s');
     } else {
         $item = R::xdispense('room_pattern');
         $item->created_at = date('Y-m-d H:i:s');
         $item->updated_at = date('Y-m-d H:i:s');
     }
     $item->room_id = $this->getAttr('room_id');
     $item->name = $this->getAttr('name');
     $item->width = $this->getAttr('width');
     $item->height = $this->getAttr('height');
     $item->tileWidth = $this->getAttr('tile_width');
     $item->tileHeight = $this->getAttr('tile_height');
     $item->tileSizeUnit = $this->getAttr('tile_size_unit');
     $item->product_use = ',' . implode(',', $this->getAttr('product_use')) . ',';
     if (!$this->emptyAttr('picture') && $this->attr['picture']->uploaded) {
         $picture = $this->getAttr('picture');
         $picture->file_new_name_body = $this->generateName("pattern_picture_");
         $picture->image_convert = 'jpeg';
         $picture->process('upload/');
         $this->pushDeleteWhenSuccess('upload/' . $item->picture);
         $this->pushDeleteWhenFailed('upload/' . $picture->file_dst_name);
         $item->picture = $picture->file_dst_name;
     }
     if (!$this->emptyAttr('thumb') && $this->attr['thumb']->uploaded) {
         $thumb = $this->getAttr('thumb');
         $thumb->file_new_name_body = $this->generateName("pattern_thumb_");
         $thumb->image_convert = 'jpeg';
         $thumb->image_resize = true;
         $thumb->image_x = 150;
         $thumb->image_y = 150;
         $thumb->process('upload/');
         $this->pushDeleteWhenSuccess('upload/' . $item->thumb);
         $this->pushDeleteWhenFailed('upload/' . $thumb->file_dst_name);
         $item->thumb = $thumb->file_dst_name;
     }
     $success = R::store($item);
     if ($success) {
         $this->handlerSuccess();
     } else {
         $this->handlerFailed();
     }
     return $success;
 }
示例#2
0
 /**
  * Insert or update a facebook user.
  *
  * @param array $payload            
  */
 public static function upsert($payload)
 {
     R::freeze(false);
     // if no session set add it
     if (!isset($payload['session'])) {
         $payload['session'] = session_id();
     }
     // Find an existing user in db by session
     $user = R::findOne(USER, 'session = :session AND ip = :ip ', array(':session' => $payload['session'], ':ip' => $payload['ip']));
     // if we have a payload with id set the facebook id
     if (isset($payload['id'])) {
         // change the id into fbid.
         $payload['fbid'] = '' . $payload['id'];
         unset($payload['id']);
     }
     if (isset($payload['email'])) {
         $emailuser = R::findOne(USER, 'email = :email ', array(':email' => $payload['email']));
         if ($emailuser) {
             $user = $emailuser;
         }
     }
     if (isset($payload['fbid'])) {
         $fbiduser = R::findOne(USER, 'fbid = :fbid ', array(':fbid' => $payload['fbid']));
         if ($fbiduser) {
             $user = $fbiduser;
         }
     }
     // the date
     $currentDate = new \DateTime();
     if (!$user) {
         $user = R::xdispense(USER);
         $user->createdate = $currentDate->format('Y-m-d H:i:s');
     }
     $user->import($payload);
     // update the lastupdated timestamp
     $user->lastupdate = $currentDate->format('Y-m-d H:i:s');
     R::store($user);
 }
示例#3
0
 /**
  */
 function populate()
 {
     // do not execute this function
     return;
     R::freeze(false);
     R::nuke();
     $quiz = R::xdispense(QUIZ);
     $quiz->theme = 'starwars';
     $quiz->nextaction = '/';
     R::store($quiz);
     $question = R::xdispense(QUESTION);
     $question->title = "Which Star Wars Character Are You?!";
     R::store($question);
     $question->{QUIZ} = $quiz;
     R::store($question);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Han Solo';
     $answer->message = "You have a strong and determined personality, but beneath your tough exterior you have a loving heart and an inner bravery that will help you through the tough times. You learn from your mistakes and always stay true to yourself!";
     $answer->sharemessage = "I have a strong and determined personality, but beneath my tough exterior I have a loving heart and an inner bravery that helps me through the tough times. I learn from my mistakes and always stay true to myself! Who would you be?";
     $answer->image = 'A';
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Luke Skywalker';
     $answer->message = "You're courageous, eager for adventure and an all-round hero. Sometimes you find it hard to control your emotions, but you always have the happiness and wellbeing of others at heart!";
     $answer->sharemessage = "I'm courageous, eager for adventure and an all-round hero. Sometimes I find it hard to control my emotions, but I always have the happiness and wellbeing of others at heart! Who would you be?";
     $answer->image = 'B';
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Princess Leia';
     $answer->image = 'C';
     $answer->message = "You're level-headed, courageous, and with a sharp-tongued wit surpassed only by your beauty. You've been through some tough times but always come out stronger in the end!";
     $answer->sharemessage = "I'm level-headed, courageous, and with a sharp-tongued wit surpassed only by my beauty. I've been through some tough times but always come out stronger in the end! Who would you be?";
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Chewbacca';
     $answer->image = 'D';
     $answer->message = "You may look tough, and even scary to some people, but deep down you're a big softie. You're loyal, affectionate and humble - but if you think something isn't fair you're not afraid to say so! ";
     $answer->sharemessage = "I may look tough, and even scary to some people, but deep down I'm a big softie. I'm loyal, affectionate and humble - but if I think something isn't fair I'm not afraid to say so! Who would you be?";
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Finn';
     $answer->image = 'E';
     $answer->message = "Despite what life has thrown at you, you have a good heart and true empathy for other people. You are brave, intelligent and with the strength to face down whatever life throws at you!";
     $answer->sharemessage = "Despite what life has thrown at me, I have a good heart and true empathy for other people. I am brave, intelligent and with the strength to face down whatever life throws at me! Who would you be?";
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $answer = R::xdispense(ANSWER);
     $answer->title = 'Rey';
     $answer->image = 'F';
     $answer->message = "You have a heart full of generosity and a desire to help others, often putting their needs before your own. You have a great imagination that sets you apart from the majority of others!";
     $answer->sharemessage = "I have a heart full of generosity and a desire to help others, often putting their needs before my own. I have a great imagination that sets me apart from the majority of others! Who would you be?";
     $answer->{QUIZ} = $quiz;
     $answer->{QUESTION} = $question;
     R::store($answer);
     $quiz_user = array('createdate' => '2016-02-08 19:20:37', 'name' => 'Matteo Monti Matteo Monti Matteo Monti Matteo Monti Matteo Monti', 'email' => 'mmonti@gmail.commmonti@gmail.commmonti@gmail.commmonti@gmail.commmonti@', 'gender' => 'maleorfemale', 'ip' => '151.237.238.110', 'fbid' => '1a01544915asdasdasdasdasdasd51609838e16', 'lastupdate' => '2016-02-08 19:20:37', 'city' => 'Leccooranotherlocationwhatever', 'country' => 'Leccooranotherlocationwhatever', 'latitude' => '45.85a', 'longitude' => '9.38333a');
     $user = R::xdispense(USER);
     $user->import($quiz_user);
     R::store($user);
     R::wipe(USER);
     R::freeze(true);
     return $quiz;
 }
示例#4
0
 /**
  * @param null $contents
  * @return int|string
  */
 public function create($contents = null)
 {
     $this->instance = R::xdispense($this->table);
     return is_null($contents) ? $this : $this->with($contents);
 }
示例#5
0
 public function addProduct()
 {
     $productId = $this->slim->request->params('product_id');
     $token = $this->slim->request->params('token');
     if (empty($token)) {
         header('Content-Type: application/json');
         echo json_encode(['error' => 'REQUIRE_AUTHORIZE'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         exit;
     }
     $account = R::findOne("account", "token = ?", [$token]);
     if (!$account) {
         header('Content-Type: application/json');
         echo json_encode(['error' => 'AUTHORIZE_FAILED'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         exit;
     }
     $product = R::findOne("product", "id = ?", [$productId]);
     if (!$product) {
         header('Content-Type: application/json');
         echo json_encode(['error' => 'PRODUCT_NOT_FOUND'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         exit;
     }
     $old = R::findOne("account_product", "account_id = ? AND product_id = ?", [$account['id'], $productId]);
     if ($old) {
         header('Content-Type: application/json');
         echo json_encode(['error' => 'DUPLICATE_ITEM'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         exit;
     }
     $item = R::xdispense('account_product');
     $item->created_at = date('Y-m-d H:i:s');
     $item->account_id = $account['id'];
     $item->product_id = $product['id'];
     R::store($item);
     $this->productAddStat($product['id']);
     header('Content-Type: application/json');
     echo json_encode(['success' => true], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }
示例#6
0
 /**
  * TODO: Update to similar to updateBean
  * Store Data into Database
  * @param $data
  * @return int|string
  */
 public function insertBean($data)
 {
     $bean = R::xdispense($this->tableName);
     if ($this->beforeInsertBean != null) {
         $callable = $this->beforeInsertBean;
         $callable($bean);
     }
     $result = $this->saveBean($bean, $data);
     if (!isset($result->msg)) {
         $result->msg = "The record has been created successfully.";
         $result->class = "callout-info";
         $result->ok = true;
     } else {
         $result->ok = false;
     }
     if ($this->afterInsertBean != null) {
         $callable = $this->afterInsertBean;
         $callable($bean, $result);
     }
     return $result;
 }