1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

WIP: wrapped entities for easier support

This commit is contained in:
Pavel 2020-07-29 15:06:51 +03:00
parent c2778b4382
commit acdd0d3fb1
5 changed files with 403 additions and 23 deletions

View file

@ -168,7 +168,7 @@ class ConfigProvider
*
* @return array
*/
public static function getSitesList(): array
public static function getSitesList()
{
if (self::isEmptyNotZero(static::$sitesList)) {
static::$sitesList = static::getUnserializedOption(Constants::CRM_SITES_LIST);
@ -182,7 +182,7 @@ class ConfigProvider
*
* @return array
*/
public static function getSitesListCorporate(): array
public static function getSitesListCorporate()
{
if (self::isEmptyNotZero(static::$sitesListCorporate)) {
static::$sitesListCorporate = static::getUnserializedOption(
@ -198,7 +198,7 @@ class ConfigProvider
*
* @return array
*/
public static function getOrderTypes(): array
public static function getOrderTypes()
{
if (self::isEmptyNotZero(static::$orderTypes)) {
static::$orderTypes = static::getUnserializedOption(Constants::CRM_ORDER_TYPES_ARR);
@ -212,7 +212,7 @@ class ConfigProvider
*
* @return array
*/
public static function getDeliveryTypes(): array
public static function getDeliveryTypes()
{
if (self::isEmptyNotZero(static::$deliveryTypes)) {
static::$deliveryTypes = static::getUnserializedOption(Constants::CRM_DELIVERY_TYPES_ARR);
@ -226,7 +226,7 @@ class ConfigProvider
*
* @return array
*/
public static function getPaymentTypes(): array
public static function getPaymentTypes()
{
if (self::isEmptyNotZero(static::$paymentTypes)) {
static::$paymentTypes = static::getUnserializedOption(Constants::CRM_PAYMENT_TYPES);
@ -240,7 +240,7 @@ class ConfigProvider
*
* @return array
*/
public static function getPaymentStatuses(): array
public static function getPaymentStatuses()
{
if (self::isEmptyNotZero(static::$paymentStatuses)) {
static::$paymentStatuses = static::getUnserializedOption(Constants::CRM_PAYMENT_STATUSES);
@ -254,7 +254,7 @@ class ConfigProvider
*
* @return array
*/
public static function getPayment(): array
public static function getPayment()
{
if (self::isEmptyNotZero(static::$payment)) {
static::$payment = static::getUnserializedOption(Constants::CRM_PAYMENT);
@ -268,7 +268,7 @@ class ConfigProvider
*
* @return array
*/
public static function getOrderProps(): array
public static function getOrderProps()
{
if (self::isEmptyNotZero(static::$orderProps)) {
static::$orderProps = static::getUnserializedOption(Constants::CRM_ORDER_PROPS);
@ -282,7 +282,7 @@ class ConfigProvider
*
* @return array
*/
public static function getLegalDetails(): array
public static function getLegalDetails()
{
if (self::isEmptyNotZero(static::$legalDetails)) {
static::$legalDetails = static::getUnserializedOption(Constants::CRM_LEGAL_DETAILS);
@ -296,7 +296,7 @@ class ConfigProvider
*
* @return array
*/
public static function getContragentTypes(): array
public static function getContragentTypes()
{
if (self::isEmptyNotZero(static::$contragentTypes)) {
static::$contragentTypes = static::getUnserializedOption(Constants::CRM_CONTRAGENT_TYPE);
@ -310,7 +310,7 @@ class ConfigProvider
*
* @return array
*/
public static function getCustomFields(): array
public static function getCustomFields()
{
if (self::isEmptyNotZero(static::$customFields)) {
static::$customFields = static::getUnserializedOption(Constants::CRM_CUSTOM_FIELDS);
@ -324,7 +324,7 @@ class ConfigProvider
*
* @return array
*/
public static function getCancellableOrderPaymentStatuses(): array
public static function getCancellableOrderPaymentStatuses()
{
if (self::isEmptyNotZero(static::$cancellableOrderPaymentStatuses)) {
static::$cancellableOrderPaymentStatuses = static::getUnserializedOption(
@ -360,7 +360,7 @@ class ConfigProvider
*
* @return array
*/
public static function getFailedOrdersIds(): array
public static function getFailedOrdersIds()
{
return static::getUnserializedOption(Constants::CRM_ORDER_FAILED_IDS);
}
@ -476,7 +476,7 @@ class ConfigProvider
*
* @return array
*/
public static function getInfoblocksInventories(): array
public static function getInfoblocksInventories()
{
if (self::isEmptyNotZero(static::$infoblocksInventories)) {
static::$infoblocksInventories = static::getUnserializedOption(
@ -492,7 +492,7 @@ class ConfigProvider
*
* @return array
*/
public static function getStores(): array
public static function getStores()
{
if (self::isEmptyNotZero(static::$stores)) {
static::$stores = static::getUnserializedOption(Constants::CRM_STORES);
@ -506,7 +506,7 @@ class ConfigProvider
*
* @return array
*/
public static function getShops(): array
public static function getShops()
{
if (self::isEmptyNotZero(static::$shops)) {
static::$shops = static::getUnserializedOption(Constants::CRM_SHOPS);

View file

@ -0,0 +1,222 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Bitrix
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Bitrix;
use Bitrix\Main\Authentication\Context;
use Bitrix\Main\ORM\Entity;
use Bitrix\Main\ORM\Fields\FieldTypeMask;
use Bitrix\Main\ORM\Objectify\Collection;
use Bitrix\Main\ORM\Objectify\EntityObject;
use Bitrix\Main\ORM\Objectify\Values;
use Bitrix\Main\ORM\Data\Result;
/**
* Class AbstractModelFacade. Wraps Bitrix objects in order to create phpdoc with necessary annotations.
*
* @package Intaro\RetailCrm\Model\Bitrix
*
* @method array collectValues($valuesType = Values::ALL, $fieldsMask = FieldTypeMask::ALL)
* @method Result save()
* @method Result delete()
* @method mixed fill($fields = FieldTypeMask::ALL)
* @method Collection|EntityObject|mixed getId()
* @method mixed get($fieldName)
* @method mixed remindActual($fieldName)
* @method mixed require ($fieldName)
* @method mixed set($fieldName, $value)
* @method mixed reset($fieldName)
* @method mixed unset($fieldName)
* @method mixed has($fieldName)
* @method mixed isFilled($fieldName)
* @method mixed isChanged($fieldName)
* @method mixed addTo($fieldName, $value)
* @method mixed removeFrom($fieldName, $value)
* @method mixed removeAll($fieldName)
* @method void defineAuthContext(Context $authContext)
* @method Entity sysGetEntity()
* @method array sysGetPrimary()
* @method mixed sysGetRuntime($name)
* @method EntityObject sysSetRuntime($name, $value)
* @method void sysSetActual($fieldName, $value)
* @method void sysChangeState($state)
* @method int sysGetState()
* @method mixed sysGetValue($fieldName, $require = false)
* @method EntityObject sysSetValue($fieldName, $value)
* @method bool sysHasValue($fieldName)
* @method bool sysIsFilled($fieldName)
* @method bool sysIsChanged($fieldName)
* @method bool sysHasPrimary()
* @method void sysOnPrimarySet()
* @method void sysAddOnPrimarySetListener($callback)
* @method EntityObject sysUnset($fieldName)
* @method EntityObject sysReset($fieldName)
* @method EntityObject sysResetRelation($fieldName)
* @method array sysRequirePrimary()
* @method array sysGetIdleFields($fields = [])
* @method array sysGetIdleFieldsByMask($mask = FieldTypeMask::ALL)
* @method Result sysSaveRelations(Result $result)
* @method void sysPostSave()
* @method void sysAddToCollection($fieldName, $remoteObject)
* @method void sysRemoveFromCollection($fieldName, $remoteObject)
* @method void sysRemoveAllFromCollection($fieldName)
* @method Collection sysFillRelationCollection($field)
* @method string sysMethodToFieldCase($methodName)
* @method string sysFieldToMethodCase($fieldName)
*/
class AbstractModelFacade implements \ArrayAccess
{
/** @var \Bitrix\Main\ORM\Objectify\EntityObject */
protected $entity;
/**
* AbstractModelFacade constructor.
*
* @param \Bitrix\Main\ORM\Objectify\EntityObject $entity
*/
public function __construct(EntityObject $entity)
{
$this->entity = $entity;
}
/**
* @param string $name
*
* @return bool
*/
public function __isset($name)
{
return property_exists(get_class($this->entity), $name);
}
/**
* Pass value to entity
*
* @param string $name
* @param mixed $value
*
* @throws \Bitrix\Main\SystemException
*/
public function __set($name, $value)
{
if (property_exists(get_class($this->entity), $name)) {
$this->entity->$name = $value;
}
return $this->entity->__set($name, $value);
}
/**
* Extract value from entity
*
* @param string $name
*
* @return array|\Bitrix\Main\Authentication\Context|\Bitrix\Main\ORM\Entity|int|mixed
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\SystemException
*/
public function __get($name)
{
if (property_exists(get_class($this->entity), $name)) {
return $this->entity->$name;
}
return $this->entity->__get($name);
}
/**
* Call method from entity
*
* @param string $name
* @param array $arguments
*
* @return \Bitrix\Main\ORM\Objectify\Collection|bool|mixed|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\SystemException
*/
public function __call($name, $arguments)
{
if (method_exists($this->entity, $name)) {
return \call_user_func_array([$this->entity, $name], $arguments);
}
return $this->entity->__call($name, $arguments);
}
/**
* @param mixed $offset
*
* @return bool
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\SystemException
*/
public function offsetExists($offset)
{
return $this->entity->offsetExists($offset);
}
/**
* @param mixed $offset
*
* @return \Bitrix\Main\ORM\Objectify\Collection|bool|mixed|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\SystemException
*/
public function offsetGet($offset)
{
return $this->entity->offsetGet($offset);
}
/**
* @param mixed $offset
* @param mixed $value
*
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\SystemException
*/
public function offsetSet($offset, $value)
{
$this->entity->offsetSet($offset, $value);
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
$this->entity->offsetUnset($offset);
}
/**
* @return \Bitrix\Main\ORM\Objectify\EntityObject
*/
public function getEntity(): EntityObject
{
return $this->entity;
}
/**
* Call static method from entity
*
* @param $name
* @param $arguments
*
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
if (method_exists(EntityObject::class, $name)) {
return \call_user_func_array([EntityObject::class, $name], $arguments);
}
throw new \RuntimeException('Cannot find method "' . $name . '"');
}
}

View file

@ -0,0 +1,146 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Bitrix
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Bitrix;
use Bitrix\Main\Type\DateTime;
/**
* Class User
*
* @package Intaro\RetailCrm\Model\Bitrix
*
* @method int getId()
* @method void setId()
* @method string getLogin()
* @method void setLogin()
* @method string getPassword()
* @method void setPassword()
* @method string getEmail()
* @method void setEmail()
* @method bool getActive()
* @method void setActive()
* @method DateTime getDateRegister()
* @method void setDateRegister()
* @method DateTime getDateRegShort()
* @method void setDateRegShort()
* @method DateTime getLastLogin()
* @method void setLastLogin()
* @method DateTime getLastLoginShort()
* @method void setLastLoginShort()
* @method DateTime getLastActivityDate()
* @method void setLastActivityDate()
* @method DateTime getTimestampX()
* @method void setTimestampX()
* @method string getName()
* @method void setName()
* @method string getSecondName()
* @method void setSecondName()
* @method string getLastName()
* @method void setLastName()
* @method string getTitle()
* @method void setTitle()
* @method string getExternalAuthId()
* @method void setExternalAuthId()
* @method string getXmlId()
* @method void setXmlId()
* @method string getBxUserId()
* @method void setBxUserId()
* @method string getConfirmCode()
* @method void setConfirmCode()
* @method string getLid()
* @method void setLid()
* @method string getLanguageId()
* @method void setLanguageId()
* @method int getTimeZoneOffset()
* @method void setTimeZoneOffset()
* @method string getPersonalProfession()
* @method void setPersonalProfession()
* @method string getPersonalPhone()
* @method void setPersonalPhone()
* @method string getPersonalMobile()
* @method void setPersonalMobile()
* @method string getPersonalWww()
* @method void setPersonalWww()
* @method string getPersonalIcq()
* @method void setPersonalIcq()
* @method string getPersonalFax()
* @method void setPersonalFax()
* @method string getPersonalPager()
* @method void setPersonalPager()
* @method mixed getPersonalStreet()
* @method void setPersonalStreet()
* @method string getPersonalMailbox()
* @method void setPersonalMailbox()
* @method string getPersonalCity()
* @method void setPersonalCity()
* @method string getPersonalState()
* @method void setPersonalState()
* @method string getPersonalZip()
* @method void setPersonalZip()
* @method string getPersonalCountry()
* @method void setPersonalCountry()
* @method DateTime getPersonalBirthday()
* @method void setPersonalBirthday()
* @method string getPersonalGender()
* @method void setPersonalGender()
* @method int getPersonalPhoto()
* @method void setPersonalPhoto()
* @method mixed getPersonalNotes()
* @method void setPersonalNotes()
* @method string getWorkCompany()
* @method void setWorkCompany()
* @method string getWorkDepartment()
* @method void setWorkDepartment()
* @method string getWorkPhone()
* @method void setWorkPhone()
* @method string getWorkPosition()
* @method void setWorkPosition()
* @method string getWorkWww()
* @method void setWorkWww()
* @method string getWorkFax()
* @method void setWorkFax()
* @method string getWorkPager()
* @method void setWorkPager()
* @method mixed getWorkStreet()
* @method void setWorkStreet()
* @method string getWorkMailbox()
* @method void setWorkMailbox()
* @method string getWorkCity()
* @method void setWorkCity()
* @method string getWorkState()
* @method void setWorkState()
* @method string getWorkZip()
* @method void setWorkZip()
* @method string getWorkCountry()
* @method void setWorkCountry()
* @method mixed getWorkProfile()
* @method void setWorkProfile()
* @method int getWorkLogo()
* @method void setWorkLogo()
* @method mixed getWorkNotes()
* @method void setWorkNotes()
* @method mixed getAdminNotes()
* @method void setAdminNotes()
* @method string getShortName()
* @method void setShortName()
* @method bool getIsOnline()
* @method void setIsOnline()
* @method bool getIsRealUser()
* @method void setIsRealUser()
* @method mixed getIndex()
* @method void setIndex()
* @method mixed getIndexSelector()
* @method void setIndexSelector()
*/
class User extends AbstractModelFacade
{
}

View file

@ -27,7 +27,7 @@ class AbstractRepository
*
* @return array
*/
protected function getEntityFields(Entity $entity): array
protected static function getEntityFields(Entity $entity): array
{
return array_keys($entity->getFields());
}

View file

@ -13,6 +13,7 @@ namespace Intaro\RetailCrm\Repository;
use Bitrix\Main\ORM\Objectify\EntityObject;
use Bitrix\Main\UserTable;
use Intaro\RetailCrm\Model\Bitrix\User;
/**
* Class UserRepository
@ -24,16 +25,27 @@ class UserRepository extends AbstractRepository
/**
* @param int $id
*
* @return \Bitrix\Main\ORM\Objectify\EntityObject|null
* @return User|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
public function getById(int $id): ?EntityObject
public static function getById(int $id): ?User
{
$result = (UserTable::query())
->setSelect($this->getEntityFields(UserTable::getEntity()))
->addFilter('=ID', $id)->exec();
return $result->fetchObject();
return static::getWrapped(UserTable::getByPrimary($id)->fetchObject());
}
/**
* @param \Bitrix\Main\ORM\Objectify\EntityObject|null $entityObject
*
* @return \Intaro\RetailCrm\Model\Bitrix\User|null
*/
private static function getWrapped(?EntityObject $entityObject): ?User
{
if (null === $entityObject) {
return null;
}
return new User($entityObject);
}
}