本文整理汇总了PHP中Model_Category::getParents方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::getParents方法的具体用法?PHP Model_Category::getParents怎么用?PHP Model_Category::getParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::getParents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPath
public function getPath($dir)
{
//первым делом ищем в структуре
$category = new Model_Category('tree');
$categoryId = $category->getCategoryIdByUrl($dir);
if ($categoryId) {
$dirs = [];
$categoryData = $category->getCategory($categoryId);
$parents = $category->getParents($categoryId);
foreach ($parents as $parent) {
if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') {
$dirs[] = $parent['url'];
}
}
return array('name' => $categoryData['name'], 'path' => implode('/', $dirs));
}
//теперь ищем в материалах
$materials = new Model_Material('group');
$materialUrl = str_replace('.html', '', $dir);
$materialId = $materials->getMaterialIdByUrl($materialUrl);
if ($materialId) {
$materialData = $materials->getMaterial($materialId);
$categoryId = $materials->getTreeIdByMid($materialId);
$categoryData = $category->getCategory($categoryId);
return array('name' => $materialData['name'], 'path' => $categoryData['url'] . '/' . $dir);
} else {
return FALSE;
}
}
示例2: action_cart
public function action_cart()
{
/* Добавление товара в корзину
$data:
$item_id* - id товара
$item_count* - кол-во товара
$order_id - id заказа
*/
$methods['add_item'] = function ($data) {
PC::debug($data, 'add item data');
$model_orders = new Model_Orders();
$materials = new Model_Material('groups');
// Добавление товара к существующему заказу
if (isset($data['order_id'])) {
PC::debug(1, 1);
$res = $model_orders->addGood(Arr::get($data, 'order_id'), Arr::get($data, 'item_id'), Arr::get($data, 'item_count'));
} else {
PC::debug(2, 1);
$item_count = Arr::get($data, 'item_count');
$res = $model_orders->newOrder(Arr::get($data, 'item_id'), $item_count);
$new_count = $item_count;
}
$material = $materials->getMaterial(Arr::get($data, 'item_id'));
$fields = $materials->getFields2(Arr::get($data, 'item_id'), TRUE);
$catalog = new Model_Category('tree');
$categoryId = $materials->getTreeIdByMid(Arr::get($data, 'item_id'));
$parents = $catalog->getParents($categoryId);
$node = '';
foreach ($parents as $parent) {
if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') {
$node .= $parent['url'] . '/';
}
}
$itemdata = $model_orders->getOrderCount(Arr::get($data, 'order_id'), Arr::get($data, 'item_id'));
$item[Arr::get($data, 'item_id')] = array_merge($material, $fields);
if (isset($new_count)) {
$item[Arr::get($data, 'item_id')]['cnt'] = $new_count;
} else {
$item[Arr::get($data, 'item_id')]['cnt'] = $itemdata['cnt'];
}
$item[Arr::get($data, 'item_id')]['node'] = $node;
return array('order_id' => $res, 'item' => $item);
};
/* Удаление товара из корзины
$data:
$order_id* - id заказа
$item_id* - id товара
$item_count* - кол-во товара
*/
$methods['del_item'] = function ($data) {
$model_orders = new Model_Orders();
extract($data);
// Удаление товара из корзины
$res = $model_orders->deleteItem(Arr::get($data, 'order_id'), Arr::get($data, 'item_id'), Arr::get($data, 'item_count'));
return $res;
};
/* Получение информации о заказе
$data:
$order_id* - id заказа
*/
$mathods['get_order'] = function ($data) {
$model_orders = new Model_Orders();
$order_data = $model_orders->getOrder($data['order_id']);
return $order_data;
};
/* Удаление заказа
$data:
$order_id* - id заказа
*/
$mathods['del_order'] = function ($data) {
PC::debug($data, 'del_order');
$model_orders = new Model_Orders();
$res = $model_orders->deleteOrder($data['order_id']);
return $res;
};
/* Получение информации о заказе
$data:
$order_id* - id заказа
*/
$methods['get_items'] = function ($data) {
$model_orders = new Model_Orders();
//extract($data);
$res = $model_orders->getOrder(Arr::get($data, 'order_id', ''));
return $res;
};
$data = Arr::get($_POST, 'data', '');
if ($data == '') {
$data = Arr::get($_GET, 'data', '');
}
extract(json_decode($data, true));
$res = false;
if (isset($methods[$method])) {
$res = $methods[$method]($data);
PC::debug($res, 'Ajax: "' . $method . '"');
}
exit(json_encode($res));
}
示例3: getOrder
public function getOrder($orderId)
{
$order = ORM::factory("Orders")->where("id", "=", $orderId)->find()->as_array();
$items = DB::select()->from("order_materials")->where("order_id", "=", $orderId)->execute()->as_array();
$materials = new Model_Material("groups");
$catalog = new Model_Category("tree");
foreach ($items as $item) {
$material = $materials->getMaterial($item["mid"]);
$fields = $materials->getFields2($item["mid"], TRUE);
$categoryId = $materials->getTreeIdByMid($item["mid"]);
$parents = $catalog->getParents($categoryId);
$node = "";
foreach ($parents as $key => $parent) {
if ($parent["url"] == "glavnaya") {
$node .= $parents[$key + 1]["url"] . "/";
break;
}
}
$order["items"][$item["mid"]] = array_merge($material, $fields);
$order["items"][$item["mid"]]["cnt"] = $item["cnt"];
$order["items"][$item["mid"]]["node"] = $node;
}
return $order;
}
示例4: getTopMaterials
public function getTopMaterials($gid, $field, $limit, $time = 0)
{
$data = array();
$query = 'SELECT a.* FROM materials a, group_materials_rel b
WHERE b.gid = ' . $gid . '
AND b.mid = a.id
ORDER BY a.' . $field . ' DESC
LIMIT 0, ' . $limit;
$materials = DB::query(Database::SELECT, $query)->execute();
foreach ($materials as $material) {
$node = '';
//получаем поля
$fields = $this->getFields2($material['id'], TRUE);
$category = new Model_Category('tree');
$parents = $category->getParents($this->getTreeIdByMid($material['id']));
foreach ($parents as $parent) {
if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') {
$node .= $parent['url'] . '/';
}
}
$arr = array_merge($material, $fields);
$arr['node'] = $node;
$data[$material['id']] = $arr;
}
return $data;
}