Example #1
0
 public function __invoke(Square $square)
 {
     $view = $this->getView();
     $html = '';
     $html .= '<tr>';
     $html .= sprintf('<td class="priority-col">%s</td>', $square->get('priority'));
     $html .= sprintf('<td><span class="gray">%s</span> %s</td>', $view->option('subject.square.type'), $square->get('name'));
     $html .= sprintf('<td>%s</td>', $view->t($square->getStatus()));
     $html .= sprintf('<td>%s</td>', $view->timeRange($square->need('time_start'), $square->need('time_end'), '%s to %s'));
     $html .= sprintf('<td>%s</td>', $view->prettyTime($square->need('time_block')));
     $html .= sprintf('<td>%s</td>', $view->prettyTime($square->need('time_block_bookable')));
     $html .= sprintf('<td>%s</td>', $view->prettyTime($square->need('time_block_bookable_max')));
     $html .= '<td class="actions-col no-print">' . '<a href="' . $view->url('backend/config/square/edit', ['sid' => $square->need('sid')]) . '" class="unlined gray symbolic symbolic-edit">' . $view->t('Edit') . '</a> &nbsp; ' . '<a href="' . $view->url('backend/config/square/delete', ['sid' => $square->need('sid')]) . '" class="unlined gray symbolic symbolic-cross">' . $view->t('Delete') . '</a></td>';
     $html .= '</tr>';
     return $html;
 }
Example #2
0
 public function __invoke(DateTime $dateTimeStart, DateTime $dateTimeEnd, Square $square)
 {
     $bookableMax = $square->get('time_block_bookable_max');
     if (!$bookableMax || $bookableMax > 86400) {
         return $this->renderDateBlockChoice($dateTimeStart, $dateTimeEnd, $square);
     } else {
         return $this->renderTimeBlockChoice($dateTimeStart, $dateTimeEnd, $square);
     }
 }
Example #3
0
 /**
  * Saves (updates or creates) a square.
  *
  * @param Square $square
  * @throws Exception
  * @return Square
  */
 public function save(Square $square)
 {
     $connection = $this->squareTable->getAdapter()->getDriver()->getConnection();
     if (!$connection->inTransaction()) {
         $connection->beginTransaction();
         $transaction = true;
     } else {
         $transaction = false;
     }
     try {
         if ($square->get('sid')) {
             /* Update existing square */
             /* Determine updated properties */
             $updates = array();
             foreach ($square->need('updatedProperties') as $property) {
                 $updates[$property] = $square->get($property);
             }
             if ($updates) {
                 $this->squareTable->update($updates, array('sid' => $square->get('sid')));
             }
             /* Determine new meta properties */
             foreach ($square->need('insertedMetaProperties') as $metaProperty) {
                 $this->squareMetaTable->insert(array('sid' => $square->get('sid'), 'key' => $metaProperty, 'value' => $square->needMeta($metaProperty), 'locale' => $square->getMetaLocale($metaProperty)));
             }
             /* Determine updated meta properties */
             foreach ($square->need('updatedMetaProperties') as $metaProperty) {
                 $locale = $square->getMetaLocale($metaProperty);
                 $where = array('sid' => $square->get('sid'), 'key' => $metaProperty);
                 if (is_null($locale)) {
                     $where[] = new IsNull('locale');
                 } else {
                     $where['locale'] = $locale;
                 }
                 $this->squareMetaTable->update(array('value' => $square->needMeta($metaProperty)), $where);
             }
             /* Determine removed meta properties */
             foreach ($square->need('removedMetaProperties') as $metaProperty) {
                 $this->squareMetaTable->delete(array('sid' => $square->get('sid'), 'key' => $metaProperty, 'locale' => $square->getMetaLocale($metaProperty)));
             }
             $square->reset();
             $this->getEventManager()->trigger('save.update', $square);
         } else {
             /* Insert square */
             if ($square->getExtra('nsid')) {
                 $sid = $square->getExtra('nsid');
             } else {
                 $sid = null;
             }
             $this->squareTable->insert(array('sid' => $sid, 'name' => $square->need('name'), 'status' => $square->get('status', 'enabled'), 'priority' => $square->need('priority'), 'capacity' => $square->need('capacity'), 'capacity_heterogenic' => $square->need('capacity_heterogenic'), 'time_start' => $square->need('time_start'), 'time_end' => $square->need('time_end'), 'time_block' => $square->need('time_block'), 'time_block_bookable' => $square->need('time_block_bookable'), 'time_block_bookable_max' => $square->need('time_block_bookable_max'), 'range_book' => $square->need('range_book'), 'range_cancel' => $square->need('range_cancel')));
             $sid = $this->squareTable->getLastInsertValue();
             if (!(is_numeric($sid) && $sid > 0)) {
                 throw new RuntimeException('Failed to save square');
             }
             foreach ($square->need('meta') as $key => $value) {
                 $this->squareMetaTable->insert(array('sid' => $sid, 'key' => $key, 'value' => $value));
                 if (!$this->squareMetaTable->getLastInsertValue()) {
                     throw new RuntimeException(sprintf('Failed to save square meta key "%s"', $key));
                 }
             }
             $square->add('sid', $sid);
             $this->getEventManager()->trigger('save.insert', $square);
         }
         if ($transaction) {
             $connection->commit();
         }
         $this->getEventManager()->trigger('save', $square);
         return $square;
     } catch (Exception $e) {
         if ($transaction) {
             $connection->rollback();
         }
         throw $e;
     }
 }