public static function createAdoption($adoptionObj)
    {
        $user_id_adopter = \Core\Db::escape($adoptionObj->getUserIdAdopter());
        $user_id_poster = \Core\Db::escape($adoptionObj->getUserIdPoster());
        $pet_id = \Core\Db::escape($adoptionObj->getPetId());
        $created = $adoptionObj->getCreated();
        $updated = $adoptionObj->getUpdated();
        $visibility = $adoptionObj->getVisibility();
        $sql = <<<q
INSERT INTO `adoption`(
`id`,
`user_id_adopter`, 
`user_id_poster`,
`pet_id`,
`created`,
`updated`,
`visibility`) 
VALUES (
DEFAULT,
'{$user_id_adopter}',
'{$user_id_poster}',
'{$pet_id}',
{$created},
{$updated},
'{$visibility}');
q;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }
Example #2
0
    /**
     * Create a new user in the database
     * @param type $userObj  an instance of the class User
     * @return type mixed    false if insert fails, integer of newly created row otherwise
     */
    public static function createUser($userObj)
    {
        $username = \Core\Db::escape($userObj->getUsername());
        $password = \Core\Db::escape($userObj->getPassword());
        $email = \Core\Db::escape($userObj->getEmail());
        $created = time();
        $updated = time();
        $isAdmin = $userObj->getIsAdmin();
        $lastLogin = \Core\Db::escape($userObj->getLastLogin());
        $sql = <<<q
INSERT INTO `user`(
`id`, 
`username`,
`password`,
`email`,
`created`, 
`updated`,
`is_admin`,
`last_login`) 
VALUES (
DEFAULT,
'{$username}',
'{$password}',
'{$email}',
{$created},
{$updated},
{$isAdmin},
DEFAULT);
q;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
        // returns id of newly created row
    }
Example #3
0
    public static function createPet($petObj)
    {
        $name = \Core\Db::escape($petObj->getName());
        $description = \Core\Db::escape($petObj->getDescription());
        $specialNeeds = \Core\Db::escape($petObj->getSpecialNeeds());
        $weight = \Core\Db::escape($petObj->getWeight());
        $species = \Core\Db::escape($petObj->getSpecies());
        $breed = \Core\Db::escape($petObj->getBreed());
        $age = $petObj->getAge();
        $sex = \Core\Db::escape($petObj->getSex());
        $userId = \Core\Db::escape($petObj->getUserId());
        $adoptionId = \Core\Db::escape($petObj->getAdoptionId());
        $created = $petObj->getCreated();
        $updated = $petObj->getUpdated();
        $visibility = $petObj->getVisibility();
        $approved = $petObj->getApproved();
        $sql = <<<q
INSERT INTO `pet`(
`id`, 
`name`,
`description`,
`special_needs`,
`weight`, 
`species`,
`breed`,
`age`,
`sex`,                
`user_id`,
`adoption_id`,
`created`,
`updated`,
`visibility`,
`approved` 
) 
VALUES (
DEFAULT,
'{$name}',
'{$description}',
'{$specialNeeds}',
{$weight},
'{$species}',
'{$breed}',
{$age},
'{$sex}',
'{$userId}',
'{$adoptionId}',
{$created},
{$updated},
'{$visibility}',
{$approved}
);
q;
        //var_dump($sql);
        //exit;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }
Example #4
0
    public static function createImage($imageObj)
    {
        $name = \Core\Db::escape($imageObj->getName());
        $fileName = \Core\Db::escape($imageObj->getFileName());
        $fileType = \Core\Db::escape($imageObj->getFileType());
        $fileSize = \Core\Db::escape($imageObj->getFileSize());
        $width = \Core\Db::escape($imageObj->getWidth());
        $height = \Core\Db::escape($imageObj->getHeight());
        $description = \Core\Db::escape($imageObj->getDescription());
        $thumbnails = \Core\Db::escape(json_encode($imageObj->getThumbnails()));
        $petId = $imageObj->getPetId();
        $created = $imageObj->getCreated();
        $updated = $imageObj->getUpdated();
        $sql = <<<q
INSERT INTO `image`(
`id`, 
`name`,
`file_name`, 
`file_type`, 
`file_size`, 
`width`, 
`height`, 
`description`, 
`thumbnails`,
`pet_id`,
`created`, 
`updated`
) 
VALUES (
DEFAULT,
'{$name}',
'{$fileName}',
'{$fileType}',
{$fileSize},
{$width},
{$height},
'{$description}',
'{$thumbnails}',
'{$petId}',
{$created},
{$updated}
);
q;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }
Example #5
0
    /**
     * Create a basket
     * @param type $basketObj
     * @return type
     */
    public static function createBasket($basketObj)
    {
        $userId = \Core\Db::escape($basketObj->getUserId());
        $petId = \Core\Db::escape($basketObj->getPetId());
        $sql = <<<q
INSERT INTO `basket`(
`id`, 
`user_id`,
`pet_id`
) 
VALUES (
DEFAULT,
'{$userId}',
'{$petId}'
);
q;
        //echo "<br/><br/>" . $sql . "<br/><br/>";
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }
Example #6
0
    public static function createMesage($messageObj)
    {
        $senderId = \Core\Db::escape($messageObj->getSenderId());
        $recipientId = \Core\Db::escape($messageObj->getRecipientId());
        $threadId = $messageObj->getThreadId() === 'new' ? self::getNextThread() : \Core\Db::escape($messageObj->getThreadId());
        if ($threadId === null) {
            throw new Exception("Error, no next thread id returned from db query");
        }
        $message = \Core\Db::escape($messageObj->getMessage());
        $created = time();
        $updated = time();
        $senderVisibility = $messageObj->getSenderVisibility();
        $recipientVisibility = $messageObj->getRecipientVisibility();
        $sql = <<<q
INSERT INTO `message`(
`id`, 
`sender_id`,
`recipient_id`,
`thread_id`,
`message`,
`created`, 
`updated`,
`sender_visibility`,
`recipient_visibility`
) VALUES (
DEFAULT,
{$senderId},
{$recipientId},
{$threadId},
'{$message}',
{$created},
{$updated},
{$senderVisibility},
{$recipientVisibility});
q;
        //var_dump($sql);
        //exit;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }