Exemple #1
0
 /**
  * Create an action button
  * @param string $actionName The Action index name update|create|delete|ddelete|restore
  * @param \Zbase\Interfaces\EntityInterface $row
  * @param array $actionConfig Action config
  * @param boolean $template If we will have to generate a template
  * @return \Zbase\Ui\UiInterface
  */
 public function createActionBtn($actionName, $row, $actionConfig, $template = false)
 {
     if (!$row instanceof \Zbase\Interfaces\EntityInterface && !$template) {
         return null;
     }
     if (empty($actionConfig)) {
         return null;
     }
     $rowTrashed = false;
     if ($this->_entity->hasSoftDelete() && !empty($row)) {
         $rowTrashed = $row->trashed();
     }
     if ($actionName == 'delete' || $actionName == 'update') {
         if ($rowTrashed) {
             return null;
         }
     }
     if ($actionName == 'restore' || $actionName == 'ddelete') {
         if (empty($rowTrashed)) {
             return null;
         }
     }
     $label = !empty($actionConfig['label']) ? $actionConfig['label'] : ucfirst($actionName);
     if (strtolower($label) == 'ddelete') {
         $label = _zt('Forever Delete');
     }
     $actionConfig['type'] = 'component.button';
     $actionConfig['size'] = 'extrasmall';
     $actionConfig['label'] = _zt($label);
     $actionConfig['tag'] = 'a';
     if (!empty($actionConfig['route']['name'])) {
         if (!empty($actionConfig['route']['params'])) {
             foreach ($actionConfig['route']['params'] as $paramName => $paramValue) {
                 if (preg_match('/row::/', $paramValue)) {
                     $rowIndex = str_replace('row::', '', $paramValue);
                     if (!empty($row)) {
                         $id = $actionConfig['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                     } else {
                         if (!empty($template)) {
                             $id = $actionConfig['route']['params'][$paramName] = '__' . $rowIndex . '__';
                         }
                     }
                 }
             }
         }
         $actionConfig['routeParams'] = $actionConfig['route']['params'];
         $actionConfig['route'] = $actionConfig['route']['name'];
     }
     $actionConfig['id'] = $this->getWidgetPrefix() . 'Action' . $actionName . (!empty($id) ? $id : null);
     if ($actionName == 'create') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'update') {
         $actionConfig['color'] = 'green';
     }
     if ($actionName == 'view') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'delete') {
         $actionConfig['color'] = 'red';
     }
     if ($actionName == 'restore') {
         $actionConfig['color'] = 'warning';
     }
     if ($actionName == 'ddelete') {
         $actionConfig['color'] = 'red';
     }
     $btn = \Zbase\Ui\Ui::factory($actionConfig);
     if ($actionName == 'create') {
         if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
             $this->_actionCreateButton = $btn;
         }
     }
     return $btn;
 }
Exemple #2
0
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  */
 public function widgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     if (preg_match('/-update/', $action)) {
         $action = 'update';
     }
     if (preg_match('/-create/', $action)) {
         $action = 'create';
     }
     if (preg_match('/-delete/', $action)) {
         $action = 'delete';
     }
     if ($action == 'update' && strtolower($method) == 'post' || $action == 'create' && strtolower($method) == 'post') {
         $this->nodeAttributes($data);
     }
     zbase_db_transaction_start();
     try {
         $parent = !empty($data['category']) ? $data['category'] : null;
         $parentNodes = [];
         if (!empty($parent)) {
             $currentParent = $this->ancestors()->first();
             if (is_array($parent)) {
                 foreach ($parent as $p) {
                     if ($parent instanceof Interfaces\EntityInterface) {
                         $parentCategoryNode = $p;
                     } else {
                         $parentCategoryNode = $this->repository()->byAlphaId($p);
                     }
                     if ($parentCategoryNode instanceof Interfaces\EntityInterface) {
                         if ($currentParent->id() != $parentCategoryNode->id()) {
                             $parentNodes[] = $parentCategoryNode;
                         }
                     } else {
                         zbase_alert('error', _zt('There was a problem performing your request.'));
                         return false;
                     }
                 }
             }
         }
         if (empty($parentNodes)) {
             $parentNodes[] = self::root();
         }
         if ($action == 'create' && strtolower($method) == 'post') {
             $this->save();
             $this->_setParentNodes($parentNodes);
             $this->uploadNodeFile();
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             zbase_alert('success', _zt('Created "%title%"!', ['%title%' => $this->title, '%id%' => $this->id()]));
             return true;
         }
         if ($action == 'update' && strtolower($method) == 'post') {
             $this->save();
             $this->_setParentNodes($parentNodes);
             $this->uploadNodeFile();
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             zbase_alert('success', _zt('Saved "%title%"!', ['%title%' => $this->title, '%id%' => $this->id()]));
             return true;
         }
         if ($action == 'delete' && strtolower($method) == 'post') {
             $this->delete();
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $undoText = '';
             if (!empty($this->hasSoftDelete())) {
                 $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Undo Delete" class="undodelete">Undo</a>.';
                 $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             }
             zbase_alert('success', _zt('Deleted "%title%"! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]));
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_db_transaction_rollback();
     }
     if ($action == 'index') {
         return;
     }
     if ($action == 'update') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             zbase_alert('warning', _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]));
             return false;
         }
     }
     if ($action == 'delete') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             zbase_alert('warning', _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]));
             return false;
         }
     }
     try {
         if ($action == 'move') {
         }
         if ($action == 'restore') {
             if ($this->trashed()) {
                 $this->restore();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $this->_actionMessages[$action]['success'][] = _zt('Row "%title%" was restored!', ['%title%' => $this->title, '%id%' => $this->id()]);
                 return true;
             }
             zbase_alert('error', _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]));
             return false;
         }
         if ($action == 'ddelete') {
             if ($this->trashed()) {
                 $this->forceDelete();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 zbase_alert('success', _zt('Row "%title%" was removed from database!', ['%title%' => $this->title, '%id%' => $this->id()]));
                 return true;
             }
             zbase_alert('error', _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]));
             return false;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_alert('error', _zt('There was a problem performing the request for "%title%".', ['%title%' => $this->title, '%id%' => $this->id()]));
         zbase_db_transaction_rollback();
     }
     return false;
 }
Exemple #3
0
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  * @return boolean
  */
 public function nodeWidgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     zbase_db_transaction_start();
     try {
         if ($action == 'create' && strtolower($method) == 'post') {
             $this->createNode($data);
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $this->_actionMessages[$action]['success'][] = _zt('Created "%title%"!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return true;
         }
         if ($action == 'update' && strtolower($method) == 'post') {
             $this->updateNode($data);
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $this->_actionMessages[$action]['success'][] = _zt('Saved "%title%"!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_db_transaction_rollback();
     }
     if ($action == 'index') {
         return;
     }
     if ($action == 'update') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->alphaId()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->alphaId()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             $this->_actionMessages[$action]['warning'][] = _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
             return false;
         }
     }
     if ($action == 'delete') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->alphaId()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->alphaId()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             $this->_actionMessages[$action]['warning'][] = _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
             return false;
         }
     }
     try {
         if (strtolower($method) == 'post') {
             if ($action == 'delete') {
                 if ($this->hasSoftDelete()) {
                     $this->deleted_at = zbase_date_now();
                     $this->save();
                 } else {
                     $this->delete();
                 }
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $undoText = '';
                 if (!empty($this->hasSoftDelete())) {
                     $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->alphaId()]) . '" title="Undo Delete" class="undodelete">Undo</a>';
                     $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->alphaId()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
                 }
                 $this->_actionMessages[$action]['success'][] = _zt('Deleted "%title%"! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
                 return true;
             }
         }
         if ($action == 'restore') {
             if ($this->trashed()) {
                 $this->restore();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $this->_actionMessages[$action]['success'][] = _zt('Row "%title%" was restored!', ['%title%' => $this->title, '%id%' => $this->id()]);
                 return true;
             }
             $this->_actionMessages[$action]['error'][] = _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return false;
         }
         if ($action == 'ddelete') {
             if ($this->trashed()) {
                 $this->forceDelete();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $this->_actionMessages[$action]['success'][] = _zt('Row "%title%" forever deleted!', ['%title%' => $this->title, '%id%' => $this->id()]);
                 return true;
             }
             $this->_actionMessages[$action]['error'][] = _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return false;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         $this->_actionMessages[$action]['error'][] = _zt('There was a problem performing the request for "%title%".', ['%title%' => $this->title, '%id%' => $this->id()]);
         zbase_db_transaction_rollback();
     }
     return false;
 }
Exemple #4
0
 public function controllerIndex()
 {
     if (!$this->getModule()->hasAccess()) {
         if (zbase_auth_has()) {
             return $this->unathorized(_zt('You don\'t have enough access to the resource.'));
         } else {
             return redirect()->to(zbase_url_from_route('login'));
         }
     }
     /**
      * Check for widgets
      */
     $widgetsAction = $action = str_replace('.', '-', $this->getRouteParameter('action', 'index'));
     $requestMethod = zbase_request_method();
     if (!empty($this->nodeName)) {
         $widgetsAction = $requestMethod . '-node-' . $this->nodeName . '-' . $action;
         $htmls = [];
     }
     $isAjax = zbase_request_is_ajax();
     if ($isAjax) {
         $widgetsAction = (!empty($this->nodeName) ? $requestMethod . '-node-' . $this->nodeName . '-' : '') . 'json-' . $action;
         $htmls = [];
     }
     if ($this->getModule()->hasAction($requestMethod . '-' . $action)) {
         $widgetsAction = $requestMethod . '-' . $action;
         $action = $widgetsAction;
         $htmls = [];
     }
     $widgets = $this->getModule()->pageProperties($action)->widgetsByControllerAction($widgetsAction);
     if (count($widgets) == 1) {
         $firstWidget = collect($widgets)->first();
         if ($firstWidget instanceof \Zbase\Widgets\WidgetInterface) {
             $firstWidget->pageProperties($widgetsAction);
         }
     }
     if (!is_array($widgets) && $widgets instanceof \Illuminate\Http\RedirectResponse) {
         return $widgets;
     }
     zbase()->json()->addVariable('_widget', $this->getModule()->id() . '_' . str_replace('-', '', $action));
     if (zbase_is_dev()) {
         zbase()->json()->addVariable(__METHOD__, $widgetsAction);
         if (zbase_request_is_post()) {
             zbase()->json()->addVariable('_POST_PARAMETERS', zbase_request_inputs());
         }
         zbase()->json()->addVariable('_ROUTE_PARAMETERS', zbase_route_inputs());
         zbase()->json()->addVariable('_GET_PARAMETERS', zbase_request_query_inputs());
     }
     // dd($this->getModule(), $widgetsAction, $widgets);
     if (empty($widgets)) {
         return zbase_abort(404);
     }
     foreach ($widgets as $widget) {
         if (!empty($this->nodeName)) {
             zbase()->json()->addVariable('node', ['prefix' => $this->getModule()->nodeNamespace(), 'name' => $this->nodeName, 'support' => 1]);
             $widget->setNodename($this->nodeName)->setNodeSupport(true);
         }
         if ($widget instanceof \Zbase\Widgets\ControllerInterface) {
             $v = $widget->validateWidget($action);
             if ($v instanceof \Illuminate\Contracts\Validation\Validator) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('errors', $v->errors()->getMessages());
                     return new \Illuminate\Http\JsonResponse($v->errors()->getMessages(), 422);
                 } else {
                     return redirect()->to($this->getRedirectUrl())->withInput(zbase_request_inputs())->withErrors($v->errors()->getMessages());
                 }
             }
             $ret = $widget->controller($this->getRouteParameter('action', 'index'));
             if ($ret instanceof \Zbase\Exceptions\NotFoundHttpException) {
                 return $this->notFound();
             }
             if ($ret instanceof \Zbase\Exceptions\UnauthorizedException) {
                 return $this->unathorized();
             }
             if ($ret instanceof \Zbase\Exceptions\Exception) {
                 return $this->error();
             }
             if ($ret instanceof \Illuminate\Http\RedirectResponse) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('redirect', $ret->getTargetUrl());
                 } else {
                     return $ret;
                 }
             }
             if (zbase_is_json()) {
                 zbase_response_format_set('json');
                 $jsonIndexName = $widget->getWidgetPrefix();
                 if (zbase_is_angular()) {
                     if ($widget instanceof \Zbase\Widgets\Type\Datatable) {
                         $angularTemplate = zbase_angular_widget_datatable($this->getModule(), $widget);
                         $jsonIndexName = $angularTemplate['serviceName'];
                     }
                 }
                 if (zbase_is_dev()) {
                     zbase()->json()->addVariable('$jsonIndexName', $jsonIndexName);
                 }
                 if (!$widget->isExporting()) {
                     zbase()->json()->addVariable($jsonIndexName, $widget->toArray());
                 }
             } else {
                 if ($isAjax) {
                     $htmls[str_replace('-', '_', $widget->id())] = $widget->render();
                 }
             }
             $widget->pageProperties($widgetsAction);
         }
     }
     if (!empty($isAjax)) {
         zbase()->json()->addVariable('_widgets', 1);
         zbase()->json()->addVariable('html', $htmls);
     } else {
         return $this->view(zbase_view_file('module.index'), array('module' => $this->getModule(), 'widgets' => $widgets));
     }
 }
 /**
  * Used only for testing
  * @return view
  */
 public function form()
 {
     if ($this->isPost()) {
         $validatorMessages = ['email.required' => _zt('Email Address is required.'), 'email.email' => _zt('Invalid email address.')];
         $valid = $this->validateInputs(zbase()->request()->inputs(), ['email' => 'required|email'], $validatorMessages);
         if (!empty($valid)) {
             $this->message('success', _zt('Successfull!'));
         }
     }
     return $this->view('form');
 }
Exemple #6
0
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  * @return boolean
  */
 public function widgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     if (!empty($this->message_recipient_id)) {
         $recipient = new Recipient();
         $msgRecipient = $recipient->repository()->byId($this->message_recipient_id);
     }
     if ($action == 'read') {
         if (empty($msgRecipient->read_status)) {
             $msgRecipient->read_status = 1;
             $msgRecipient->save();
         }
     }
     if (strtolower($method) == 'post') {
         if (!empty($data['msg'])) {
             $oMessage = $this->fetchByAlphaId($data['msg']);
         }
         if (!empty($oMessage)) {
             /**
              * Action is read, but posting, means that it is a reply
              */
             if ($action == 'read' || $action == 'reply') {
                 $message = $data['content'];
                 $subject = 'RE: ' . $oMessage->subject();
                 $sender = zbase_auth_user()->id();
                 $recipient = $oMessage->sender_id;
                 if (!empty($oMessage->node_id) && !empty($oMessage->node_prefix)) {
                     $options['node_id'] = $oMessage->node_id;
                     $options['node_prefix'] = $oMessage->node_prefix;
                     if (!empty($oMessage->parent_id)) {
                         $options['parent_id'] = $oMessage->parent_id;
                     } else {
                         $options['parent_id'] = $oMessage->id();
                     }
                 }
                 $messageObject = zbase_entity($this->entityName, [], true);
                 $newMessage = $messageObject->newMessage($message, $subject, $sender, $recipient, $options);
                 $msgRecipient->reply_status = 1;
                 $msgRecipient->save();
                 $this->_actionMessages[$action]['success'][] = _zt('Message sent.', ['%title%' => $newMessage->subject()]);
                 return true;
             }
         }
         if ($action == 'trash') {
             $msgRecipient->trash_status = 1;
             $msgRecipient->save();
             $this->_actionMessages[$action]['success'][] = _zt('Message trashed.', ['%title%' => $this->subject()]);
             return true;
         }
         $this->_actionMessages[$action]['error'][] = _zt('Message reference not found. Kindly check.', ['%title%' => $this->title, '%id%' => $this->id()]);
         return false;
     }
     return true;
 }
Exemple #7
0
 /**
  * Verify email address
  * @param string $code
  * @return boolean
  */
 public function verifyEmailAddress($code)
 {
     try {
         $verificationCode = $this->getDataOption('email_verification_code', null);
         if (!is_null($code) && $code == $verificationCode) {
             $oldEmails = $this->getDataOption('email_old');
             if (is_array($oldEmails)) {
                 $i = 0;
                 foreach ($oldEmails as $e) {
                     if ($e['new'] == $this->email()) {
                         $e['verify'] = zbase_date_now();
                         $e['verify_ip'] = zbase_ip();
                         $oldEmails[$i] = $e;
                     }
                     $i++;
                 }
             }
             if (!empty($oldEmails)) {
                 $this->setDataOption('email_old', $oldEmails);
             }
             $this->unsetDataOption('email_verification_code');
             $this->email_verified = 1;
             $this->email_verified_at = zbase_date_now();
             $this->log('user::verifyEmailAddress');
             $this->save();
             zbase_alert('info', _zt('Your email address <strong>%email%<strong> is now verified.', ['%email%' => $this->email()]));
             zbase_session_flash('user_verifyEmailAddress', true);
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_exception_throw($e);
     }
     return false;
 }
Exemple #8
0
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  * @return boolean
  */
 public function nodeWidgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     zbase_db_transaction_start();
     try {
         if (strtolower($method) == 'post') {
             if ($action == 'file-update') {
                 $action = 'update';
             }
             if ($action == 'file-delete') {
                 $action = 'delete';
             }
         }
         if (strtolower($method) == 'post' && zbase_request_is_upload()) {
             $parentObject = $widget->parentEntityObject();
             if (empty($parentObject)) {
                 return false;
             }
             $this->receiveFile($parentObject);
             $action = 'create';
         }
         if (strtolower($method) == 'post') {
             if (!empty($data)) {
                 $newData = $data;
                 $data = [];
                 foreach ($newData as $dK => $dV) {
                     $data[str_replace('nodefile', '', $dK)] = $dV;
                 }
             }
         }
         if ($action == 'create' && strtolower($method) == 'post') {
             if (isset($data['title'])) {
                 $this->title = $data['title'];
             }
             if (isset($data['excerpt'])) {
                 $this->excerpt = $data['excerpt'];
             }
             $this->save();
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $this->_actionMessages[$action]['success'][] = _zt('File Uploaded!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return true;
         }
         if ($action == 'update' && strtolower($method) == 'post') {
             foreach ($data as $k => $v) {
                 unset($data[$k]);
                 $data[str_replace('nodefile', '', $k)] = $v;
             }
             if (!empty($data['status'])) {
                 $this->status = 2;
                 unset($data['status']);
             } else {
                 $this->status = 0;
             }
             if (isset($data['title'])) {
                 $this->title = $data['title'];
             }
             if (isset($data['excerpt'])) {
                 $this->excerpt = $data['excerpt'];
             }
             if (isset($data['primary']) && !empty($data['primary'])) {
                 $this->updatePrimary($data['primary']);
                 $this->parentObject()->image = $this->alphaId();
             } else {
                 $this->parentObject()->image = null;
             }
             $this->parentObject()->save();
             $this->save();
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $this->_actionMessages[$action]['success'][] = _zt('Saved', ['%title%' => $this->title, '%id%' => $this->id()]);
             return true;
         }
         if ($action == 'primary' && strtolower($method) == 'post') {
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $this->_actionMessages[$action]['success'][] = _zt('Saved', ['%title%' => $this->title, '%id%' => $this->id()]);
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_db_transaction_rollback();
     }
     if ($action == 'index') {
         return;
     }
     if ($action == 'update') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             $this->_actionMessages[$action]['warning'][] = _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
             return false;
         }
     }
     if ($action == 'delete') {
         if ($this->hasSoftDelete() && $this->trashed()) {
             $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Restore" class="undodelete">Restore</a>';
             $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             $this->_actionMessages[$action]['warning'][] = _zt('Row "%title%" was trashed! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
             return false;
         }
     }
     try {
         if ($action == 'delete') {
             if ($this->hasSoftDelete()) {
                 $this->deleted_at = zbase_date_now();
                 $this->save();
             } else {
                 $this->_deleteFile();
                 $this->delete();
             }
             $this->log($action);
             zbase_db_transaction_commit();
             zbase_cache_flush([$this->getTable()]);
             $undoText = '';
             if (!empty($this->hasSoftDelete())) {
                 $undoText = '<a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'restore', 'id' => $this->id()]) . '" title="Undo Delete" class="undodelete">Undo</a>.';
                 $undoText .= ' | <a href="' . $widget->getModule()->url(zbase_section(), ['action' => 'ddelete', 'id' => $this->id()]) . '" title="Delete Forever " class="ddeleteforever">Delete Forever</a>';
             }
             $this->_actionMessages[$action]['success'][] = _zt('File Deleted! %undo%', ['%title%' => $this->title, '%id%' => $this->id(), '%undo%' => $undoText]);
             return true;
         }
         if ($action == 'restore') {
             if ($this->trashed()) {
                 $this->restore();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $this->_actionMessages[$action]['success'][] = _zt('Row "%title%" was restored!', ['%title%' => $this->title, '%id%' => $this->id()]);
                 return true;
             }
             $this->_actionMessages[$action]['error'][] = _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return false;
         }
         if ($action == 'ddelete') {
             if ($this->trashed()) {
                 $this->forceDelete();
                 $this->_deleteFile();
                 $this->log($action);
                 zbase_db_transaction_commit();
                 zbase_cache_flush([$this->getTable()]);
                 $this->_actionMessages[$action]['success'][] = _zt('Row "%title%" was removed from database!', ['%title%' => $this->title, '%id%' => $this->id()]);
                 return true;
             }
             $this->_actionMessages[$action]['error'][] = _zt('Error restoring "%title%". Row was not trashed.!', ['%title%' => $this->title, '%id%' => $this->id()]);
             return false;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         $this->_actionMessages[$action]['error'][] = _zt('There was a problem performing the request for "%title%".', ['%title%' => $this->title, '%id%' => $this->id()]);
         zbase_db_transaction_rollback();
     }
     return false;
 }
Exemple #9
0
<div class="ui-auth">
	<?php 
echo zbase_view_render(zbase_view_file_contents('ui.message.access'), array('message' => !empty($message) ? $message : _zt('You need to login to be able to continue')));
?>
	<hr />
	<?php 
echo zbase_view_render(zbase_view_file_contents('auth.login.form'));
?>
	<hr />
</div>
 public function boot()
 {
     parent::boot();
     $this->loadViewsFrom(__DIR__ . '/../resources/views', zbase_tag());
     $this->loadViewsFrom(__DIR__ . '/../modules', zbase_tag() . 'modules');
     if (!zbase_is_testing()) {
         $this->mergeConfigFrom(__DIR__ . '/../config/config.php', zbase_tag());
         $packages = zbase()->packages();
         if (!empty($packages)) {
             foreach ($packages as $packageName) {
                 $packagePath = zbase_package($packageName)->path();
                 $this->loadViewsFrom($packagePath . 'modules', $packageName . 'modules');
                 if (zbase_file_exists($packagePath . 'resources/views')) {
                     $this->loadViewsFrom($packagePath . 'resources/views', $packageName);
                 }
                 if (zbase_file_exists($packagePath . 'resources/assets')) {
                     $this->publishes([$packagePath . 'resources/assets' => zbase_public_path(zbase_path_asset($packageName))], 'public');
                 }
                 if (zbase_file_exists($packagePath . '/Http/Controllers/Laravel/routes.php')) {
                     require $packagePath . '/Http/Controllers/Laravel/routes.php';
                 }
             }
         }
         $this->app['config'][zbase_tag()] = array_replace_recursive($this->app['config'][zbase_tag()], zbase()->getPackagesMergedConfigs());
     } else {
         $this->loadViewsFrom(__DIR__ . '/../tests/resources/views', zbase_tag() . 'test');
         copy(__DIR__ . '/../config/entities/user.php', __DIR__ . '/../tests/config/entities/user.php');
         $this->mergeConfigFrom(__DIR__ . '/../tests/config/config.php', zbase_tag());
     }
     $this->publishes([__DIR__ . '/../resources/assets' => zbase_public_path(zbase_path_asset())], 'public');
     $this->publishes([__DIR__ . '/../database/migrations' => base_path('database/migrations'), __DIR__ . '/../database/seeds' => base_path('database/seeds'), __DIR__ . '/../database/factories' => base_path('database/factories')], 'migrations');
     $this->app['config']['database.connections.mysql.prefix'] = zbase_db_prefix();
     $this->app['config']['auth.providers.users.model'] = get_class(zbase_entity('user'));
     $this->app['config']['auth.passwords.users.table'] = zbase_config_get('entity.user_tokens.table.name');
     $this->app['config']['auth.passwords.users.email'] = zbase_view_file_contents('auth.password.email.password');
     require __DIR__ . '/Http/Controllers/Laravel/routes.php';
     zbase()->prepareWidgets();
     /**
      * Validator to check for account password
      * @TODO should be placed somewhere else other than here, and just call
      */
     \Validator::extend('accountPassword', function ($attribute, $value, $parameters, $validator) {
         if (zbase_auth_has()) {
             $user = zbase_auth_user();
             if (zbase_bcrypt_check($value, $user->password)) {
                 return true;
             }
         }
         return false;
     });
     \Validator::replacer('accountPassword', function ($message, $attribute, $rule, $parameters) {
         return _zt('Account password don\'t match.');
     });
     /**
      *
      */
     \Validator::extend('passwordStrengthCheck', function ($attribute, $value, $parameters, $validator) {
         //			if(!preg_match("#[0-9]+#", $value))
         //			{
         //				//$errors[] = "Password must include at least one number!";
         //				return false;
         //			}
         //
         //			if(!preg_match("#[a-zA-Z]+#", $value))
         //			{
         //				//$errors[] = "Password must include at least one letter!";
         //				return false;
         //			}
         return true;
     });
     \Validator::replacer('passwordStrengthCheck', function ($message, $attribute, $rule, $parameters) {
         return _zt('New password is too weak.');
     });
     // dd(zbase_config_get('email.account-noreply.email'));
     // dd(\Zbase\Utility\Service\Flickr::findByTags(['heavy equipment','dozers','loader']));
 }
Exemple #11
0
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  * @return boolean
  */
 public function nodeWidgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     zbase_db_transaction_start();
     try {
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_db_transaction_rollback();
     }
     try {
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         $this->_actionMessages[$action]['error'][] = _zt('There was a problem performing the request for "%title%".', ['%title%' => $this->title, '%id%' => $this->id()]);
         zbase_db_transaction_rollback();
     }
     return false;
 }
Exemple #12
0
 /**
  * Method not allowed
  *
  * @param string $msg
  * @return type
  */
 public function methodNotAllowed($msg = 'Method not allowed.')
 {
     return zbase_abort(405, _zt($msg));
 }
Exemple #13
0
 /**
  * Prepare the Actions
  */
 protected function _actions()
 {
     if (!empty($this->_actions)) {
         foreach ($this->_actions as $actionName => $action) {
             $enable = !empty($action['enable']) ? true : false;
             if (!empty($enable)) {
                 $label = !empty($action['label']) ? $action['label'] : ucfirst($actionName);
                 $action['type'] = 'component.button';
                 $action['id'] = $this->id() . 'Action' . $actionName;
                 $action['size'] = 'extrasmall';
                 $action['label'] = _zt($label);
                 $action['tag'] = 'a';
                 if (!empty($action['route']['name'])) {
                     if (!empty($action['route']['params'])) {
                         foreach ($action['route']['params'] as $paramName => $paramValue) {
                             if (preg_match('/row::/', $paramValue)) {
                                 $rowIndex = str_replace('row::', '', $paramValue);
                                 if (!empty($row)) {
                                     $action['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                                 }
                             }
                         }
                     }
                     $action['routeParams'] = $action['route']['params'];
                     $action['route'] = $action['route']['name'];
                 }
                 $btn = \Zbase\Ui\Ui::factory($action);
                 if ($actionName == 'create') {
                     if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
                         $this->_actionCreateButton = $btn;
                     }
                     continue;
                 }
             }
         }
     }
 }