Esempio n. 1
0
 private function bitfieldToFlagsMap($bitfield)
 {
     $flags = [];
     foreach ($this->field_names_map as $position => $name) {
         $flags[$name] = \databox_status::bitIsSet($bitfield, $position);
     }
     return $flags;
 }
 public function getRecordFlags(RecordInterface $record)
 {
     $recordStatuses = [];
     /** @var \appbox $appbox */
     $appbox = $this->app['phraseanet.appbox'];
     $databox = $appbox->get_databox($record->getDataboxId());
     $structure = $databox->getStatusStructure()->toArray();
     if (!$this->isGrantedOnCollection($record->getBaseId(), 'chgstatus')) {
         $structure = array_filter($structure, function ($status) {
             return (bool) $status['printable'];
         });
     }
     $bitValue = $record->getStatusBitField();
     foreach ($structure as $status) {
         $on = \databox_status::bitIsSet($bitValue, $status['bit']);
         if (null === ($on ? $status['img_on'] : $status['img_off'])) {
             continue;
         }
         $recordStatuses[] = ['path' => $on ? $status['img_on'] : $status['img_off'], 'labels' => $on ? $status['labels_on_i18n'] : $status['labels_off_i18n']];
     }
     return $recordStatuses;
 }
 /**
  *    Truth table for status rights
  *
  *    +-----------+
  *    | and | xor |
  *    +-----------+
  *    |  0  |  0  | -> BOTH STATES ARE CHECKED
  *    +-----------+
  *    |  1  |  0  | -> UNSET STATE IS CHECKED
  *    +-----------+
  *    |  0  |  1  | -> UNSET STATE IS CHECKED (not possible)
  *    +-----------+
  *    |  1  |  1  | -> SET STATE IS CHECKED
  *    +-----------+
  *
  */
 private function computeAccess($and, $xor, $bit)
 {
     $xorBit = \databox_status::bitIsSet($xor, $bit);
     $andBit = \databox_status::bitIsSet($and, $bit);
     if (!$xorBit && !$andBit) {
         return self::FLAG_ALLOW_BOTH;
     }
     if ($xorBit && $andBit) {
         return self::FLAG_SET_ONLY;
     }
     return self::FLAG_UNSET_ONLY;
 }
Esempio n. 4
0
 /**
  * Retrieve detailed information about one status
  *
  * @param \record_adapter $record
  * @return array
  */
 private function listRecordStatus(\record_adapter $record)
 {
     $ret = [];
     foreach ($record->getStatusStructure() as $bit => $status) {
         $ret[] = ['bit' => $bit, 'state' => \databox_status::bitIsSet($record->getStatusBitField(), $bit)];
     }
     return $ret;
 }