Просмотр исходного кода

sync xero client to user, succeed

master
patrick 6 лет назад
Родитель
Сommit
9eec35a6d1
5 измененных файлов: 149 добавлений и 20 удалений
  1. +12
    -1
      Xero.php
  2. +76
    -14
      css/bts_timesheet.css
  3. +12
    -1
      js/bts_timesheet.js
  4. +1
    -1
      js/ts.js
  5. +48
    -3
      ts.php

+ 12
- 1
Xero.php Просмотреть файл

@@ -36,6 +36,17 @@ class Xero {
public function __construct(){
$this->xero = new PrivateApplication($this->office_config());
}
public function getClients($contact_group_id){
$xero = $this->xero;
$cg = $xero->loadByGUID("Accounting\\ContactGroup", $contact_group_id);
$contacts = $cg->getContacts();
return $contacts;
}
public function getContact($id){
$user = $this->xero->loadByGUID("Accounting\\Contact",$id);
return $user;
}
}

+ 76
- 14
css/bts_timesheet.css Просмотреть файл

@@ -1,5 +1,3 @@
@CHARSET "UTF-8";

html,
body {
margin: 0px !important;
@@ -148,7 +146,7 @@ div.peopleitem .card {
box-shadow: 1px 1px 10px black;
}

div.peopleitem .card div {
div.peopleitem .card > div {
position: absolute;
height: 100%;
width: 100%;
@@ -417,7 +415,8 @@ div.week2 {
padding-right: 10px;
}

div.week1:after, div.week2:after{
div.week1:after,
div.week2:after {
content: '';
display: inline-block;
width: 100%;
@@ -433,7 +432,8 @@ div.week2 {
left: 10px;
}

div.week1 > div, div.week2 > div{
div.week1 > div,
div.week2 > div {
display: inline-block;
text-align: center;
width: 10%;
@@ -443,15 +443,16 @@ div.week1 > div, div.week2 > div{
font-weight: bolder;
}

div.week1 > div{
div.week1 > div {
box-shadow: 0px 0px 10px white inset;
}
div.week2 > div{

div.week2 > div {
background-color: dodgerblue;
box-shadow: 0px 0px 10px white inset;
}

div.sheettableheader{
div.sheettableheader {
margin-top: 0px;
height: 30px;
background-color: lightgrey;
@@ -459,7 +460,16 @@ div.sheettableheader{
overflow-y: scroll;
}

div.bday, div.bdate, div.btos, div.bstart, div.bfinish, div.bhours, div.bstaff, div.bclients, div.bconfirmed, div.bdelete{
div.bday,
div.bdate,
div.btos,
div.bstart,
div.bfinish,
div.bhours,
div.bstaff,
div.bclients,
div.bconfirmed,
div.bdelete {
display: block;
float: left;
background-color: black;
@@ -468,21 +478,73 @@ div.bday, div.bdate, div.btos, div.bstart, div.bfinish, div.bhours, div.bstaff,
font-weight: bolder;
font-size: 20px;
color: white;

/* box-shadow: 1px 1px 10px black; */
width:10%;
width: 10%;
height: 30px;
}
div.bdelete, div.bconfirmed{

div.bdelete,
div.bconfirmed {
width: 5%;
}
div.btos{

div.btos {
width: 20%;
}

div.assignment > div{
color:navy;
div.assignment > div {
color: navy;
background-color: white;
font-size: 20px;
font-weight: lighter;
border: 1px dotted lightgrey;
}

/* peple item card*/
.peopleitem div span.checked {
color:orange;
}
.peopleitem div.card div.front > div[name="title"] {
height: auto;
text-align: center;
background-color: lightgrey;
}
div.front > span[name='icon'] {
width: 100%;
height: 15px;
background-color: dimgrey;
color: white;
}

div.back > span.icon{
width: 100%;
background-color: lightgrey;
color: dimgrey
}


div.front > span.badge, div.back > span.badge {
border-radius: 50%;
display: inline-block;
padding-left: 8px;
padding-right: 8px;
text-align: center;
position:absolute;
right : -5px;
top: -5px;
}

span.badge.blue{
color: #fff;
box-shadow: 1px 1px 10px black;
background-color: black;
}

span.badge.pink{
color: black;
box-shadow: 1px 1px 10px white;
background-color: white;
}


+ 12
- 1
js/bts_timesheet.js Просмотреть файл

@@ -1,5 +1,16 @@
(function ($) {
$(function () {
console.log("in timesheets %o", bts());
class People{
function constructor(selector){
}
}//end of class People
var sample_people{
firstname: "first",
lastname: "last"
}
});
})(jQuery);

+ 1
- 1
js/ts.js Просмотреть файл

@@ -9,6 +9,6 @@ function bts(){

(function ($) {
$(function () {
console.log("%o", bts());
});
})(jQuery);

+ 48
- 3
ts.php Просмотреть файл

@@ -18,6 +18,8 @@ class AcareOffice{
private $nonce; //for ajax verification
private $pages = array('time-sheets', 'user-list');
private $acaresydney_userid = 0;
private $clientgroup="48646f3d-cf5e-4fea-8c8b-5812bd540e1b";
private $xero ;
public function __construct() {
add_action('init', array($this, 'class_loader'));
@@ -25,6 +27,8 @@ class AcareOffice{
add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
add_filter('show_admin_bar', '__return_false');
add_shortcode( 'ts-sync-users', array($this, 'sync_users'));
}
/**
@@ -41,9 +45,8 @@ class AcareOffice{
// Add our namespace and the folder it maps to
$loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
$loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );


$n = new Xero();
$this->xero = new Xero();
}

@@ -88,6 +91,48 @@ class AcareOffice{
wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' ));
}
//sync users to wordpress system
public function sync_users(){
$this->sync_clients();
$this->sync_employees();
}
private function sync_clients(){
$contacts = $this->xero->getClients($this->clientgroup);
foreach ($contacts as $c){
$this->ensure_contact_exists($c);
}
}
private function sync_employees(){
}
private function ensure_contact_exists($contact){
$login = $contact->getContactID();
$xero_contact = $this->xero->getContact($login);
$args = $this->xero_contact_profile($xero_contact);
$user = get_user_by('login', $login);
if ($user === false){
wp_insert_user($args);
}else{//update user
$args['ID'] = $user->ID;
wp_update_user($args);
}
}
private function xero_contact_profile($c){
$args = [
'user_login' => $username = $c->getContactID(),
'user_pass' => md5(uniqid(rand() + time(), true)),
'display_name' =>$c->getName(),
'user_email' => $c->getEmailAddress(),
'first_name' => $c->getFirstName(),
'last_name' => $c->getLastName(),
'nickname' => $c->getName(),
'role' => 'client',
];
return $args;
}
}

new AcareOffice();

Загрузка…
Отмена
Сохранить