示例#1
0
 protected function getBreadcrumb()
 {
     $depth = Status::depth($this->statusVariables);
     if ($depth <= 1) {
         return array();
     }
     $breadcrumb = array();
     $gridConfig = $this->config;
     $breadcrumb[] = array('title' => $gridConfig->getTitle(), 'url' => '#');
     $lastStatusVariables = array();
     $db = new Db($this->config, $this->statusVariables);
     for ($i = 1; $i <= $depth - 1; $i++) {
         if (isset($this->statusVariables['gridParentId' . $i])) {
             $parentId = $this->statusVariables['gridParentId' . $i];
         } else {
             $parentId = null;
         }
         if (isset($this->statusVariables['gridId' . $i])) {
             $gridId = $this->statusVariables['gridId' . $i];
         } else {
             $gridId = null;
         }
         $lastStatusVariables = Status::genSubgridVariables($lastStatusVariables, $gridId, $parentId);
         $tmpGridConfig = $gridConfig->subgridConfig($lastStatusVariables);
         $hash = Status::build($lastStatusVariables);
         $breadcrumbGridconfig = $gridConfig->subgridConfig($lastStatusVariables, $i);
         if ($breadcrumbGridconfig->getBreadcrumbField()) {
             $title = $db->breadcrumbTitle($i);
         } else {
             $title = $tmpGridConfig->getTitle();
         }
         $breadcrumb[] = array('title' => $title, 'url' => '#' . $hash);
     }
     return $breadcrumb;
 }
示例#2
0
 public function delete($id)
 {
     $db = new Db($this->subgridConfig, $this->statusVariables);
     $fields = $this->subgridConfig->fields();
     $curData = $db->fetchRow($id);
     foreach ($fields as $field) {
         $fieldObject = $this->subgridConfig->fieldObject($field);
         $fieldObject->beforeDelete($id, $curData);
     }
     $sql = "\n        DELETE\n            " . $this->subgridConfig->tableName() . "\n        FROM\n            " . $this->subgridConfig->tableName() . "\n            " . $db->joinQuery() . "\n        WHERE\n            " . $this->subgridConfig->tableName() . ".`" . $this->subgridConfig->idField() . "` = :id\n        ";
     $params = array('id' => $id);
     $callables = $this->subgridConfig->beforeDelete();
     if ($callables) {
         if (is_array($callables) && !is_callable($callables)) {
             foreach ($callables as $callable) {
                 call_user_func($callable, $params['id']);
             }
         } else {
             call_user_func($callables, $params['id']);
         }
     }
     ipDb()->execute($sql, $params);
     if ($this->subgridConfig->isMultilingual()) {
         $sql = "\n            DELETE\n\n            FROM\n                " . $this->subgridConfig->languageTableName() . "\n            WHERE\n                " . $this->subgridConfig->languageTableName() . ".`" . $this->subgridConfig->languageForeignKeyField() . "` = :id\n            ";
         ipDb()->execute($sql, $params);
     }
     $callables = $this->subgridConfig->afterDelete();
     if ($callables) {
         if (is_array($callables) && !is_callable($callables)) {
             foreach ($callables as $callable) {
                 call_user_func($callable, $params['id']);
             }
         } else {
             call_user_func($callables, $params['id']);
         }
     }
     //remove records in child grids
     foreach ($fields as $field) {
         $fieldObject = $this->subgridConfig->fieldObject($field);
         $fieldObject->afterDelete($id, $curData);
         if ($field['type'] == 'Grid') {
             $childStatusVariables = Status::genSubgridVariables($this->statusVariables, $field['gridId'], $id);
             $subActions = new Actions(new Config($field['config']), $childStatusVariables);
             $childConfig = new Config($field['config']);
             $db = new Db($childConfig, $childStatusVariables);
             $where = $db->buildSqlWhere();
             $sql = "\n                    SELECT\n                        `" . $childConfig->idField() . "`\n                    FROM\n                        " . $childConfig->tableName() . "\n                    WHERE\n                        {$where}\n                ";
             $idsToDelete = ipDb()->fetchColumn($sql);
             foreach ($idsToDelete as $idToDelete) {
                 $subActions->delete($idToDelete);
             }
         }
     }
 }
示例#3
0
 protected function subgrid($params)
 {
     if (empty($params['gridId'])) {
         throw new \Ip\Exception('girdId GET variable missing');
     }
     if (empty($params['gridParentId'])) {
         throw new \Ip\Exception('girdParentId GET variable missing');
     }
     $newStatusVariables = Status::genSubgridVariables($this->statusVariables, $params['gridId'], $params['gridParentId']);
     $commands[] = Commands::setHash(Status::build($newStatusVariables));
     return $commands;
 }