/** Asynchronous controller for material save */ function __async_save() { /** @var array $result Asynchronous controller result */ $result = array('status' => false); // If we have POST data if (isset($_POST)) { // Create empty object /* @var $material \samson\cms\CMSMaterial */ $material = new Material(false); // If material identifier is passed and it's valid if (isset($_POST['MaterialID']) && $_POST['MaterialID'] > 0) { $material = dbQuery('samson\\cms\\Material')->id($_POST['MaterialID'])->first(); } else { // New material creation // Fill creation ts $material->Created = date('Y-m-d H:m:s'); $material->Active = 1; } // Set material modification date $material->Modyfied = date('Y-m-d H:m:s'); // Make it not draft $material->Draft = 0; // Try to find changed information if (isset($_POST['Name'])) { $material->Name = $_POST['Name']; } if (isset($_POST['Published'])) { $material->Published = $_POST['Published']; } if (isset($_POST['type'])) { $material->type = $_POST['type']; } if (isset($_POST['Url'])) { $material->Url = $_POST['Url']; } // Save object to DB $material->save(); /** @var \samson\activerecord\structurematerial $structureMaterial Clear existing * relations between material and structures */ foreach (dbQuery('structurematerial')->cond('MaterialID', $material->id)->exec() as $structureMaterial) { $structureMaterial->delete(); } // Iterate relations between material and structures if (isset($_POST['StructureID'])) { foreach ($_POST['StructureID'] as $structureId) { // Save record $sm = new CMSNavMaterial(false); $sm->MaterialID = $material->id; $sm->StructureID = $structureId; $sm->Active = 1; $sm->save(); } } // Success $result['status'] = true; $result[] = $this->__async_form($material->id); } // Fail return $result; }
/** * Add new structure to entity * @param int $navigation Parent navigation identifier */ public function __async_addnav($materialId = null, $navigation = null) { // Save record $sm = new CMSNavMaterial(false); $sm->MaterialID = $materialId; $sm->StructureID = $navigation; $sm->Active = '1'; $sm->save(); }