gy-doc-code
[ class tree: gy-doc-code ] [ index: gy-doc-code ] [ all elements ]

Source for file GeneralUsersPropertys.php

Documentation is available at GeneralUsersPropertys.php

  1. <?php
  2.  
  3. namespace Gy\Core\User;
  4.  
  5. if (!defined("GY_CORE") && (GY_CORE !== true)) die( "gy: err include core" );
  6.  
  7. /**
  8.  * GeneralUsersPropertys - класс для работы с общими свойствами пользователей
  9.  */
  10. {
  11.  
  12.     private static $tableNameCreatePropertys = 'create_all_users_property';
  13.     private static $tableNameTypePropertys = 'type_all_user_propertys';
  14.  
  15.     private static $tableNameTypePropertysForCodeTypeProperty = array(
  16.         'text' => 'value_all_user_propertys_text'
  17.     );
  18.  
  19.     /**
  20.      * getAllGeneralUsersPropertys
  21.      *  - получить все созданные пользовательские свойства
  22.      * 
  23.      * @global type $DB 
  24.      * @return array 
  25.      */
  26.     public static function getAllGeneralUsersPropertys()
  27.     { 
  28.         global $DB;
  29.         $res = $DB->selectDb(
  30.             self::$tableNameCreatePropertys,
  31.             array('*'),
  32.             array()
  33.         );
  34.         $result = $DB->fetchAll($res, 'id');
  35.         return $result;
  36.     }
  37.  
  38.     /**
  39.      * getAllTypeAllUsersPropertys
  40.      *  - получить все возможные типы пользовательских свойств
  41.      * 
  42.      * @global type $DB 
  43.      * @return array 
  44.      */
  45.     public static function getAllTypeAllUsersPropertys()
  46.     {
  47.         global $DB;
  48.         $res = $DB->selectDb(
  49.             self::$tableNameTypePropertys,
  50.             array('*'),
  51.             array(
  52.             )
  53.         );
  54.         $result = $DB->fetchAll($res, 'id');
  55.         return $result;
  56.     }
  57.  
  58.     /**
  59.      * addUsersPropertys
  60.      *  - создать пользовательское свойство
  61.      * 
  62.      * @global type $DB 
  63.      * @param string $name - имя
  64.      * @param int $idType - тип
  65.      * @param string $code - код
  66.      * @return boolean 
  67.      */
  68.     public static function addUsersPropertys($name, $idType, $code)
  69.     {
  70.         $result = false;
  71.  
  72.         global $DB;
  73.         $res = $DB->insertDb(
  74.             self::$tableNameCreatePropertys,
  75.             array(
  76.                 'name_property' => $name,
  77.                 'type_property' => $idType,
  78.                 'code' => $code
  79.             )
  80.         );
  81.  
  82.         if ($res){
  83.             $result = true;
  84.         }
  85.         return $result;
  86.     }
  87.  
  88.     /**
  89.      * deleteUserProperty
  90.      *  - удалить общее пользовательское свойство
  91.      * 
  92.      * @global type $DB 
  93.      * @param int $id - id общего пользовательского свойства
  94.      * @return boolean 
  95.      */
  96.     public static function deleteUserProperty($id)
  97.     {
  98.         $result = false;
  99.         global $DB;
  100.  
  101.         $res = $DB->deleteDb(
  102.             self::$tableNameCreatePropertys,
  103.             array('='=>array('id', $id))
  104.         );
  105.  
  106.         if ($res) {
  107.             $result = true;
  108.         }
  109.  
  110.         //удалить значения
  111.         self::deleteAllValuesAllUserBypropertyId($id, 'text'); // text - т.к. пока других нет
  112.  
  113.         return $result;
  114.     }
  115.  
  116.     /**
  117.      * deleteAllValuesAllUserBypropertyId
  118.      *  - удалить все значения определённого свойства у всех пользователей
  119.      * 
  120.      * @global type $DB 
  121.      * @param int $idProperty - id свойства (общее свойство)
  122.      * @param string $typePropertyCode - пока у всех значение text
  123.      * @return boolean 
  124.      */
  125.     public static function deleteAllValuesAllUserBypropertyId($idProperty, $typePropertyCode)
  126.     {
  127.         $result = false;
  128.  
  129.         if (!empty(self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode])) {
  130.             global $DB;
  131.  
  132.             $res = $DB->deleteDb(
  133.                 self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode],
  134.                 array( '=' => array('id_property', $idProperty) )
  135.             );
  136.  
  137.             if ($res) {
  138.                 $result = true;
  139.             }
  140.         }
  141.         return $result;
  142.  
  143.     }
  144.  
  145.     /**
  146.      * getAllValueUserProperty
  147.      *  - взять все значения определённого типа свойства пользователя
  148.      * 
  149.      * @global type $DB 
  150.      * @param int $idUser - id пользователя
  151.      * @param string $typePropertyCode - пока у всех значение text
  152.      * @return boolean/array 
  153.      */
  154.     public static function getAllValueUserProperty($idUser, $typePropertyCode)
  155.     {
  156.         $result = false;
  157.  
  158.         if (!empty(self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode])) {
  159.             global $DB;
  160.             $res = $DB->selectDb(
  161.                 self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode],
  162.                 array('*'),
  163.                 array( '=' => array('id_users', $idUser) )
  164.             );
  165.             $result = $DB->fetchAll($res, 'id_property');
  166.         }
  167.         return $result;
  168.     }
  169.  
  170.     /**
  171.      * addValueProperty
  172.      *  - добавить значение свойства
  173.      * 
  174.      * @global type $DB 
  175.      * @param int $idUser - id пользователя
  176.      * @param string $typePropertyCode - пока у всех значение text
  177.      * @param int $idProperty - id пользовательского свойства
  178.      * @param string $value - пока тип text, тут только строка
  179.      * @return boolean 
  180.      */
  181.     public static function addValueProperty($idUser, $typePropertyCode, $idProperty, $value)
  182.     {
  183.         $result = false;
  184.  
  185.         if (!empty(self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode])) {
  186.             global $DB;
  187.             $res = $DB->insertDb(
  188.                 self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode],
  189.                 array(
  190.                     'value' => $value,
  191.                     'id_users' => $idUser,
  192.                     'id_property' => $idProperty
  193.                 )
  194.             );
  195.  
  196.             if ($res) {
  197.                 $result = true;
  198.             }
  199.         }
  200.         return $result;
  201.     }
  202.  
  203.     /**
  204.      * deleteValueProperty
  205.      *  - удалить значения конкретного свойства конкретного пользователя
  206.      * 
  207.      * @global type $DB 
  208.      * @param int $idUser - id пользователя
  209.      * @param string $typePropertyCode - пока у всех значение text
  210.      * @param int $idProperty - id пользовательского свойства
  211.      * @return boolean 
  212.      */
  213.     public static function deleteValueProperty($idUser, $typePropertyCode, $idProperty)
  214.     {
  215.         $result = false;
  216.  
  217.         if (!empty(self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode])) {
  218.             global $DB;
  219.  
  220.             $res = $DB->deleteDb(
  221.                 self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode],
  222.                 array( 
  223.                     'AND' => array(
  224.                         array('=' => array('id_users', $idUser) ),
  225.                         array('=' => array('id_property', $idProperty) )
  226.                     ),
  227.                 )
  228.             );
  229.  
  230.             if ($res) {
  231.                 $result = true;
  232.             }
  233.         }
  234.  
  235.         return $result;
  236.     }
  237.  
  238.     /**
  239.      * updateValueProperty
  240.      *  - изменить значение конкретного свойства конкретного пользователя
  241.      * 
  242.      * @global type $DB 
  243.      * @param int $idUser - id пользователя
  244.      * @param string $typePropertyCode - пока у всех значение text
  245.      * @param int $idProperty - id пользовательского свойства
  246.      * @param string $value - пока тип text, тут только строка
  247.      * @return boolean 
  248.      */
  249.     public static function updateValueProperty($idUser, $typePropertyCode, $idProperty, $value)
  250.     {
  251.         $result = false;
  252.  
  253.         if (!empty(self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode])) {
  254.             global $DB;
  255.             $res = $DB->updateDb(
  256.                 self::$tableNameTypePropertysForCodeTypeProperty[$typePropertyCode],
  257.                 array(
  258.                     'id_users' => $idUser,
  259.                     'id_property' => $idProperty,
  260.                     'value' => $value
  261.                 ),
  262.                 array(
  263.                     'AND' => array(
  264.                         array('=' => array('id_users', $idUser) ),
  265.                         array('=' => array('id_property', $idProperty) )
  266.                     ),
  267.                 )
  268.             );
  269.  
  270.             if ($res) {
  271.                 $result = true;
  272.             }
  273.         }
  274.         return $result;
  275.     }
  276.  
  277. }

Documentation generated on Sat, 27 Apr 2024 11:17:29 +0300 by phpDocumentor 1.4.3