vendor\project-biz\database-bundle\src\Entity\ColumnDefinition.php line 15

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\DatabaseBundle\Entity;
  3. use ProjectBiz\DatabaseBundle\Database\GenericRepositoryFactory;
  4. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaComposite;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaBuilder;
  7. /**
  8.  * @ORM\Entity
  9.  * @ORM\Table(name="ColumnDefinition")
  10.  */
  11. class ColumnDefinition
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\Column(type="integer", name="ColDefinition_ID")
  16.      * @ORM\GeneratedValue(strategy="AUTO")
  17.      */
  18.     protected $id;
  19.     /**
  20.      * @ORM\Column(name="ColDefinition_InternalTablename", type="string", length=50)
  21.      */
  22.     private $table;
  23.     /**
  24.      * @ORM\Column(name="ColDefinition_InternalColumnname", type="string", length=50)
  25.      */
  26.     private $column;
  27.     /**
  28.      * @ORM\Column(name="ColDefinition_ColumnCaption", type="string", length=50)
  29.      */
  30.     private $caption;
  31.     /**
  32.      * @ORM\Column(name="ColDefinition_StandardValue", type="string", length=50)
  33.      */
  34.     private $defaultValue;
  35.     /**
  36.      * @ORM\Column(name="ColDefinition_ColumnType", type="string", length=50)
  37.      */
  38.     private $type;
  39.     /**
  40.      * @ORM\Column(name="ColDefinition_Tooltip", type="string", length=500)
  41.      */
  42.     private $tooltip;
  43.     /**
  44.      * @ORM\Column(name="ColDefinition_Responsible_Name",type="string", length=500)
  45.      */
  46.     private $responsible;
  47.     /**
  48.      * @ORM\Column(name="ColDefinition_WidthPx", type="integer")
  49.      */
  50.     private $width;
  51.     /**
  52.      * @ORM\Column(name="ColDefinition_PermissionRead", type="bigint")
  53.      */
  54.     private $read_rights;
  55.     /**
  56.      * Invalidates $read_rights to ensure some columns are unvisible
  57.      * if $read_rights are set by mistake
  58.      *
  59.      * @ORM\Column(name="ColDefinition_PermissionReadOverwrite", type="bigint")
  60.      */
  61.     private $read_rights_overwrite;
  62.     /**
  63.      * @ORM\Column(name="ColDefinition_PermissionWrite", type="bigint")
  64.      */
  65.     private $write_rights;
  66.     /**
  67.      * Invalidates $write_rights to ensure some columns are unwritable
  68.      * if $write_rights are set by mistake
  69.      *
  70.      * @ORM\Column(name="ColDefinition_PermissionWriteOverwrite", type="bigint")
  71.      */
  72.     private $write_rights_overwrite;
  73.     /**
  74.      * @ORM\Column(name="ColDefinition_BackColour", type="string", length=50)
  75.      */
  76.     private $background_color;
  77.     /**
  78.      * @ORM\Column(name="ColDefinition_ColorCondition", type="string", length=20)
  79.      */
  80.     private $color_condition;
  81.     /**
  82.      * @ORM\Column(name="ColDefinition_Active", type="boolean")
  83.      */
  84.     private $active;
  85.     /**
  86.      * @ORM\Column(name="ColDefinition_SourceTable", type="string", length=50)
  87.      */
  88.     private $source_table;
  89.     /**
  90.      * @ORM\Column(name="ColDefinition_SourceFK", type="string", length=50)
  91.      */
  92.     private $source_foreign_key;
  93.     /**
  94.      * SourceCriterias for querying data from DB.
  95.      *
  96.      * An example is:
  97.      * {"type":"comparison","operator":"=",
  98.      *  "left":{"type":"unmapped_column","column_name":"Price01_LINK_PriceListOverview_ID"},
  99.      *  "right":{"type":"constant","value":"null"}
  100.      * }
  101.      *
  102.      * @ORM\Column(name="ColDefinition_SourceCriteria", type="string")
  103.      */
  104.     private $source_criteria;
  105.     /**
  106.      * Inject varibales into source_criteria.
  107.      *
  108.      * An example is {"[request][price_list_id]":"[right][value]"}
  109.      *
  110.      * @ORM\Column(name="ColDefinition_SourceCriteriaInjection", type="string")
  111.      */
  112.     private $source_criteria_injection;
  113.     /**
  114.      * @ORM\Column(name="ColDefinition_SecHeaderType", type="string", length=50)
  115.      */
  116.     private $secondary_header;
  117.     /**
  118.      * @ORM\Column(name="ColDefinition_SourceColumn", type="string", length=50)
  119.      */
  120.     private $source_column;
  121.     /**
  122.      * @ORM\Column(name="ColDefinition_SourceView", type="string", length=255)
  123.      */
  124.     private $source_view;
  125.     /**
  126.      * @ORM\Column(name="ColDefinition_ControllingClass", type="string", length=255)
  127.      */
  128.     private $controlling_class;
  129.     /**
  130.      * @ORM\Column(name="ColDefinition_AutoIncrementID", type="bigint")
  131.      */
  132.     private $auto_increment_id;
  133.     /**
  134.      * @ORM\Column(name="ColDefinition_NotNull", type="boolean")
  135.      */
  136.     private $not_null;
  137.     /**
  138.      * @ORM\Column(name="ColDefinition_ExcludeFromCloning", type="boolean")
  139.      */
  140.     private $exclude_from_cloning;
  141.     /**
  142.      * @ORM\Column(name="ColDefinition_Encrypt", type="boolean")
  143.      */
  144.     private $encrypt;
  145.     /**
  146.      * Permissions as bitsum for direct cell editing.
  147.      *
  148.      * @ORM\Column(name="ColDefinition_DirectEditPermissions", type="bigint")
  149.      */
  150.     private $direct_edit_permissions;
  151.     /**
  152.      * @ORM\Column(name="ColDefinition_InputConstraint", type="string", length=255)
  153.      */
  154.     private $input_constraint;
  155.     /**
  156.      * @ORM\Column(name="ColDefinition_MaximumLength", type="bigint")
  157.      */
  158.     private $maximum_length;
  159.     private $typeCache null;
  160.     private $reverseCache null;
  161.     private $typeInitialized false;
  162.     public function getId()
  163.     {
  164.         return $this->id;
  165.     }
  166.     public function getTable()
  167.     {
  168.         return $this->table;
  169.     }
  170.     public function getColumn()
  171.     {
  172.         return $this->column;
  173.     }
  174.     public function getCaption()
  175.     {
  176.         return $this->caption;
  177.     }
  178.     public function isActive()
  179.     {
  180.         return $this->active;
  181.     }
  182.     public function getDefault()
  183.     {
  184.         return $this->defaultValue;
  185.     }
  186.     public function getReverseProperty()
  187.     {
  188.         if (!$this->typeInitialized) {
  189.             $this->buildType();
  190.         }
  191.         return $this->reverseCache;
  192.     }
  193.     private function buildType()
  194.     {
  195.         $this->typeCache null;
  196.         if (isset($this->type) && !empty($this->type)) {
  197.             if (strpos($this->type'fer:') === 0) {
  198.                 $parts              explode(':'$this->type);
  199.                 $this->typeCache    'fer';
  200.                 $this->reverseCache $parts[1];
  201.             } else {
  202.                 $this->typeCache $this->type;
  203.             }
  204.         }
  205.         $this->typeInitialized true;
  206.     }
  207.     public function getTooltip()
  208.     {
  209.         $lasttooltip =  $this->tooltip;
  210.         $lastresponsible =  $this->responsible;
  211.         $lasttooltip =str_replace("<p>",""str_replace("</p>","",$lasttooltip));
  212.         if (null !== $lastresponsible) {
  213.             $lasttooltip=$lasttooltip." --Verantwortlicher:".$lastresponsible." --";
  214.         }
  215.         return $lasttooltip;
  216.     }
  217.     public function getWidth()
  218.     {
  219.         return isset($this->width)?$this->width:0;
  220.     }
  221.     public function getBackgroundColor()
  222.     {
  223.         return $this->background_color;
  224.     }
  225.     public function getColorCondition()
  226.     {
  227.         return $this->color_condition;
  228.     }
  229.     public function getSource()
  230.     {
  231.         if ((!empty($this->source_table) && !empty($this->source_foreign_key) && !empty($this->source_column))) {
  232.             return [
  233.                 'table'          => $this->source_table,
  234.                 'foreign_key'    => $this->source_foreign_key,
  235.                 'display_column' => $this->source_column,
  236.                 'view'           => array_unique(
  237.                     array_merge(
  238.                         [$this->source_column$this->source_foreign_key],
  239.                         !empty($this->source_view)?explode(','$this->source_view):[]
  240.                     )
  241.                 ),
  242.             ];
  243.         } else {
  244.             return null;
  245.         }
  246.     }
  247.     /**
  248.      * @param bool $asArray
  249.      * @return mixed
  250.      */
  251.     public function getSourceCriteria($asArray false)
  252.     {
  253.         if ($asArray) {
  254.             return json_decode($this->source_criteriatrue);
  255.         }
  256.         $result null;
  257.         if (null !== $this->source_criteria) {
  258.             $result = (new CriteriaBuilder())->buildFromJson($this->source_criteria);
  259.         }
  260.         return $result;
  261.     }
  262.     public function getSourceCriteriaInjection()
  263.     {
  264.         return json_decode($this->source_criteria_injectiontrue);
  265.     }
  266.     public function getControllingClass()
  267.     {
  268.         return isset($this->controlling_class)?explode(','$this->controlling_class):[];
  269.     }
  270.     public function getSecondaryHeader()
  271.     {
  272.         return $this->secondary_header;
  273.     }
  274.     public function isVirtual()
  275.     {
  276.         return ($this->getType() === 'ref') || ($this->getType() === 'fer');
  277.     }
  278.     public function getType()
  279.     {
  280.         if (!$this->typeInitialized) {
  281.             $this->buildType();
  282.         }
  283.         return $this->typeCache;
  284.     }
  285.     public function checkReadRights($value)
  286.     {
  287.         try {
  288.             /*
  289.              * read_rights_overwrite are set by superadmin only and have a higher priority
  290.              */
  291.             if ($this->read_rights_overwrite) {
  292.                 return (gmp_cmp(gmp_and(gmp_init($this->read_rights_overwrite), gmp_init($value)), 0) > 0);
  293.             }
  294.             return (gmp_cmp(gmp_and(gmp_init($this->read_rights), gmp_init($value)), 0) > 0);
  295.         } catch (\Exception $e) {
  296.             throw new \Exception('Error while checking read permissions for column: ' $this->column0$e);
  297.         }
  298.     }
  299.     public function getReadRights()
  300.     {
  301.         return $this->read_rights;
  302.     }
  303.     public function getReadRightsOverwrite()
  304.     {
  305.         return $this->read_rights_overwrite;
  306.     }
  307.     public function checkWriteRights($value)
  308.     {
  309.         try {
  310.             /*
  311.              * write_rights_overwrite are set by superadmin only and have a higher priority
  312.              */
  313.             if ($this->write_rights_overwrite) {
  314.                 return (gmp_cmp(gmp_and(gmp_init($this->write_rights_overwrite), gmp_init($value)), 0) > 0);
  315.             }
  316.             return (gmp_cmp(gmp_and(gmp_init($this->write_rights), gmp_init($value)), 0) > 0);
  317.         } catch (\Exception $e) {
  318.             throw new \Exception('Error while checking write permissions for column: ' $this->column0$e);
  319.         }
  320.     }
  321.     public function getWriteRights()
  322.     {
  323.         return $this->write_rights;
  324.     }
  325.     public function getWriteRightsOverwrite()
  326.     {
  327.         return $this->write_rights_overwrite;
  328.     }
  329.     public function getAutoIncrementID()
  330.     {
  331.         return $this->auto_increment_id;
  332.     }
  333.     public function getNotNull()
  334.     {
  335.         return $this->not_null;
  336.     }
  337.     public function getEncrypt()
  338.     {
  339.         return $this->encrypt;
  340.     }
  341.     public function getExcludeFromCloning()
  342.     {
  343.         return $this->exclude_from_cloning;
  344.     }
  345.     public function getDirectEditPermissions()
  346.     {
  347.         return $this->direct_edit_permissions;
  348.     }
  349.     public function getInputConstraint()
  350.     {
  351.         return $this->input_constraint;
  352.     }
  353.     public function getMaximumLength()
  354.     {
  355.         return $this->maximum_length;
  356.     }
  357. }