Skip to content

Commit

Permalink
New system release
Browse files Browse the repository at this point in the history
Merge branch 'release/2.1.10'
  • Loading branch information
maso committed Dec 7, 2017
2 parents 2730fc5 + 35205e0 commit fb69df6
Show file tree
Hide file tree
Showing 16 changed files with 673 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: tests/clover.xml
json_path: tests/coveralls-upload.json
28 changes: 21 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
language: php
php:
- '5.6'
- '7.1'

services:
- mysql

git:
depth: 1

mysql:
database: test
Expand All @@ -9,16 +16,23 @@ mysql:

before_install:
- sudo apt-get update > /dev/null
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"

- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'

install:
- php composer.phar install
# Install composer packages, will also trigger dump-autoload
- travis_retry composer install --no-interaction
# Install coveralls.phar
- wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- chmod +x coveralls.phar
- php coveralls.phar --version

script:
- cd tests
- php run.php
- php coverage-checker.php clover.xml 70
- cd ..

after_success:
# Submit coverage report to Coveralls servers, see .coveralls.yml
- travis_retry php coveralls.phar -v
# Submit coverage report to codecov.io
- bash <(curl -s https://codecov.io/bash)
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# tenant

[![Build Status](https://travis-ci.org/pluf/tenant.svg?branch=master)](https://travis-ci.org/pluf/tenant)
[![codecov](https://codecov.io/gh/pluf/tenant/branch/master/graph/badge.svg)](https://codecov.io/gh/pluf/tenant)
[![Coverage Status](https://coveralls.io/repos/github/pluf/tenant/badge.svg?branch=master)](https://coveralls.io/github/pluf/tenant?branch=master)

# Develop


[![Build Status](https://travis-ci.org/pluf/tenant.svg?branch=develop)](https://travis-ci.org/pluf/tenant)

It is a Pluf module to manage current tenant.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"minimum-stability" : "stable",
"require" : {
"pluf/core" : "^2.1.0",
"pluf/user" : "^2.1.0"
"pluf/user" : "^2.1.0",
"pluf/discount" : "^2.1.0",
"pluf/bank" : "^2.1.0"
},
"require-dev" : {
"pluf/test" : "^2.1.0",
"pluf/collection" : "^2.1.0"
"pluf/test" : "^2.1.0"
},
"include-path" : [
"src/"
Expand Down
20 changes: 20 additions & 0 deletions src/Tenant/BankBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Tenant_BankBackend extends Bank_Backend
{

function init()
{
parent::init();
$this->_a['multitenant'] = false;
$this->_a['cols'] = array_merge($this->_a['cols'], array(
'tenant' => array(
'type' => 'Pluf_DB_Field_Foreignkey',
'model' => 'Pluf_Tenant',
'blank' => false,
'unique' => true,
'editable' => false
)
));
}
}
53 changes: 53 additions & 0 deletions src/Tenant/BankReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* ساختارهای داده‌ای برای رسید را ایجاد می‌کند.
*
* رسید عبارت است از یک مجموعه از داده‌ها که برای پرداخت به بانک ارسال
* می‌شود. این رسید زمانی که بانک تایید کند به روز شده و اطلاعات دریافتی
* از بانک نیز به آن اضافه می شود.
*
* رسید در اینجا مثل رسید در ماژول بانک است با این تفاوت که این رسید تنها برای پرداخت‌های مربوط به tenant است.
*
* @author hadi
*
*/
class Tenant_BankReceipt extends Bank_Receipt
{

/**
* @see Bank_Receipt::init()
*/
function init()
{
parent::init();
// Change class type of backend foreingkey from Bank_Backend to Tenant_BankBackend
$this->_a['cols'] = array_merge($this->_a['cols'], array(
'backend' => array(
'type' => 'Pluf_DB_Field_Foreignkey',
'model' => 'Tenant_BankBackend',
'blank' => false,
'relate_name' => 'backend'
)
));
}

}
67 changes: 67 additions & 0 deletions src/Tenant/BankService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

class Tenant_BankService
{

/**
* یک پرداخت جدید ایجاد می‌کند
*
* روالی که برای ایجاد یک پرداخت دنبال می‌شه می‌تونه خیلی متفاوت باشه
* و ساختارهای رو برای خودش ایجاد کنه. برای همین ما پارامترهای ارسالی در
* در خواست رو هم ارسال می‌کنیم.
*
* پرداخت ایجاد شده بر اساس اطلاعاتی است که با متغیر $reciptParam ارسال
* می‌شود. این پارامترها
* باید به صورت یک آرایه بوده و شامل موارد زیر باشد:
*
* <pre><code>
* $param = array(
* 'amount' => 1000, // مقدار پرداخت به ریال
* 'title' => 'payment title',
* 'description' => 'description',
* 'email' => '[email protected]',
* 'phone' => '0917222222',
* 'callbackURL' => 'http://.....',
* 'backend' => 2
* );
* </code></pre>
*
* <ul>
* <li>*amount: مقدار بر اساس ریال</li>
* <li>*title: عنوان پرداخت</li>
* <li>*description: توضیحات</li>
* <li>email: رایانامه مشتری</li>
* <li>phone: شماره تماس مشتری</li>
* <li>callbackURL: آدرسی که بعد از تکمیل باید فراخوانی شود</li>
* <li>*backend: درگاه پرداخت مورد نظر</li>
* </ul>
*
* در نهایت باید موجودیتی تعیین بشه که این پرداخت رو می‌خواهیم براش ایجاد
* کنیم.
*
* نکته مهم اینکه در این پیاده‌سازی backend باید مربوط به ملک اصلی باشه.
*
* @param array $param
* @param Pluf_Model $owner
* @return Bank_Receipt
*/
public static function create ($param, $owner = null, $ownerId = null)
{
$form = new Tenant_Form_BankReceiptNew($param);
$receipt = $form->save(false);
// $backend = Pluf::factory('Tenant_BankBackend', $receipt->backend);
$backend = $receipt->get_backend();
$engine = $backend->get_engine();
$engine->create($receipt);
if ($owner instanceof Pluf_Model) { // Pluf module
$receipt->owner_class = $owner->getClass();
$receipt->owner_id = $owner->getId();
} elseif (! is_null($owner)) { // module
$receipt->owner_class = $owner;
$receipt->owner_id = $ownerId;
}
$receipt->create();
return $receipt;
}

}
94 changes: 94 additions & 0 deletions src/Tenant/Form/BankReceiptNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* This form is same as Bank_Form_RecieptNew form except that in this form given backend
* sould blong to main tenant
*
* @author hadi <mohammad.hadi.mansouri@dpq.co.ir>
*
*/
class Tenant_Form_BankReceiptNew extends Bank_Form_ReceiptNew
{

function clean_backend()
{
$backend = Pluf::factory('Tenant_BankBackend', $this->cleaned_data['backend']);
if ($backend->isAnonymous()) {
throw new Pluf_Exception('backend not found');
}
// Check if backend blong to main tenant
$mainTenant = Tenant_Shortcuts_GetMainTenant();
if ($backend->tenant !== $mainTenant->getId()) {
throw new Pluf_Exception('backend is not valid for this payment');
}
// XXX: maso, 1395: گرفتن پشتوانه
return $backend->id;
}

/**
*
* @param string $commit
* @throws Pluf_Exception
* @return Tenant_BankBackend
*/
function save ($commit = true)
{
if (! $this->isValid()) {
// TODO: maso, 1395: باید از خطای مدل فرم استفاده شود.
throw new Pluf_Exception(
'Cannot save a receipt from an invalid form.');
}
// Set attributes
$receipt = new Tenant_BankReceipt();
$receipt->setFromFormData($this->cleaned_data);
$receipt->secure_id = $this->getSecureKey();
// موجودیت قرار گیرد.
if ($commit) {
if (! $receipt->create()) {
throw new Pluf_Exception('fail to create the recipt.');
}
}
return $receipt;
}

/**
* یک کد جدید برای موجودیت ایجاد می‌کند.
*
* @return Tenant_BankReceipt
*/
private function getSecureKey ()
{
$recipt = new Tenant_BankReceipt();
while (1) {
$key = sha1(
microtime() . rand(0, 123456789) . Pluf::f('secret_key'));
$sess = $recipt->getList(
array(
'filter' => 'secure_id=\'' . $key . '\''
));
if (count($sess) == 0) {
break;
}
}
return $key;
}
}

21 changes: 10 additions & 11 deletions src/Tenant/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function init()
'blank' => false,
'is_null' => false
),
'due_dtiem' => array(
'due_dtime' => array(
'type' => 'Pluf_DB_Field_Date',
'blank' => false,
'is_null' => false
Expand Down Expand Up @@ -74,7 +74,7 @@ function init()
// relations
'payment' => array(
'type' => 'Pluf_DB_Field_Foreignkey',
'model' => 'Bank_Receipt',
'model' => 'Tenant_BankReceipt',
'blank' => false,
'editable' => false,
'readable' => true,
Expand Down Expand Up @@ -131,15 +131,14 @@ function getStatus()

function setStatus($status)
{
// if ($this->status === 'payed') {
// return;
// }
// // It is first time to activate invoice
// // Note: Hadi - 1396-04: time is base on day
// $day = Setting_Service::get(Tenant_Constants::SETTING_KEY_LINK_VALID_DAY, '30');
// $expiryDay = ' +' . $day . ' day';
// $this->expiry = date('Y-m-d H:i:s', strtotime($expiryDay));
// $this->active = true;
if ($this->status === 'payed') {
return;
}
// It is first time to update status of invoice
// Note: Hadi - 1396-04: time is base on day
// $day = Setting_Service::get(Tenant_Constants::SETTING_KEY_INVOICE_VALID_DAY, '30');
// $expiryDay = ' +' . $day . ' day';
// $this->expiry = date('Y-m-d H:i:s', strtotime($expiryDay));
$this->status = $status;
$this->update();
}
Expand Down
23 changes: 23 additions & 0 deletions src/Tenant/Shortcuts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

function Tenant_Shortcuts_GetMainTenant ()
{
$subdomain = Pluf::f('tenant_default', null);
if($subdomain === null){
throw new Pluf_Exception_DoesNotExist('tenant_default is not set!');
}
$tenant = Pluf_Tenant::bySubDomain($subdomain);
if ($tenant == null || $tenant->id <= 0) {
throw new Pluf_Exception_DoesNotExist(
"Tenant not found (subdomain:" . $subdomain . ")");
}
return $tenant;
}

function Tenant_Shortcuts_NormalizeItemPerPage ($request)
{
$count = array_key_exists('_px_c', $request->REQUEST) ? intval($request->REQUEST['_px_c']) : 30;
if($count > 30)
$count = 30;
return $count;
}
2 changes: 1 addition & 1 deletion src/Tenant/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function current ($request, $match)
public static function update ($request, $match)
{
$model = $request->tenant;
$form = Pluf_Shortcuts_GetFormForModel($model, $request->REQUEST,
$form = Pluf_Shortcuts_GetFormForUpdateModel($model, $request->REQUEST,
array());
return new Pluf_HTTP_Response_Json($form->save());
}
Expand Down
Loading

0 comments on commit fb69df6

Please sign in to comment.