Beispiel #1
0
 /**
  * @param $userId
  * @return SubscriptionModel|null
  */
 public function readById($userId)
 {
     $model = new SubscriptionModel();
     $model->setUserId($userId);
     if ($this->validateModel($model)) {
         return $this->dao->readByUserId($model);
     } else {
         echo "<br>ERROR: User information is invalid!";
     }
     return null;
 }
Beispiel #2
0
 /**
  * @param $model
  * @return array|null
  */
 public function readByUserId($model)
 {
     $data = null;
     $result = null;
     $userId = $model->getUserId();
     $sql = "SELECT *\n                    FROM tblSubscription\n                    WHERE `userId` = '{$userId}'";
     $response = $this->dao->connection->query($sql);
     $numberRow = mysqli_num_rows($response);
     if ($numberRow >= 2) {
         $row = mysqli_fetch_all($response);
         $i = $numberRow - 1;
         while ($i != -1) {
             $j = 0;
             $id = $row[$i][$j];
             $userId = $row[$i][++$j];
             $type = $row[$i][++$j];
             $receiver = $row[$i][++$j];
             $status = $row[$i][++$j];
             $model = new SubscriptionModel();
             $model->setId($id);
             $model->setUserId($userId);
             $model->setReceiver($receiver);
             $model->setStatus($status);
             $model->setType($type);
             $array[$i] = array($model);
             --$i;
         }
     } elseif (mysqli_num_rows($response) == 1) {
         $response = mysqli_fetch_array($response);
         $model = new SubscriptionModel();
         $id = $response['id'];
         $userId = $response['userId'];
         $receiver = $response['receiver'];
         $type = $response['status'];
         $status = $response['type'];
         $model->setId($id);
         $model->setUserId($userId);
         $model->setReceiver($receiver);
         $model->setStatus($status);
         $model->setType($type);
         $array[0] = $model;
     } else {
         return $array = null;
     }
     return $array;
 }