public function createNew($data = array()) { // acts as the parameterized constructor $this->id = $data["id"]; $this->no = $data["no"]; $this->owner = $data["owner"]; $this->status = $data["status"]; $this->barcode = $data["barcode"]; $this->price = $data["price"]; $this->installed_date = $data["installed_date"]; $this->condition = $data["condition"]; $this->supplier = $data["supplier"]; $this->item_id = $data["item_id"]; $parentItem = Item::search(array("item_id" => $data["item_id"])); $parentCategoryNo = $parentItem->get_category()[0]; $parentCategory = Category::search(array("category_id" => $parentCategoryNo)); $itemCopyList = $parentItem->get_copies(); if (!empty($itemCopyList)) { array_push($itemCopyList, $this); } else { $itemCopyList[1] = $this; } end($itemCopyList); $last_id = key($itemCopyList); $no1 = (string) $parentCategory->get_label(); $no2 = (string) $parentItem->get_no(); $no3 = (string) $last_id; $this->no = $no1 . $no2 . "_" . $no3; }
public function actionIndex() { $this->pageTitle = 'Рубрики'; $model = new Category('search'); $model->unsetAttributes(); if(isset($_GET['Category'])) $model->attributes=$_GET['Category']; $dataProvider = $model->search(); $this->render('index', array( 'model' => $model, 'dataProvider'=>$dataProvider, )); }
public function actionGeneratePdf() { $this->layout = 'pdf'; $model = new Category('search'); if (isset($_GET['Category'])) { $model->attributes = $_GET['Category']; } // to execute the filters (if is the case) $dataProvider = $model->search(); $dataProvider->pagination = false; $mPDF1 = Yii::app()->ePdf->mpdf(); # You can easily override default constructor's params $mPDF1 = Yii::app()->ePdf->mpdf('', 'A5'); # renderPartial (only 'view' of current controller) $mPDF1->WriteHTML($this->renderPartial('admin', array('model' => $model), true)); # Outputs ready PDF $mPDF1->Output(); }
/** * @brief Import Parts (create Parts, and if neccessary, Categories, Footprints and so on) * * @note This function uses database transactions. If an error occurs, all changes will be rolled back. * * @param Database &$database reference to the database object * @param User &$current_user reference to the user which is logged in * @param Log &$log reference to the Log-object * @param array $data The import data array from "extract_import_data_from_request()" * @param boolean $only_check_data If true, this function will only check if all values in "$data" are valid. * In this case, no parts will be imported! * * @retval array All new Part objects (only if "$only_check_data == false") * * @throws Exception if there was an error (maybe the passed data is not valid) */ function import_parts(&$database, &$current_user, &$log, $data, $only_check_data = false) { $parts = array(); try { $transaction_id = $database->begin_transaction(); // start transaction // Get the category, footprint, storelocation, ... which are named "Import", or create them. // We need this elements as parent for new elements, which will be created while import parts. $import_categories = Category::search($database, $current_user, $log, 'Import', true); if (count($import_categories) > 0) { $import_category = $import_categories[0]; $import_category_created = false; } else { $import_category = Category::add($database, $current_user, $log, 'Import', NULL); $import_category_created = true; // we can delete it later if we didn't need it } $import_storelocations = Storelocation::search($database, $current_user, $log, 'Import', true); if (count($import_storelocations) > 0) { $import_storelocation = $import_storelocations[0]; $import_storelocation_created = false; } else { $import_storelocation = Storelocation::add($database, $current_user, $log, 'Import', NULL); $import_storelocation_created = true; // we can delete it later if we didn't need it } $import_footprints = Footprint::search($database, $current_user, $log, 'Import', true); if (count($import_footprints) > 0) { $import_footprint = $import_footprints[0]; $import_footprint_created = false; } else { $import_footprint = Footprint::add($database, $current_user, $log, 'Import', NULL); $import_footprint_created = true; // we can delete it later if we didn't need it } $import_suppliers = Supplier::search($database, $current_user, $log, 'Import', true); if (count($import_suppliers) > 0) { $import_supplier = $import_suppliers[0]; $import_supplier_created = false; } else { $import_supplier = Supplier::add($database, $current_user, $log, 'Import', NULL); $import_supplier_created = true; // we can delete it later if we didn't need it } $import_manufacturers = Manufacturer::search($database, $current_user, $log, 'Import', true); if (count($import_manufacturers) > 0) { $import_manufacturer = $import_manufacturers[0]; $import_manufacturer_created = false; } else { $import_manufacturer = Manufacturer::add($database, $current_user, $log, 'Import', NULL); $import_manufacturer_created = true; // we can delete it later if we didn't need it } $import_category_used = false; $import_storelocation_used = false; $import_footprint_used = false; $import_supplier_used = false; $import_manufacturer_used = false; // start import $row_index = 0; foreach ($data as $row) { $name = $row['part_name']; $description = $row['part_description']; $instock = $row['part_instock']; $mininstock = $row['part_mininstock']; $comment = $row['part_comment']; $category_name = $row['part_category_name']; $footprint_name = $row['part_footprint_name']; $storelocation_name = $row['part_storelocation_name']; $manufacturer_name = $row['part_manufacturer_name']; $supplier_name = $row['part_supplier_name']; $supplierpartnr = $row['part_supplierpartnr']; $price = $row['part_price']; // search elements / create them if they don't exist already if (strlen($category_name) > 0) { $categories = Category::search($database, $current_user, $log, $category_name, true); if (count($categories) > 0) { $category = $categories[0]; } else { $category = Category::add($database, $current_user, $log, $category_name, $import_category->get_id()); $import_category_used = true; } } else { throw new Exception('Jedes Bauteil muss eine Kategorie haben!'); } if (strlen($storelocation_name) > 0) { $storelocations = Storelocation::search($database, $current_user, $log, $storelocation_name, true); if (count($storelocations) > 0) { $storelocation = $storelocations[0]; } else { $storelocation = Storelocation::add($database, $current_user, $log, $storelocation_name, $import_storelocation->get_id()); $import_storelocation_used = true; } } if (strlen($manufacturer_name) > 0) { $manufacturers = Manufacturer::search($database, $current_user, $log, $manufacturer_name, true); if (count($manufacturers) > 0) { $manufacturer = $manufacturers[0]; } else { $manufacturer = Manufacturer::add($database, $current_user, $log, $manufacturer_name, $import_manufacturer->get_id()); $import_manufacturer_used = true; } } if (strlen($footprint_name) > 0) { $footprints = Footprint::search($database, $current_user, $log, $footprint_name, true); if (count($footprints) > 0) { $footprint = $footprints[0]; } else { $footprint = Footprint::add($database, $current_user, $log, $footprint_name, $import_footprint->get_id()); $import_footprint_used = true; } } if (strlen($supplier_name) > 0) { $suppliers = Supplier::search($database, $current_user, $log, $supplier_name, true); if (count($suppliers) > 0) { $supplier = $suppliers[0]; } else { $supplier = Supplier::add($database, $current_user, $log, $supplier_name, $import_supplier->get_id()); $import_supplier_used = true; } } else { if (strlen($supplierpartnr) > 0 || $price > 0) { throw new Exception('Ist eine Bestellnummer oder ein Preis angegeben, so muss auch ein Lieferant angegeben werden!'); } } $new_part = Part::add($database, $current_user, $log, $name, $category->get_id(), $description, $instock, $mininstock, isset($storelocation) ? $storelocation->get_id() : NULL, isset($manufacturer) ? $manufacturer->get_id() : NULL, isset($footprint) ? $footprint->get_id() : NULL, $comment); if (isset($supplier)) { $new_orderdetails = Orderdetails::add($database, $current_user, $log, $new_part->get_id(), $supplier->get_id(), $supplierpartnr); if ($price > 0) { $new_pricedetails = Pricedetails::add($database, $current_user, $log, $new_orderdetails->get_id(), $price); } } if (!$only_check_data) { $parts[] = $new_part; } $row_index++; } // delete all elements which were created in this function, but were not used if ($import_category_created && !$import_category_used) { $import_category->delete(); } if ($import_storelocation_created && !$import_storelocation_used) { $import_storelocation->delete(); } if ($import_footprint_created && !$import_footprint_used) { $import_footprint->delete(); } if ($import_supplier_created && !$import_supplier_used) { $import_supplier->delete(); } if ($import_manufacturer_created && !$import_manufacturer_used) { $import_manufacturer->delete(); } if ($only_check_data) { $database->rollback(); } else { $database->commit($transaction_id); } // commit transaction } catch (Exception $e) { $database->rollback(); // rollback transaction throw new Exception((isset($row_index) ? 'Nr. ' . ($row_index + 1) . ': ' : '') . $e->getMessage()); } return $parts; }
<?php $model = new Category(); $this->widget('zii.widgets.grid.CGridView', array('id' => 'category-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('title', array('class' => 'CButtonColumn', 'viewButtonUrl' => 'Yii::app()->createUrl("/shop/category/view", array("id" => $data->category_id))', 'updateButtonUrl' => 'Yii::app()->createUrl("/shop/category/update", array("id" => $data->category_id))', 'deleteButtonUrl' => 'Yii::app()->createUrl("/shop/category/delete", array("id" => $data->category_id))')))); echo CHtml::link(Yii::t('ShopModule.shop', 'Create a new Category'), array('category/create'));
<?php require_once 'core/init.php'; $member_role = $_SESSION['roles']; if (in_array("Laboratory Administrator", $member_role) || in_array("Related Lecturer", $member_role)) { } else { header('location:restricted_page.php'); } $cat_id = $_GET["cat_id"]; $editable = $_GET["editable"]; $categoryName; $categoryNo; if (isset($cat_id)) { $category = Category::search(array("category_id" => $cat_id)); $items = $category->get_items(); $categoryName = $category->get_name(); $categoryNo = $category->get_label(); foreach ($items as $label1) { foreach ($label1 as $label2) { $itemId = $label2->get_id(); echo "<div id='{$itemId}' class=\"dashicon\">"; echo "<a onclick = itemClicked(\"{$itemId}\")>"; echo "<img src=\"img/items/" . $label2->get_name() . ".png \" height=\"150\" width=\"150\"/>"; echo $label2->get_name(); echo "</a>"; echo "</div>"; } } } if ($editable == 1) { //itemView($cat_id);
ksort($itemTable); echo "<tr>"; echo "<td colspan = \"2\"></td>"; //echo "<td></td>"; foreach ($itemTable as $key => $value) { echo "<th colspan = \"{$value}\">{$key}</th>"; } echo "</tr>"; foreach ($categoryTable as $key => $value) { for ($x = 1; $x <= $value; $x++) { echo "<tr>"; if ($x == 1) { echo "<th rowspan=\"{$value}\">{$key}</th>"; } $catLabel = $key . $x; $category = Category::search(array("category_no" => $catLabel)); $catName = $category->get_name(); echo "<td>{$x} {$catName}</td>"; $itemList = $category->get_items(); foreach ($itemTable as $key2 => $value2) { for ($y = 1; $y <= $value2; $y++) { if (isset($itemList[$key2][$y])) { $itemName = $itemList[$key2][$y]->get_name(); $itemId = $itemList[$key2][$y]->get_id(); echo "<td><a href=\"#\" onclick=cellClicked(\"{$itemId}\",\"{$catLabel}\")> {$itemName}</a></td>"; } else { echo "<td>{$key2}{$y}</td>"; } } } echo "</tr>";