Example #1
0
 public static function createFolder(array $attributes = [])
 {
     $dir = new static();
     $dir->is_dir = 1;
     $dir->user_id = isset($attributes['user_id']) ? $attributes['user_id'] : 0;
     $dir->project_id = isset($attributes['project_id']) ? $attributes['project_id'] : 0;
     $dir->parent_id = isset($attributes['parent_id']) ? $attributes['parent_id'] : 0;
     $dir->name = isset($attributes['name']) ? $attributes['name'] : '新建文件夹';
     $dir->type = isset($attributes['type']) ? $attributes['type'] : 'dir';
     $dir->path = isset($attributes['path']) ? $attributes['path'] : '/';
     $dir->save();
     $status = true;
     if (isset($attributes['path']) || $dir->parent_id == 0) {
         $dir->path .= $dir->id . '/';
     } else {
         $path = $dir->parent()->where('project_id', $dir->project_id)->where('is_dir', 1)->pluck('path');
         if (!$path || $path->count() == 0) {
             $dir->delete();
             $status = false;
         } else {
             if (!is_string($path)) {
                 $path = $path[0];
             }
             $dir->path = $path . $dir->id . '/';
         }
     }
     if ($status) {
         $dir->save();
         return static::find($dir->id);
     }
 }
Example #2
0
 public static function request()
 {
     $class = new static();
     !Input::has('deleteShippingMethod') ?: $class->delete(Input::get('deleteShippingMethod'));
     !Input::has('updateShippingMethod') ?: $class->update(Input::get('updateShippingMethod'))->with(Input::get('shipping.fill'));
     !Input::has('addShippingMethod') ?: $class->add()->with(Input::get('shipping.fill'));
 }
Example #3
0
 public static function request()
 {
     $class = new static();
     $class->acton = Input::get('action');
     !Input::has('deleteSearch') ?: $class->delete(Input::get('deleteSearch'));
     $class->action != 'addSearch' ?: $class->add(Input::get('search'), Input::get('users'));
 }
Example #4
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     !Input::has('deleteList') ?: $class->delete(Input::get('deleteList'));
     $class->action != 'addList' ?: $class->addList(Input::all());
 }
Example #5
0
 public static function request()
 {
     $class = new static();
     !Input::has('deletePaymentMethod') ?: $class->delete(Input::get('deletePaymentMethod'));
     !Input::has('updatePaymentMethod') ?: $class->update(Input::get('updatePaymentMethod'))->with(Input::get('payment.fill'));
     !Input::has('addPaymentMethod') ?: $class->add()->with(Input::get('payment.fill'));
 }
Example #6
0
 public static function request()
 {
     $class = new static();
     Input::get('action') != 'addComment' ?: $class->add(Input::all());
     !Input::has('hideComment') ?: $class->hide(head(Input::get('hideComment', [])));
     !Input::has('unhideComment') ?: $class->unhide(head(Input::get('unhideComment', [])));
     !Input::has('deleteComment') ?: $class->delete(head(Input::get('deleteComment', [])));
 }
Example #7
0
 public static function request()
 {
     $class = new static();
     Input::get('action') != 'addMessage' ?: $class->add(Input::get('communication'));
     !Input::has('hideMessage') ?: $class->hide(head(Input::get('hideMessage', [])));
     !Input::has('unhideMessage') ?: $class->unhide(head(Input::get('unhideMessage', [])));
     !Input::has('deleteMessage') ?: $class->delete(head(Input::get('deleteMessage', [])));
 }
Example #8
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     $class->sites_id = Input::get('InSite');
     $class->action != 'updateRoles' ?: $class->update(Input::get('role'));
     !starts_with($class->action, 'deleteRole') ?: $class->delete(substr($class->action, 11));
     !Input::has('InUsers') ?: $class->attachUsers(Input::get('InUsers'));
 }
Example #9
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     !starts_with($class->action, "deleteTag") ?: $class->delete(substr($class->action, 10));
     !Input::has('renameTag') ?: $class->renameTags(Input::get('renameTag'));
     !Input::has('newTag') ?: $class->newTags(Input::get('newTag'));
     event('veer.message.center', trans('veeradmin.tag.update'));
 }
Example #10
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     !Input::has('deleteUserbook') ?: $class->delete(Input::get('deleteUserbook'));
     if ($class->action == 'addUserbook' || $class->action == 'updateUserbook') {
         $class->update(head(Input::get('userbook', [])));
     }
 }
 public static function deleteMany(array $hashes)
 {
     foreach ($hashes as $hash) {
         if (array_key_exists("id", $hash)) {
             $Hash = new static();
             $Hash->id = $hash['id'];
             $Hash->delete();
         }
     }
 }
Example #12
0
 /**
  * Actions for attributes based on Request.
  * @return void
  */
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     $newValue = Input::get('newValue');
     $newName = Input::get('newName');
     $renameAttrName = Input::get('renameAttrName');
     !starts_with($class->action, "deleteAttrValue") ?: $class->delete(substr($class->action, 16));
     $class->action != 'newAttribute' ?: $class->add($newName, $newValue);
     $class->rename($renameAttrName)->update(Input::all());
     event('veer.message.center', trans('veeradmin.attribute.update'));
 }
Example #13
0
 /**
  * 
  * @return void
  */
 public static function request()
 {
     //\Event::fire('router.filter: csrf');
     $class = new static();
     $class->action = Input::get('action');
     if (Input::has('id')) {
         return $class->one();
     }
     $class->updateRestrictions(Input::get('changeRestrictUser'));
     $class->updateBan(Input::get('changeStatusUser'));
     $class->delete(Input::get('deleteUser'));
     $class->add($class->action == 'Add' ? Input::all() : null);
 }
Example #14
0
 /**
  * Actions for categories based on Request. Triggers are hardcoded.
  * 
  * @return void
  */
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     $class->action != 'delete' ?: $class->delete(Input::get('deletecategoryid'));
     if (Input::has('category')) {
         return $class->one();
     }
     $addCategory = $class->action == 'add' ? Input::all() : null;
     $sortCategory = $class->action == 'sort' ? Input::all() : null;
     $class->sort($sortCategory)->addCategory($addCategory);
     //return $class->isAjaxRequest();
 }
Example #15
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     foreach (array_keys(Input::all()) as $k) {
         if (Input::hasFile($k)) {
             // @todo attention
             $class->uploadedIds = array_merge($class->uploadedIds, $class->upload('image', $k, null, null, '', null, true));
             event('veer.message.center', trans('veeradmin.image.upload'));
         }
     }
     !Input::has('attachImages') ?: $class->attachImages(Input::get('attachImages'));
     !starts_with($class->action, 'deleteImage') ?: $class->delete(substr($class->action, 12));
 }
Example #16
0
 /**
  * Get a unique temporary file.
  * 
  * @param string $filename
  * @param string $extension
  * @return File 
  */
 public static function tempFile($filename = '', $extension = '')
 {
     $folder = \GO::config()->getTempFolder();
     if (!empty($filename)) {
         $p = $folder->path() . '/' . $filename;
     } else {
         $p = $folder->path() . '/' . uniqid(time());
     }
     if (!empty($extension)) {
         $p .= '.' . $extension;
     }
     $file = new static($p);
     $file->delete();
     return $file;
 }
Example #17
0
 public static function request()
 {
     $class = new static();
     !Input::has('deleteStatus') ?: $class->delete(Input::get('deleteStatus'));
     if (Input::has('addStatus')) {
         foreach (Input::get('InName') as $key => $value) {
             if (!empty($value)) {
                 $class->addOrUpdateFromRequest(new \Veer\Models\OrderStatus(), $key, null, $key, '#000');
                 $_added = true;
             }
         }
         !isset($_added) ?: event('veer.message.center', trans('veeradmin.status.new'));
     }
     if (Input::has('updateGlobalStatus')) {
         $o = \Veer\Models\OrderStatus::find(Input::get('updateGlobalStatus'));
         if (is_object($o)) {
             $class->addOrUpdateFromRequest($o, $o->id, $o->name, $o->manual_order, $o->color);
             event('veer.message.center', trans('veeradmin.status.update'));
         }
     }
 }
Example #18
0
 public static function request()
 {
     $class = new static();
     $class->action = Input::get('action');
     list($command, $id) = array_pad(explode('.', $class->action, 2), 2, null);
     switch ($command) {
         case 'removeFile':
             $class->remove($id);
             break;
         case 'deleteFile':
             $class->delete($id);
             break;
         case 'makeRealLink':
             $class->mklink($id, Input::all());
             break;
         case 'copyFile':
             $class->copyFileToPagesOrProducts($id, Input::all());
             break;
     }
     !Input::hasFile('uploadFiles') ?: ($class->uploadedIds[] = $class->upload('file', 'uploadFiles', null, null, '', null, true));
     !Input::has('attachFiles') ?: $class->copyFilesToPagesOrProductsFromForm(Input::get('attachFiles'));
 }
 /**
  * @warning this is not valid if $itemtype_1 == $itemtype_2 !
  *
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     $action = $ma->getAction();
     $input = $ma->getInput();
     $specificities = static::getRelationMassiveActionsSpecificities();
     // First, get normalized action : add or remove
     if (in_array($action, $specificities['normalized']['add'])) {
         $normalized_action = 'add';
     } else {
         if (in_array($action, $specificities['normalized']['remove'])) {
             $normalized_action = 'remove';
         } else {
             // If we cannot get normalized action, then, its not for this method !
             parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
             return;
         }
     }
     $link = new static();
     // Get the default 'input' entries from the relation
     $input2 = static::getRelationInputForProcessingOfMassiveActions($action, $item, $ids, $input);
     // complete input2 with the right fields from input and define the peer with this information
     foreach (array(static::$itemtype_1, static::$items_id_1) as $field) {
         if (isset($input['peer_' . $field])) {
             $input2[$field] = $input['peer_' . $field];
             $item_number = 2;
         }
     }
     foreach (array(static::$itemtype_2, static::$items_id_2) as $field) {
         if (isset($input['peer_' . $field])) {
             $input2[$field] = $input['peer_' . $field];
             $item_number = 1;
         }
     }
     // If the fields provided by showMassiveActionsSubForm are not valid then quit !
     if (!isset($item_number)) {
         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
         $ma->addMessage($link->getErrorMessage(ERROR_NOT_FOUND));
         return;
     }
     if ($item_number == 1) {
         $itemtype = static::$itemtype_1;
         $items_id = static::$items_id_1;
         $peertype = static::$itemtype_2;
         $peers_id = static::$items_id_2;
     } else {
         $itemtype = static::$itemtype_2;
         $items_id = static::$items_id_2;
         $peertype = static::$itemtype_1;
         $peers_id = static::$items_id_1;
     }
     if (preg_match('/^itemtype/', $itemtype)) {
         $input2[$itemtype] = $item->getType();
     }
     // Get the peer from the $input2 and the name of its fields
     $peer = static::getItemFromArray($peertype, $peers_id, $input2, true, true, true);
     // $peer not valid => not in DB or try to remove all at once !
     if ($peer === false || $peer->isNewItem()) {
         if (isset($input2[$peers_id]) && $input2[$peers_id] > 0) {
             $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             if ($peer instanceof CommonDBTM) {
                 $ma->addMessage($peer->getErrorMessage(ERROR_NOT_FOUND));
             } else {
                 $ma->addMessage($link->getErrorMessage(ERROR_NOT_FOUND));
             }
             return;
         }
         if (!$specificities['can_remove_all_at_once'] && !$specificities['only_remove_all_at_once']) {
             return false;
         }
         $peer = false;
     }
     // Make a link between $item_1, $item_2 and $item and $peer. Thus, we will be able to update
     // $item without having to care about the number of the item
     if ($item_number == 1) {
         $item_1 =& $item;
         $item_2 =& $peer;
     } else {
         $item_1 =& $peer;
         $item_2 =& $item;
     }
     switch ($normalized_action) {
         case 'add':
             // remove all at once only available for remove !
             if (!$peer) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 $ma->addMessage($link->getErrorMessage(ERROR_ON_ACTION));
                 return;
             }
             foreach ($ids as $key) {
                 if (!$item->getFromDB($key)) {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                     continue;
                 }
                 $input2[$items_id] = $item->getID();
                 // If 'can_link_several_times', then, we add the elements !
                 if ($specificities['can_link_several_times']) {
                     if ($link->can(-1, CREATE, $input2)) {
                         if ($link->add($input2)) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($link->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($link->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $link->getEmpty();
                     if (!$link->getFromDBForItems($item_1, $item_2)) {
                         if ($specificities['check_both_items_if_same_type'] && $item_1->getType() == $item_2->getType()) {
                             $link->getFromDBForItems($item_2, $item_1);
                         }
                     }
                     if (!$link->isNewItem()) {
                         if (!$specificities['update_if_different']) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($link->getErrorMessage(ERROR_ALREADY_DEFINED));
                             continue;
                         }
                         $input2[static::getIndexName()] = $link->getID();
                         if ($link->can($link->getID(), UPDATE, $input2)) {
                             if ($link->update($input2)) {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($link->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($link->getErrorMessage(ERROR_RIGHT));
                         }
                         // if index defined, then cannot not add any other link due to index unicity
                         unset($input2[static::getIndexName()]);
                     } else {
                         if ($link->can(-1, CREATE, $input2)) {
                             if ($link->add($input2)) {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($link->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($link->getErrorMessage(ERROR_RIGHT));
                         }
                     }
                 }
             }
             return;
         case 'remove':
             foreach ($ids as $key) {
                 // First, get the query to find all occurences of the link item<=>key
                 if (!$peer) {
                     $query = static::getSQLRequestToSearchForItem($item->getType(), $key);
                 } else {
                     if (!$item->getFromDB($key)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                         continue;
                     }
                     $query = 'SELECT `' . static::getIndexName() . '`
                         FROM `' . static::getTable() . '`';
                     $WHERE = array();
                     if (preg_match('/^itemtype/', static::$itemtype_1)) {
                         $WHERE[] = " `" . static::$itemtype_1 . "` = '" . $item_1->getType() . "'";
                     }
                     $WHERE[] = " `" . static::$items_id_1 . "` = '" . $item_1->getID() . "'";
                     if (preg_match('/^itemtype/', static::$itemtype_2)) {
                         $WHERE[] = " `" . static::$itemtype_2 . "` = '" . $item_2->getType() . "'";
                     }
                     $WHERE[] = " `" . static::$items_id_2 . "` = '" . $item_2->getID() . "'";
                     $query .= 'WHERE (' . implode(' AND ', $WHERE) . ')';
                     if ($specificities['check_both_items_if_same_type'] && $item_1->getType() == $item_2->getType()) {
                         $WHERE = array();
                         if (preg_match('/^itemtype/', static::$itemtype_1)) {
                             $WHERE[] = " `" . static::$itemtype_1 . "` = '" . $item_2->getType() . "'";
                         }
                         $WHERE[] = " `" . static::$items_id_1 . "` = '" . $item_2->getID() . "'";
                         if (preg_match('/^itemtype/', static::$itemtype_2)) {
                             $WHERE[] = " `" . static::$itemtype_2 . "` = '" . $item_2->getType() . "'";
                         }
                         $WHERE[] = " `" . static::$items_id_2 . "` = '" . $item_2->getID() . "'";
                         $query .= ' OR (' . implode(' AND ', $WHERE) . ')';
                     }
                 }
                 $request = $DB->request($query);
                 $number_results = $request->numrows();
                 if ($number_results == 0) {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     $ma->addMessage($link->getErrorMessage(ERROR_NOT_FOUND));
                     continue;
                 }
                 $ok = 0;
                 $ko = 0;
                 $noright = 0;
                 foreach ($request as $line) {
                     if ($link->can($line[static::getIndexName()], DELETE)) {
                         if ($link->delete(array('id' => $line[static::getIndexName()]))) {
                             $ok++;
                         } else {
                             $ko++;
                             $ma->addMessage($link->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $noright++;
                         $ma->addMessage($link->getErrorMessage(ERROR_RIGHT));
                     }
                 }
                 if ($ok == $number_results) {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                 } else {
                     if ($noright > 0) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     } else {
                         if ($ko > 0) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         }
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Example #20
0
 /**
  * Enregistre en BDD l'ensemble d'action décrits dans $input
  * Agit comme une série de CommonDBTM::add/update/delete sur différents objets
  *
  * @param array $input
  *           tableau d'actions (typiquement POST après le formulaire)
  */
 public static final function updateAll($input)
 {
     $instance = new static();
     if (isset($input['rules'])) {
         foreach ($input['rules'] as $id => $rule) {
             if (preg_match('@' . self::NEW_ID_TAG . '(\\d*)@', $id)) {
                 $instance->add($rule);
             } else {
                 $rule[self::getIndexName()] = $id;
                 $instance->update($rule);
             }
         }
     }
     if (isset($input['delete_rules'])) {
         foreach ($input['delete_rules'] as $id) {
             $instance->delete(array(self::getIndexName() => $id));
         }
     }
 }
Example #21
0
 public static function request()
 {
     $class = new static();
     !Input::has('updateGlobalDiscounts') ?: $class->add(Input::get('discount', []));
     !Input::has('deleteDiscount') ?: $class->delete(Input::get('deleteDiscount'));
 }
Example #22
0
 /**
  * Renames the directory.
  *
  * @param string  $newDirName New directory name.
  * @param boolean $overwrite  Overwrite an existing directory.
  *
  * @replaces #rename
  */
 public function rename($newDirName, $overwrite = false)
 {
     $this->tossIfDeleted();
     if (!$this->getParent()->isWritable()) {
         throw new EnvironmentException('The directory, %s, can not be renamed because the directory containing it is not writable', $this->directory);
     }
     // If the dirname does not contain any folder traversal, rename the dir in the current parent directory
     if (preg_match('#^[^/\\\\]+$#D', $newDirName)) {
         $newDirName = $this->getParent()->getPath() . $newDirName;
     }
     $info = static::$fs->getPathInfo($newDirName);
     if (!file_exists($info['dirname'])) {
         throw new ProgrammerException('The new directory name specified, %s, is inside of a directory that does not exist', $newDirName);
     }
     if (file_exists($newDirName)) {
         if (!is_writable($newDirName)) {
             throw new EnvironmentException('The new directory name specified, %s, already exists, but is not writable', $newDirName);
         }
         if (!$overwrite) {
             $newDirName = static::$fs->makeUniqueName($newDirName);
         } else {
             $dir = new static($newDirName);
             $dir->delete();
         }
     } else {
         $parentDir = new static($info['dirname']);
         if (!$parentDir->isWritable()) {
             throw new EnvironmentException('The new directory name specified, %s, is inside of a directory that is not writable', $parentDir);
         }
     }
     rename($this->directory, $newDirName);
     $this->directory = static::$fs->makeCanonical(realpath($newDirName));
 }
 public static function unlink($path)
 {
     $opts = static::parsePath($path);
     try {
         $wrapper = new static();
         return $wrapper->delete($opts);
     } catch (Exception $e) {
         dolog(self::getPrefix(false) . ' Error: [unlink] ' . $e->getMessage(), LOG_WARN);
         return false;
     }
 }
Example #24
0
 public static function overwrite($path, $mask = self::MASK)
 {
     if (is_dir($path)) {
         $dir = new static($path);
         $dir->delete();
     }
     return static::create($path, $mask);
 }
Example #25
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'add_item':
             $input = $ma->getInput();
             $item_ticket = new static();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id) && !empty($input['items_id'])) {
                     $input['tickets_id'] = $id;
                     $input['itemtype'] = $input['item_itemtype'];
                     if ($item_ticket->can(-1, CREATE, $input)) {
                         $ok = true;
                         if (!$item_ticket->add($input)) {
                             $ok = false;
                         }
                         if ($ok) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                 }
             }
             return;
         case 'delete_item':
             $input = $ma->getInput();
             $item_ticket = new static();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id) && !empty($input['items_id'])) {
                     $item_found = $item_ticket->find("`tickets_id` = {$id} AND `itemtype` = '" . $input['item_itemtype'] . "' AND `items_id` = " . $input['items_id']);
                     if (!empty($item_found)) {
                         $item_founds_id = array_keys($item_found);
                         $input['id'] = $item_founds_id[0];
                         if ($item_ticket->can($input['id'], DELETE, $input)) {
                             $ok = true;
                             if (!$item_ticket->delete($input)) {
                                 $ok = false;
                             }
                             if ($ok) {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 public static function getByID($ptComposerFormLayoutSetControlID)
 {
     $app = Application::getFacadeApplication();
     $db = $app->make('database')->connection();
     $r = $db->fetchAssoc('select * from PageTypeComposerFormLayoutSetControls where ptComposerFormLayoutSetControlID = ?', [$ptComposerFormLayoutSetControlID]);
     if ($r && $r['ptComposerFormLayoutSetControlID']) {
         $control = new static();
         $control->setPropertiesFromArray($r);
         $control->ptComposerControlObject = unserialize($r['ptComposerControlObject']);
         if (!$control->ptComposerControlObject->objectExists()) {
             $control->delete();
             return null;
         } else {
             $control->ptComposerControlObject->setPageTypeComposerFormLayoutSetControlObject($control);
         }
         return $control;
     }
 }
Example #27
0
 /**
  * Delete rows by id values.
  *
  * @param string|array $ids
  * @param \Phalcon\DiInterface $di
  * @param \Phalcon\Events\ManagerInterface $eventsManager
  * @return string
  */
 public static function deleteRows($params, $key, \Phalcon\DiInterface $di = null, \Phalcon\Events\ManagerInterface $eventsManager = null)
 {
     $result = ['success' => false, 'error' => []];
     if (is_string($params)) {
         if (!\Engine\Tools\String::isJson($params)) {
             $result['error'][] = 'Params not valid';
             return $result;
         }
         $params = json_decode($params);
     }
     if (is_array($params)) {
         if (!isset($params[$key]) && !is_array($params[$key])) {
             $result['error'][] = 'Array params not valid';
             return $result;
         }
         $rows = !isset($rows[0]) ? [$params[$key]] : $params[$key];
     } elseif ($params instanceof \stdClass) {
         if (!isset($params->{$key})) {
             $result['error'][] = 'Object params not valid';
             return $result;
         }
         $rows = is_object($params->{$key}) ? [(array) $params->{$key}] : $params->{$key};
     } else {
         $result['error'][] = 'Params not valid';
         return $result;
     }
     $false = false;
     $form = new static(null, [], $di, $eventsManager);
     if (!$form->isRemovable()) {
         $result['error'][] = 'Data can\'t be remove from this form';
     }
     $primary = $form->getPrimaryField();
     if (!$primary) {
         throw new \Engine\Exception('Primary field not found');
     }
     $primaryKey = $primary->getKey();
     foreach ($rows as $id) {
         if (is_array($id)) {
             if (!isset($id[$primaryKey])) {
                 throw new \Engine\Exception('Primary key not found in params');
             }
             $id = $id[$primaryKey];
         } elseif (is_object($id)) {
             if (!isset($id->{$primaryKey})) {
                 throw new \Engine\Exception('Primary key not found in params');
             }
             $id = $id->{$primaryKey};
         }
         $resultRow = $form->delete($id);
         if ($resultRow === false) {
             $false = true;
             //$result['error'] = array_merge($result['error'], $rowResult['error']);
         }
     }
     if (!$false) {
         $result['success'] = true;
         $result['msg'] = "Deleted";
     }
     return $result;
 }
Example #28
0
 public static function getByID($ptComposerFormLayoutSetControlID)
 {
     $db = Loader::db();
     $r = $db->GetRow('select * from PageTypeComposerFormLayoutSetControls where ptComposerFormLayoutSetControlID = ?', array($ptComposerFormLayoutSetControlID));
     if (is_array($r) && $r['ptComposerFormLayoutSetControlID']) {
         $control = new static();
         $control->setPropertiesFromArray($r);
         $control->ptComposerControlObject = unserialize($r['ptComposerControlObject']);
         if (!$control->ptComposerControlObject->objectExists()) {
             $control->delete();
             return null;
         } else {
             $control->ptComposerControlObject->setPageTypeComposerFormLayoutSetControlObject($control);
         }
         return $control;
     }
 }
Example #29
0
 /**
  * Delete an object in the database
  * @param array|integer $params Primary key value or parameter array
  * @param \PDO $db Database connection to use
  * @return boolean
  */
 public static function _delete($params, &$db = FALSE)
 {
     // Create object
     $obj = new static();
     // Delete
     return $obj->delete($params, $db);
 }